Skip to main content

Using the Web API

You can call any Web API method using the WebClient provided to your app's listeners as client. This uses either the token that initialized your app or the token that is returned from the authorize function for the incoming event. The built-in OAuth support handles the second case by default.

Your Bolt app also has a top-level app.client which you can manually pass the token parameter. If the incoming request is not authorized or you're calling a method from outside of a listener, use the top-level app.client.

Calling one of the WebClient methods will return a Promise containing the response from Slack, regardless of whether you use the top-level or listener's client.

Since the introduction of org wide app installations, some web-api methods now require a team_id parameter to indicate which workspace to act on. Bolt for JavaScript will attempt to infer the team_id value based on incoming payloads and pass it along to client. This is handy for existing applications looking to add support for org wide installations and not spend time updating all of these web-api calls.

// Unix Epoch time for September 30, 2019 11:59:59 PM
const whenSeptemberEnds = 1569887999;

app.message('wake me up', async ({ message, client, logger }) => {
try {
// Call chat.scheduleMessage with the built-in client
const result = await client.chat.scheduleMessage({
channel: message.channel,
post_at: whenSeptemberEnds,
text: 'Summer has come and passed'
});
}
catch (error) {
logger.error(error);
}
});