The Bolt family of SDKs

Bolt is the swiftest way to start programming with the Slack Platform in JavaScript, Python, or Java.

All flavors of Bolt are equipped to help you build apps and integrations with our most commonly used features.

Bolt for JavaScript

Bolt for Python

Bolt for Java

  • Rapidly develop with Kotlin bindings
  • Works with Servlet containers out-of-the-box, including Spring Boot
  • Built on top of and included as part of java-slack-sdk
  • Getting started guide

What does Bolt look like?

Sending your first message with the API is a rite of passage made right as rain with Bolt.

Calling views.open
Java
JavaScript
Python
Java
import com.slack.api.bolt.App;
import com.slack.api.bolt.AppConfig;
import com.slack.api.bolt.jetty.SlackAppServer;
import com.slack.api.methods.SlackApiException;

import java.io.IOException;

import static com.slack.api.model.block.Blocks.*;
import static com.slack.api.model.block.composition.BlockCompositions.markdownText;
import static com.slack.api.model.block.element.BlockElements.asContextElements;
import static com.slack.api.model.view.Views.*;

public class ViewsOpen {

    public static void main(String[] args) throws Exception {
        var config = new AppConfig();
        config.setSingleTeamBotToken(System.getenv("SLACK_BOT_TOKEN"));
        config.setSigningSecret(System.getenv("SLACK_SIGNING_SECRET"));
        var app = new App(config); // `new App()` does the same

        app.globalShortcut("open_modal", (req, ctx) -> {
            var logger = ctx.logger;
            try {
                var payload = req.getPayload();
                // Call the conversations.create method using the built-in WebClient
                var modalView = view(v -> v
                    .type("modal")
                    .title(viewTitle(vt -> vt.type("plain_text").text("My App")))
                    .close(viewClose(vc -> vc.type("plain_text").text("Close")))
                    .blocks(asBlocks(
                        section(s -> s.text(markdownText(mt ->
                            mt.text("About the simplest modal you could conceive of :smile:\\n\\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>.")))),
                        context(c -> c.elements(asContextElements(
                            markdownText("Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>")
                        )))
                    ))
                );
                var result = ctx.client().viewsOpen(r -> r
                    // The token you used to initialize your app
                    .token(System.getenv("SLACK_BOT_TOKEN"))
                    .triggerId(payload.getTriggerId())
                    .view(modalView)
                );
                // Print result
                logger.info("result: {}", result);
            } catch (IOException | SlackApiException e) {
                logger.error("error: {}", e.getMessage(), e);
            }
            return ctx.ack();
        });

        var server = new SlackAppServer(app);
        server.start();
    }

}
JavaScript
Code to initialize Bolt app
// Require the Bolt for JavaScript package (github.com/slackapi/bolt) const { App, LogLevel } = require("@slack/bolt"); const app = new App({ token: "xoxb-your-token", signingSecret: "your-signing-secret", // LogLevel can be imported and used to make debugging simpler logLevel: LogLevel.DEBUG });
// The open_modal shortcut opens a plain old modal // Shortcuts require the command scope app.shortcut('open_modal', async ({ ack, payload, client }) => { // Acknowledge shortcut request ack(); try { // Call the views.open method using the WebClient passed to listeners const result = await client.views.open({ trigger_id: payload.trigger_id, view: { "type": "modal", "title": { "type": "plain_text", "text": "My App" }, "close": { "type": "plain_text", "text": "Close" }, "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "About the simplest modal you could conceive of :smile:\n\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>." } }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": "Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>" } ] } ] } }); console.log(result); } catch (error) { console.error(error); } });
Code to run app
(async () => { // Start your app await app.start(process.env.PORT || 3000); console.log("⚡️ Bolt app is running!"); })();
Python
Code to initialize Bolt app
import os # Import Bolt for Python (github.com/slackapi/bolt-python) from slack_bolt import App # Initializes your Bolt app with a bot token and signing secret app = App( token="xoxb-your-token", signing_secret="your-signing-secret" )
# The open_modal shortcut opens a plain old modal # Shortcuts require the command scope @app.shortcut("open_modal") def open_modal(ack, shortcut, client, logger): # Acknowledge shortcut request ack() try: # Call the views.open method using the WebClient passed to listeners result = client.views_open( trigger_id=shortcut["trigger_id"], view={ "type": "modal", "title": {"type": "plain_text", "text": "My App"}, "close": {"type": "plain_text", "text": "Close"}, "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "About the simplest modal you could conceive of :smile:\n\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>.", }, }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": "Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>", } ], }, ], }, ) logger.info(result) except SlackApiError as e: logger.error("Error creating conversation: {}".format(e))
Code to run app
# Start your app if __name__ == "__main__": app.start(port=int(os.environ.get("PORT", 3000)))