All Projects → slackapi → Bolt Python

slackapi / Bolt Python

Licence: mit
A framework to build Slack apps using Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Bolt Python

Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+1640.53%)
Mutual labels:  asyncio, aiohttp, slack, websocket, websockets, websocket-client
Java Slack Sdk
Slack Developer Kit (including Bolt for Java) for any JVM language
Stars: ✭ 393 (+106.84%)
Mutual labels:  chatbot, slack-api, slack, websocket, websockets, websocket-client
Node Slack Sdk
Slack Developer Kit for Node.js
Stars: ✭ 2,988 (+1472.63%)
Mutual labels:  slack, websocket, websockets, websocket-client
Channelstream
Channelstream is a websocket communication server for web applications
Stars: ✭ 52 (-72.63%)
Mutual labels:  django, flask, websocket, websockets
Slacker
Slack Bot Framework
Stars: ✭ 495 (+160.53%)
Mutual labels:  chatbot, slack-api, slack, chatops
Bolt Js
A framework to build Slack apps using JavaScript
Stars: ✭ 1,971 (+937.37%)
Mutual labels:  slack, websocket, websockets, websocket-client
Cryptofeed
Cryptocurrency Exchange Websocket Data Feed Handler
Stars: ✭ 643 (+238.42%)
Mutual labels:  asyncio, websocket, websockets
Gun
HTTP/1.1, HTTP/2 and Websocket client for Erlang/OTP.
Stars: ✭ 710 (+273.68%)
Mutual labels:  websocket, websockets, websocket-client
Awesome Websockets
A curated list of Websocket libraries and resources.
Stars: ✭ 850 (+347.37%)
Mutual labels:  websocket, websockets, websocket-client
Cog
Bringing the power of the command line to chat
Stars: ✭ 910 (+378.95%)
Mutual labels:  chatbot, slack, chatops
Django Channels React Multiplayer
turn based strategy game using django channels, redux, and react hooks
Stars: ✭ 52 (-72.63%)
Mutual labels:  django, websocket, websockets
Flottbot
A chatbot framework written in Go. All configurations are made in YAML files, or inside scripts written in your favorite language.
Stars: ✭ 175 (-7.89%)
Mutual labels:  chatbot, slack, chatops
Claws
Awesome WebSocket CLient - an interactive command line client for testing websocket servers
Stars: ✭ 187 (-1.58%)
Mutual labels:  websocket, websockets, websocket-client
Starscream
Websockets in swift for iOS and OSX
Stars: ✭ 7,105 (+3639.47%)
Mutual labels:  websocket, websockets, websocket-client
Django Private Chat
Django one-to-one Websocket-based Asyncio-handled chat, developed by Bearle team
Stars: ✭ 376 (+97.89%)
Mutual labels:  asyncio, django, websockets
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+1860%)
Mutual labels:  websocket, websockets, websocket-client
Python Dependency Injector
Dependency injection framework for Python
Stars: ✭ 1,203 (+533.16%)
Mutual labels:  asyncio, flask, aiohttp
Arduinowebsockets
arduinoWebSockets
Stars: ✭ 1,265 (+565.79%)
Mutual labels:  websocket, websockets, websocket-client
Yetibot
🤖 Extreme chatops bot for Slack and IRC 🔧 New contributors welcome 🏗
Stars: ✭ 311 (+63.68%)
Mutual labels:  chatbot, slack, chatops
Webargs
A friendly library for parsing HTTP request arguments, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, Pyramid, webapp2, Falcon, and aiohttp.
Stars: ✭ 1,145 (+502.63%)
Mutual labels:  django, flask, aiohttp

Bolt Bolt logo for Python

Python Version pypi package Build Status Codecov

A Python framework to build Slack apps in a flash with the latest platform features. Read the getting started guide and look at our code examples to learn how to build apps using Bolt.

Setup

# Python 3.6+ required
python -m venv .venv
source .venv/bin/activate

pip install -U pip
pip install slack_bolt

Creating an app

Create a Bolt for Python app by calling a constructor, which is a top-level export. If you'd prefer, you can create an async app.

import logging
logging.basicConfig(level=logging.DEBUG)

from slack_bolt import App

# export SLACK_SIGNING_SECRET=***
# export SLACK_BOT_TOKEN=xoxb-***
app = App()

# Add functionality here

if __name__ == "__main__":
    app.start(3000)  # POST http://localhost:3000/slack/events

Running an app

export SLACK_SIGNING_SECRET=***
export SLACK_BOT_TOKEN=xoxb-***
python app.py

# in another terminal
ngrok http 3000

Running a Socket Mode app

If you use Socket Mode for running your app, SocketModeHandler is available for it.

import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

# Install the Slack app and get xoxb- token in advance
app = App(token=os.environ["SLACK_BOT_TOKEN"])

# Add functionality here

if __name__ == "__main__":
    # Create an app-level token with connections:write scope
    handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
    handler.start()

Run the app this way:

export SLACK_APP_TOKEN=xapp-***
export SLACK_BOT_TOKEN=xoxb-***
python app.py

# SLACK_SIGNING_SECRET is not required
# Running ngrok is not required

Listening for events

Apps typically react to a collection of incoming events, which can correspond to Events API events, actions, shortcuts, slash commands or options requests. For each type of request, there's a method to build a listener function.

# Listen for an event from the Events API
app.event(event_type, fn)

# Convenience method to listen to only `message` events using a string or re.Pattern
app.message([pattern ,] fn)

# Listen for an action from a Block Kit element (buttons, select menus, date pickers, etc)
app.action(action_id, fn)

# Listen for dialog submissions
app.action({"callback_id": callbackId}, fn)

# Listen for a global or message shortcuts
app.shortcut(callback_id, fn)

# Listen for slash commands
app.command(command_name, fn)

# Listen for view_submission modal events
app.view(callback_id, fn)

# Listen for options requests (from select menus with an external data source)
app.options(action_id, fn)

The recommended way to use these methods are decorators:

@app.event(event_type)
def handle_event(event):
    pass

Making things happen

Most of the app's functionality will be inside listener functions (the fn parameters above). These functions are called with a set of arguments, each of which can be used in any order. If you'd like to access arguments off of a single object, you can use args, an slack_bolt.kwargs_injection.Args instance that contains all available arguments for that event.

Argument Description
body Dictionary that contains the entire body of the request (superset of payload). Some accessory data is only available outside of the payload (such as trigger_id and authorizations).
payload Contents of the incoming event. The payload structure depends on the listener. For example, for an Events API event, payload will be the event type structure. For a block action, it will be the action from within the actions list. The payload dictionary is also accessible via the alias corresponding to the listener (message, event, action, shortcut, view, command, or options). For example, if you were building a message() listener, you could use the payload and message arguments interchangably. An easy way to understand what's in a payload is to log it.
context Event context. This dictionary contains data about the event and app, such as the botId. Middleware can add additional context before the event is passed to listeners.
ack Function that must be called to acknowledge that your app received the incoming event. ack exists for all actions, shortcuts, view submissions, slash command and options requests. ack returns a promise that resolves when complete. Read more in Acknowledging events.
respond Utility function that responds to incoming events if it contains a response_url (shortcuts, actions, and slash commands).
say Utility function to send a message to the channel associated with the incoming event. This argument is only available when the listener is triggered for events that contain a channel_id (the most common being message events). say accepts simple strings (for plain-text messages) and dictionaries (for messages containing blocks).
client Web API client that uses the token associated with the event. For single-workspace installations, the token is provided to the constructor. For multi-workspace installations, the token is returned by using the OAuth library, or manually using the authorize function.
logger The built-in logging.Logger instance you can use in middleware/listeners.

Creating an async app

If you'd prefer to build your app with asyncio, you can import the AIOHTTP library and call the AsyncApp constructor. Within async apps, you can use the async/await pattern.

# Python 3.6+ required
python -m venv .venv
source .venv/bin/activate

pip install -U pip
# aiohttp is required
pip install slack_bolt aiohttp

In async apps, all middleware/listeners must be async functions. When calling utility methods (like ack and say) within these functions, it's required to use the await keyword.

# Import the async app instead of the regular one
from slack_bolt.async_app import AsyncApp

app = AsyncApp()

@app.event("app_mention")
async def event_test(body, say, logger):
    logger.info(body)
    await say("What's up?")

@app.command("/hello-bolt-python")
async def command(ack, body, respond):
    await ack()
    await respond(f"Hi <@{body['user_id']}>!")

if __name__ == "__main__":
    app.start(3000)

If you want to use another async Web framework (e.g., Sanic, FastAPI, Starlette), take a look at the built-in adapters and their examples.

Getting Help

The documentation has more information on basic and advanced concepts for Bolt for Python.

If you otherwise get stuck, we're here to help. The following are the best ways to get assistance working through your issue:

  • Issue Tracker for questions, bug reports, feature requests, and general discussion related to Bolt for Python. Try searching for an existing issue before creating a new one.
  • Email our developer support team: [email protected]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].