slackbot-helper


Nameslackbot-helper JSON
Version 0.1.42 PyPI version JSON
download
home_pagehttps://github.com/craigtrim/slackbot-helper
SummaryHelper Functions for Slackbots
upload_time2023-03-29 18:12:23
maintainerCraig Trim
docs_urlNone
authorCraig Trim
requires_python>=3.8.5,<4.0.0
licenseMIT
keywords chatbot bot slack helper utility
VCS
bugtrack_url
requirements aiohttp aiosignal async-timeout attrs autopep8 baseblock blis catalogue certifi cffi cfgv charset-normalizer click colorama confection cryptography cymem distlib entrypoints exceptiongroup fast-sentence-tokenize filelock flake8 flakeheaven frozenlist identify idna iniconfig Jinja2 joblib langcodes MarkupSafe mccabe multidict murmurhash nltk nodeenv numpy packaging pathy plac platformdirs pluggy pre-commit preshed pycodestyle pycparser pydantic pyflakes Pygments pytest PyYAML regex requests slack-bolt slack-sdk slackbot-helper slackclient smart-open spacy spacy-legacy spacy-loggers srsly thinc toml tomli tqdm typer typing_extensions unicodedata2 urllib3 virtualenv wasabi yarl
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:
```python
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:
```python
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:
```json
{
    "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)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/craigtrim/slackbot-helper",
    "name": "slackbot-helper",
    "maintainer": "Craig Trim",
    "docs_url": null,
    "requires_python": ">=3.8.5,<4.0.0",
    "maintainer_email": "craigtrim@gmail.com",
    "keywords": "chatbot,bot,slack,helper,utility",
    "author": "Craig Trim",
    "author_email": "craigtrim@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f3/7c/8c937f06c5c81bdc6f41778222474d314a80f7d7a0a37bc191c2b870ac9c/slackbot-helper-0.1.42.tar.gz",
    "platform": null,
    "description": "# Slackbot Helper (slackbot-helper)\n\nContains Utility Functions to help deal with Slack Events and I/O\n\nSlack Events structures are highly variable and deeply nested.\n\nThis algorithm performs consistent extraction of the core key:value pairs.\n\n## Usage\nAssume this incoming event:\n```python\nd_incoming = {\n    \"blocks\": [\n        {\n            \"block_id\": \"vz+U\",\n            \"elements\": [\n                {\n                    \"elements\": [\n                        {\n                            \"type\": \"user\",\n                            \"user_id\": \"U045HCSMG8K\"\n                        },\n                        {\n                            \"text\": \" dead ahead!\",\n                            \"type\": \"text\"\n                        }\n                    ],\n                    \"type\": \"rich_text_section\"\n                }\n            ],\n            \"type\": \"rich_text\"\n        }\n    ],\n    \"channel\": \"C046DB9TLEL\",\n    \"text\": \"<@U045HCSMG8K> dead ahead!\",\n    \"ts\": 1665195085.499959,\n    \"type\": \"app_mention\",\n    \"user\": \"U04674UNRBJ\"\n}\n```\n\nImport the `normalize_event` function:\n```python\nfrom slackbot_helper import normalize_event\n\nd_normalized = normalize_event(\n    d_event=d_incoming,\n    bot_ids=['U045HCSMG8K']\n)\n```\n\nThe `bot_ids` parameter is a list of all known **bot_ids** in your application.\n\nThe output of this function is:\n```json\n{\n    \"membership\": \"85e8d1eb_46c2_11ed_97a0_4c1d96716627\",\n    \"analysis\": {\n        \"commands\": [],\n        \"meta_mode\": \"human2bot\",\n        \"meta_type\": \"H2B_SINGLE\",\n        \"text_1\": \"@U045HCSMG8K dead ahead!\",\n        \"text_2\": \"dead ahead!\",\n        \"user_all\": [\"U045HCSMG8K\"],\n        \"user_source\": \"U04674UNRBJ\",\n        \"user_target\": \"U045HCSMG8K\"\n    },\n    \"event\": {\n        \"blocks\": [\n            {\n                \"block_id\": \"vz+U\",\n                \"elements\": [\n                    {\n                        \"elements\": [\n                            {\n                                \"type\": \"user\",\n                                \"user_id\": \"U045HCSMG8K\"\n                            },\n                            {\n                                \"text\": \" dead ahead!\",\n                                \"type\": \"text\"\n                            }\n                        ],\n                        \"type\": \"rich_text_section\"\n                    }\n                ],\n                \"type\": \"rich_text\"\n            }\n        ],\n        \"channel\": \"C046DB9TLEL\",\n        \"text\": \"<@U045HCSMG8K> dead ahead!\",\n        \"ts\": 1665195085.499959,\n        \"type\": \"app_mention\",\n        \"user\": \"U04674UNRBJ\"\n    },\n}\n```\n\nThe `analysis` structure within the output contains the following fields of interest:\n1. `commands`: Any Commands extracted from the text\n2. `meta_mode`: The Mode of communication (`human2bot`, `human2human`, `bot2human`, `bot2bot`)\n3. `meta_type`: The Type of communication (`H2B_SINGLE` means Human is addressing a Single bot)\n4. `text_1`: The original text\n5. `text_2`: The normalized text\n6. `user_all`: All the user IDs addressed in the text\n7. `source_user`: The Source User (responsible for sending the event)\n8. `target_user`: The Target User (primary user responsible for receiving the event)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Helper Functions for Slackbots",
    "version": "0.1.42",
    "split_keywords": [
        "chatbot",
        "bot",
        "slack",
        "helper",
        "utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5d5a4180030bd79f20e01fa447604ecaec2ec80c1740ab84ff5d2bcd55f47127",
                "md5": "023d7e14ec350d2b97d2b83476b49a66",
                "sha256": "57f0740d11bd7bd1dc9a66eb75cf5d209c15478ce5f5f345b4fec4c405ad8343"
            },
            "downloads": -1,
            "filename": "slackbot_helper-0.1.42-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "023d7e14ec350d2b97d2b83476b49a66",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.5,<4.0.0",
            "size": 27143,
            "upload_time": "2023-03-29T18:12:24",
            "upload_time_iso_8601": "2023-03-29T18:12:24.459823Z",
            "url": "https://files.pythonhosted.org/packages/5d/5a/4180030bd79f20e01fa447604ecaec2ec80c1740ab84ff5d2bcd55f47127/slackbot_helper-0.1.42-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f37c8c937f06c5c81bdc6f41778222474d314a80f7d7a0a37bc191c2b870ac9c",
                "md5": "cec5400837235a17a3431f619fcb05af",
                "sha256": "8976ae09ff3c10d7f1fcb4d19151f6d71a70d0a3219d98a58b5222208e0d7278"
            },
            "downloads": -1,
            "filename": "slackbot-helper-0.1.42.tar.gz",
            "has_sig": false,
            "md5_digest": "cec5400837235a17a3431f619fcb05af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.5,<4.0.0",
            "size": 16390,
            "upload_time": "2023-03-29T18:12:23",
            "upload_time_iso_8601": "2023-03-29T18:12:23.179945Z",
            "url": "https://files.pythonhosted.org/packages/f3/7c/8c937f06c5c81bdc6f41778222474d314a80f7d7a0a37bc191c2b870ac9c/slackbot-helper-0.1.42.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-29 18:12:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "craigtrim",
    "github_project": "slackbot-helper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": []
        },
        {
            "name": "aiosignal",
            "specs": []
        },
        {
            "name": "async-timeout",
            "specs": []
        },
        {
            "name": "attrs",
            "specs": []
        },
        {
            "name": "autopep8",
            "specs": []
        },
        {
            "name": "baseblock",
            "specs": []
        },
        {
            "name": "blis",
            "specs": []
        },
        {
            "name": "catalogue",
            "specs": []
        },
        {
            "name": "certifi",
            "specs": []
        },
        {
            "name": "cffi",
            "specs": []
        },
        {
            "name": "cfgv",
            "specs": []
        },
        {
            "name": "charset-normalizer",
            "specs": []
        },
        {
            "name": "click",
            "specs": []
        },
        {
            "name": "colorama",
            "specs": []
        },
        {
            "name": "confection",
            "specs": []
        },
        {
            "name": "cryptography",
            "specs": []
        },
        {
            "name": "cymem",
            "specs": []
        },
        {
            "name": "distlib",
            "specs": []
        },
        {
            "name": "entrypoints",
            "specs": []
        },
        {
            "name": "exceptiongroup",
            "specs": []
        },
        {
            "name": "fast-sentence-tokenize",
            "specs": []
        },
        {
            "name": "filelock",
            "specs": []
        },
        {
            "name": "flake8",
            "specs": []
        },
        {
            "name": "flakeheaven",
            "specs": []
        },
        {
            "name": "frozenlist",
            "specs": []
        },
        {
            "name": "identify",
            "specs": []
        },
        {
            "name": "idna",
            "specs": []
        },
        {
            "name": "iniconfig",
            "specs": []
        },
        {
            "name": "Jinja2",
            "specs": []
        },
        {
            "name": "joblib",
            "specs": []
        },
        {
            "name": "langcodes",
            "specs": []
        },
        {
            "name": "MarkupSafe",
            "specs": []
        },
        {
            "name": "mccabe",
            "specs": []
        },
        {
            "name": "multidict",
            "specs": []
        },
        {
            "name": "murmurhash",
            "specs": []
        },
        {
            "name": "nltk",
            "specs": []
        },
        {
            "name": "nodeenv",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "packaging",
            "specs": []
        },
        {
            "name": "pathy",
            "specs": []
        },
        {
            "name": "plac",
            "specs": []
        },
        {
            "name": "platformdirs",
            "specs": []
        },
        {
            "name": "pluggy",
            "specs": []
        },
        {
            "name": "pre-commit",
            "specs": []
        },
        {
            "name": "preshed",
            "specs": []
        },
        {
            "name": "pycodestyle",
            "specs": []
        },
        {
            "name": "pycparser",
            "specs": []
        },
        {
            "name": "pydantic",
            "specs": []
        },
        {
            "name": "pyflakes",
            "specs": []
        },
        {
            "name": "Pygments",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": []
        },
        {
            "name": "PyYAML",
            "specs": []
        },
        {
            "name": "regex",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "slack-bolt",
            "specs": []
        },
        {
            "name": "slack-sdk",
            "specs": []
        },
        {
            "name": "slackbot-helper",
            "specs": [
                [
                    "==",
                    "0.1.42"
                ]
            ]
        },
        {
            "name": "slackclient",
            "specs": []
        },
        {
            "name": "smart-open",
            "specs": []
        },
        {
            "name": "spacy",
            "specs": []
        },
        {
            "name": "spacy-legacy",
            "specs": []
        },
        {
            "name": "spacy-loggers",
            "specs": []
        },
        {
            "name": "srsly",
            "specs": []
        },
        {
            "name": "thinc",
            "specs": []
        },
        {
            "name": "toml",
            "specs": []
        },
        {
            "name": "tomli",
            "specs": []
        },
        {
            "name": "tqdm",
            "specs": []
        },
        {
            "name": "typer",
            "specs": []
        },
        {
            "name": "typing_extensions",
            "specs": []
        },
        {
            "name": "unicodedata2",
            "specs": []
        },
        {
            "name": "urllib3",
            "specs": []
        },
        {
            "name": "virtualenv",
            "specs": []
        },
        {
            "name": "wasabi",
            "specs": []
        },
        {
            "name": "yarl",
            "specs": []
        }
    ],
    "lcname": "slackbot-helper"
}
        
Elapsed time: 0.05526s