Helper Functions for Slackbots
Project description
Slackbot Helper (slackbot-helper)
Contains Utility Functions to help deal with Slack Events and I/O
Usage
Assume this incoming event:
d_incoming = {
"blocks": [
{
"block_id": "vz+U",
"elements": [
{
"elements": [
{
"type": "user",
"user_id": "U045HCSMG8K"
},
{
"text": " dead ahead!",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"channel": "C046DB9TLEL",
"team": "T045AR44M70",
"text": "<@U045HCSMG8K> dead ahead!",
"ts": 1665195085.499959,
"type": "app_mention",
"user": "U04674UNRBJ"
}
Import the normalize_event
function:
from slackbot_helper import normalize_event
d_normalized = normalize_event(
d_event=d_incoming,
bot_ids=['U045HCSMG8K']
)
The bot_ids
parameter is a list of all known bot_ids in your application.
The output of this function is:
{
"membership": "85e8d1eb_46c2_11ed_97a0_4c1d96716627",
"analysis": {
"commands": [],
"meta_mode": "human2bot",
"meta_type": "H2B_SINGLE",
"text_1": "@U045HCSMG8K dead ahead!",
"text_2": "dead ahead!",
"user_all": ["U045HCSMG8K"],
"user_source": "U04674UNRBJ",
"user_target": "U045HCSMG8K"
},
"event": {
"blocks": [
{
"block_id": "vz+U",
"elements": [
{
"elements": [
{
"type": "user",
"user_id": "U045HCSMG8K"
},
{
"text": " dead ahead!",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"channel": "C046DB9TLEL",
"team": "T045AR44M70",
"text": "<@U045HCSMG8K> dead ahead!",
"ts": 1665195085.499959,
"type": "app_mention",
"user": "U04674UNRBJ"
},
}
The analysis
structure within the output contains the following fields of interest:
commands
: Any Commands extracted from the textmeta_mode
: The Mode of communication (human2bot
,human2human
,bot2human
,bot2bot
)meta_type
: The Type of communication (H2B_SINGLE
means Human is addressing a Single bot)text_1
: The original texttext_2
: The normalized textuser_all
: All the user IDs addressed in the textsource_user
: The Source User (responsible for sending the event)target_user
: The Target User (primary user responsible for receiving the event)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
slackbot-helper-0.1.23.tar.gz
(15.5 kB
view hashes)
Built Distribution
Close
Hashes for slackbot_helper-0.1.23-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a5d1727541bf88494a860109afefaf7c0a425158da25cb79b5cfeda6125852 |
|
MD5 | db544cd72479b75fb540cb9b65db163d |
|
BLAKE2b-256 | 7272c2772e34e33afdc2f29c05b73694848b2f94a9758d3996ee7df06279bb9e |