slack-qna


Nameslack-qna JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryAn easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.
upload_time2023-12-18 18:16:50
maintainer
docs_urlNone
authorlokwkin
requires_python>=3.11,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
<img src="./docs/chatgpt-a.png" width="50%">

##### Reply
<img src="./docs/chatgpt-b.png" width="50%">

#### Use with Dall-E (Image Response)
##### Loading
<img src="./docs/dalle-a.png" width="50%">

##### Reply
<img src="./docs/dalle-b.png" width="50%">

## Usage

### Install
```
pypi install slack-qna
```

```python
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
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "slack-qna",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "lokwkin",
    "author_email": "lokwkin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/96/fa/31e11b04af930f169b3c8e7e6cacd9d741ad93e1ba54ef3fca8fc8447035/slack_qna-0.1.1.tar.gz",
    "platform": null,
    "description": "# Slack Q&A\n\nAn easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.\n\nFor NodeJS version, please see https://github.com/lokwkin/slack-qna-node\n\n## Description\n\nHigh level flow:\n1. User messages this BOT via either:\n    1. Direct Message\n    2. Mention in Channel\n    3. Slack Command\n2. The BOT shows a loading reaction to the message.\n3. The BOT relays user's message to your custom handler, and expect for a result either in `Text`, `File` or `Image` type.\n4. The BOT reply the user's message in Slack Thread.\n5. The BOT also shows a success reaction to the message.\n\nNote:\n- 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.\n\n## Sample use cases\n\n#### Use with ChatGPT (Text Response)\n##### Loading\n<img src=\"./docs/chatgpt-a.png\" width=\"50%\">\n\n##### Reply\n<img src=\"./docs/chatgpt-b.png\" width=\"50%\">\n\n#### Use with Dall-E (Image Response)\n##### Loading\n<img src=\"./docs/dalle-a.png\" width=\"50%\">\n\n##### Reply\n<img src=\"./docs/dalle-b.png\" width=\"50%\">\n\n## Usage\n\n### Install\n```\npypi install slack-qna\n```\n\n```python\nfrom slack_qna.slack_qna import SlackQna\nfrom slack_qna.schema import IncomingMessage, CommandHook, Reactions\n\nslack_bot_token = os.getenv(\"SLACK_BOT_TOKEN\")\nslack_app_token = os.getenv(\"SLACK_APP_TOKEN\")\nbot_user_id = os.getenv(\"SLACK_BOT_USER_ID\")\n\nslackQnaBot = SlackQna(slack_bot_token, slack_app_token, bot_user_id, Reactions(\n            loading=\"loading\",\n            success=\"white_check_mark\",\n            failed=\"x\"\n        ))\n\ndef my_handler(message: IncomingMessage):\n    return \"Hi there\"\n\nslackQnaBot.register_handler(CommandHook(is_sync=True, data_type='text', handler=my_handler))\nslackQnaBot.listen(direct_message=True, mention=True)\n```\n\n### Slack Setup\n1. Register an Slack App in portal https://api.slack.com/\n2. \"Socket Mode\" -> Enable Socket Mode\n3. \"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`\n4. \"Event Subscription\" -> \"Enable Event\" -> \"Subscribe to bot events\" -> Add `message.im` and `app_mention` --> \"save\"\n5. \"App Home\" -> \"Message Tab\" -> Enable \"Allow users to send Slash commands and messages from the messages tab\"\n6. Install bot to your workspace\n7. Obtain your Bot Token from \"OAuth & Permissions\" > \"Bot User OAuth Token\"\n8. Obtain your App Token from \"Basic Information\" > \"App Level Token\"\n9. \"Install App\" -> Reinstall to workspace if neccessary",
    "bugtrack_url": null,
    "license": "",
    "summary": "An easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "beaa8a42139a27e42502b15e4dc17652d591a0026b2ec3fa5c1cb7ebf0d449bc",
                "md5": "7cfb63f26231681a036cc3119f8dd6f6",
                "sha256": "f2bef9529410a8765413e799d80c3f01ee1bb7e0b94142cbc6fcc0cc6307e513"
            },
            "downloads": -1,
            "filename": "slack_qna-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7cfb63f26231681a036cc3119f8dd6f6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 5016,
            "upload_time": "2023-12-18T18:16:49",
            "upload_time_iso_8601": "2023-12-18T18:16:49.279905Z",
            "url": "https://files.pythonhosted.org/packages/be/aa/8a42139a27e42502b15e4dc17652d591a0026b2ec3fa5c1cb7ebf0d449bc/slack_qna-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96fa31e11b04af930f169b3c8e7e6cacd9d741ad93e1ba54ef3fca8fc8447035",
                "md5": "aae54735ab8052eca6fd45db48152374",
                "sha256": "d00c7cb5b47829e84ef251bcc792acc96a98b7cf088ff4e55d838796e8054de1"
            },
            "downloads": -1,
            "filename": "slack_qna-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "aae54735ab8052eca6fd45db48152374",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11,<4.0",
            "size": 4186,
            "upload_time": "2023-12-18T18:16:50",
            "upload_time_iso_8601": "2023-12-18T18:16:50.492270Z",
            "url": "https://files.pythonhosted.org/packages/96/fa/31e11b04af930f169b3c8e7e6cacd9d741ad93e1ba54ef3fca8fc8447035/slack_qna-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-18 18:16:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "slack-qna"
}
        
Elapsed time: 0.37578s