Skip to main content

Helper Functions for Slackbots

Project description

Slackbot Helper (slackbot-helper)

Contains Utility Functions to help deal with Slack Events and I/O

Slack Events structures are highly variable and deeply nested.

This algorithm performs consistent extraction of the core key:value pairs.

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",
    "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",
        "text": "<@U045HCSMG8K> dead ahead!",
        "ts": 1665195085.499959,
        "type": "app_mention",
        "user": "U04674UNRBJ"
    },
}

The analysis structure within the output contains the following fields of interest:

  1. commands: Any Commands extracted from the text
  2. meta_mode: The Mode of communication (human2bot, human2human, bot2human, bot2bot)
  3. meta_type: The Type of communication (H2B_SINGLE means Human is addressing a Single bot)
  4. text_1: The original text
  5. text_2: The normalized text
  6. user_all: All the user IDs addressed in the text
  7. source_user: The Source User (responsible for sending the event)
  8. target_user: The Target User (primary user responsible for receiving the event)

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

slackbot-helper-0.1.42.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

slackbot_helper-0.1.42-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file slackbot-helper-0.1.42.tar.gz.

File metadata

  • Download URL: slackbot-helper-0.1.42.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.5 Windows/10

File hashes

Hashes for slackbot-helper-0.1.42.tar.gz
Algorithm Hash digest
SHA256 8976ae09ff3c10d7f1fcb4d19151f6d71a70d0a3219d98a58b5222208e0d7278
MD5 cec5400837235a17a3431f619fcb05af
BLAKE2b-256 f37c8c937f06c5c81bdc6f41778222474d314a80f7d7a0a37bc191c2b870ac9c

See more details on using hashes here.

File details

Details for the file slackbot_helper-0.1.42-py3-none-any.whl.

File metadata

File hashes

Hashes for slackbot_helper-0.1.42-py3-none-any.whl
Algorithm Hash digest
SHA256 57f0740d11bd7bd1dc9a66eb75cf5d209c15478ce5f5f345b4fec4c405ad8343
MD5 023d7e14ec350d2b97d2b83476b49a66
BLAKE2b-256 5d5a4180030bd79f20e01fa447604ecaec2ec80c1740ab84ff5d2bcd55f47127

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