Skip to main content

An easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.

Project description

Slack Q&A

An easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.

For NodeJS version, please see https://github.com/lokwkin/slack-qna-node

Description

High level flow:

  1. User messages this BOT via either:
    1. Direct Message
    2. Mention in Channel
    3. Slack Command
  2. The BOT shows a loading reaction to the message.
  3. The BOT relays user's message to your custom handler, and expect for a result either in Text, File or Image type.
  4. The BOT reply the user's message in Slack Thread.
  5. The BOT also shows a success reaction to the message.

Note:

  • This BOT uses Slack's Socket Mode instead of Webhook mode for slack connection, so it does not require an exposed public endpoint. But your services need to be long running.

Sample use cases

Use with ChatGPT (Text Response)

Loading
Reply

Use with Dall-E (Image Response)

Loading
Reply

Usage

Install

pypi install slack-qna
from slack_qna.slack_qna import SlackQna
from slack_qna.schema import IncomingMessage, CommandHook, Reactions

slack_bot_token = os.getenv("SLACK_BOT_TOKEN")
slack_app_token = os.getenv("SLACK_APP_TOKEN")
bot_user_id = os.getenv("SLACK_BOT_USER_ID")

slackQnaBot = SlackQna(slack_bot_token, slack_app_token, bot_user_id, Reactions(
            loading="loading",
            success="white_check_mark",
            failed="x"
        ))

def my_handler(message: IncomingMessage):
    return "Hi there"

slackQnaBot.register_handler(CommandHook(is_sync=True, data_type='text', handler=my_handler))
slackQnaBot.listen(direct_message=True, mention=True)

Slack Setup

  1. Register an Slack App in portal https://api.slack.com/
  2. "Socket Mode" -> Enable Socket Mode
  3. "OAuth & Permissions" -> "Bot Token Scopes" -> Grant these permissions: app_mentions:read, channels:history, chat:write, im:history, im:write, reactions:write, groups:history, files:write
  4. "Event Subscription" -> "Enable Event" -> "Subscribe to bot events" -> Add message.im and app_mention --> "save"
  5. "App Home" -> "Message Tab" -> Enable "Allow users to send Slash commands and messages from the messages tab"
  6. Install bot to your workspace
  7. Obtain your Bot Token from "OAuth & Permissions" > "Bot User OAuth Token"
  8. Obtain your App Token from "Basic Information" > "App Level Token"
  9. "Install App" -> Reinstall to workspace if neccessary

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

slack_qna-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

slack_qna-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file slack_qna-0.1.1.tar.gz.

File metadata

  • Download URL: slack_qna-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Darwin/21.6.0

File hashes

Hashes for slack_qna-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d00c7cb5b47829e84ef251bcc792acc96a98b7cf088ff4e55d838796e8054de1
MD5 aae54735ab8052eca6fd45db48152374
BLAKE2b-256 96fa31e11b04af930f169b3c8e7e6cacd9d741ad93e1ba54ef3fca8fc8447035

See more details on using hashes here.

File details

Details for the file slack_qna-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: slack_qna-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Darwin/21.6.0

File hashes

Hashes for slack_qna-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2bef9529410a8765413e799d80c3f01ee1bb7e0b94142cbc6fcc0cc6307e513
MD5 7cfb63f26231681a036cc3119f8dd6f6
BLAKE2b-256 beaa8a42139a27e42502b15e4dc17652d591a0026b2ec3fa5c1cb7ebf0d449bc

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