Skip to main content

A light decorator around flask and slack to remove the boilerplate for handling Slack slash commands

Project description

flask-slack-template

A light decorator around flask and slack to remove the boilerplate for handling Slack slash commands

Example Usage:

from flask import Flask

from flaskslack.flaskslack import FlaskSlack
from flaskslack.slack import ResponseType, Slack

app = Flask(__name__)
# If you want to get your config in a non default way,
# you can create a slack client with: Slack('slack_oauth_token', 'slack_signing_secret')
slack = Slack.create()
flask_slack = FlaskSlack(app, slack)


# set verify_signature to False if you want to do some local testing
@flask_slack.slack_route('/slack/endpoint', response_type=ResponseType.IN_CHANNEL, verify_signature=True)
def get_channel_member_ids(form_content):
    """
    :param form_content: a dict containing the data payload from the slack HTTP POST
            see: https://api.slack.com/slash-commands#app_command_handling
    :return: It should return a dict. The dict should contain a 'text' field, and/or a list of 'attachments'.
            see: https://api.slack.com/slash-commands#responding_immediate_response
    """

    channel_id = form_content["channel_id"]
    members_form_content = slack.try_api_call("conversations.members", channel=channel_id)
    channel_member_ids = members_form_content["members"]

    text_response = f"The channel_member_ids for channel_id {channel_id} is: {channel_member_ids}"
    return Slack.create_response(text_response)


if __name__ == "__main__":
    app.run(host="localhost")

Installation:

  • pip install flask_slack_template
  • Create a file called config.json in the root directory with the slack oauth token and signing secret
    {
      "SLACK_OAUTH_TOKEN": "YOUR_TOKEN_HERE",
      "SLACK_SIGNING_SECRET": "YOUR_SECRET_HERE"
    }
    
    # main.py   
    
    slack = Slack.create()
    # If you want to get your config in a non default way,
    # you can create a slack client with: Slack('slack_oauth_token', 'slack_signing_secret')
    # slack = Slack('slack_oauth_token', 'slack_signing_secret')
    
    • You can find your oauth token and signing secret here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_slack_template-0.0.6.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

flask_slack_template-0.0.6-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_slack_template-0.0.6.tar.gz.

File metadata

  • Download URL: flask_slack_template-0.0.6.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for flask_slack_template-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4e7baa9827dd26c9e46cca9886a908679b35ecb648770b1b6fc023d6a4080342
MD5 75f050d322c2d27625a7ac6fb84c15f0
BLAKE2b-256 351e25a87ce6ae704adf074dad098e1e9589e9d02f05164dac7e494b54c7306a

See more details on using hashes here.

File details

Details for the file flask_slack_template-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: flask_slack_template-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for flask_slack_template-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 331a358b819e6382bc71b660ff04f33cdde9b2f3fb7c2d63b557cfc8f47b0302
MD5 9586ef5eb7db3a581a840eda41bcc8a7
BLAKE2b-256 65ab9aef7594f084c3f24667bdef8ebe13f1753f0f6a1a34522af6964d6de82b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page