slack-serverless


Nameslack-serverless JSON
Version 2024.1006a0 PyPI version JSON
download
home_page
SummarySimplified serverless Slack bot interactions
upload_time2024-02-03 10:32:12
maintainer
docs_urlNone
author
requires_python>=3.10
licenseCopyright 2023 Ross Bamford & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords slack serverless cloud chatbot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Utility library for serverless Slack apps

![PyPI](https://img.shields.io/pypi/v/slack-serverless)

This is a (currently very simple) library that eases development of serverless Slack
app and bots.

Currently, it targets Google Cloud Platform (but is easily generalised), and provides 
a decorator and some utility functions that make Slack signature verification automatic
and help with building responses in a very lightweight fashion.

I will grow it with things I end up needing in my work, but if you have different
needs and want to extend the library to support them, then PRs would be gratefully
received!

### MVP Example

This will accept any slash command you've configured for your bot, and just greet 
the user who calls it, tagging them in the reply. 

```python
from slack_serverless import slack_slash_command_gcp
from slack_messaging import slack_in_channel_text_response, slack_tags

@slack_slash_command_gcp(slack_signing_key=YOUR_SIGNING_KEY)
def command_handler(payload):
    return slack_in_channel_text_response(f"Hi there <@{slack_tags([payload['user_id']])}>")
```

### Message Deferral

If you need to take more than three seconds to reply to a Slack message, the usual
thing to do in a serverless environment is hand off the message to another function,
and have the first one acknowledge receipt back to Slack within three seconds. This 
is required - failing to respond in a timely fashion will result in the user seeing
an error message.

This library provides a comfort wrapper around this use case - all you need to do is
set up a PubSub topic (or your cloud's equivalent, though only GCP is supported as yet)
and defer the message in your main Slack handler with the `slack_defer` function.

You then have a second lambda, triggered by the pubsub (Eventarc or equivalent) in 
which the main function is decorated with `@slack_deferred_slash_handler_gcp`
(despite the name, it supports both events and slash commands - it'll be 
changing soon) and handles the event.

This will take care of wrapping and unwrapping the event appropriately and generally
trades of some ease of use for a little flexibility. If it doesn't meet your needs
you can of course just ignore it and code up the functionality yourself.


### Other Cloud Providers

Things will be a bit more manual here (but I'll happily add comfort wrappers if
there's enough call and a PR that contributes them 😉).

The easiest thing to do is use the `slack_slash_command` decorator, which 
is similar to the `gcp` one above but needs you pass in a couple of `Callable`s
the code will use to get access to the data in a provider-specific way.

Take a look at the code in `slack_serverless.py` for examples to get you started.

### Developing

Don't forget to set up `pre-commit` if you're developing things, especially if you
plan to push a PR.

### Legal Mumbo-Jumbo

Copyright (c)2023 Ross Bamford (and contributors)

License: MIT (see `LICENSE.md` for details).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "slack-serverless",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "slack,serverless,cloud,chatbot",
    "author": "",
    "author_email": "Ross Bamford <roscopeco@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1d/ed/a8feb2c859293e425db480f06cb14b861478bf9abc8eb98013f185e161dc/slack-serverless-2024.1006a0.tar.gz",
    "platform": null,
    "description": "## Utility library for serverless Slack apps\n\n![PyPI](https://img.shields.io/pypi/v/slack-serverless)\n\nThis is a (currently very simple) library that eases development of serverless Slack\napp and bots.\n\nCurrently, it targets Google Cloud Platform (but is easily generalised), and provides \na decorator and some utility functions that make Slack signature verification automatic\nand help with building responses in a very lightweight fashion.\n\nI will grow it with things I end up needing in my work, but if you have different\nneeds and want to extend the library to support them, then PRs would be gratefully\nreceived!\n\n### MVP Example\n\nThis will accept any slash command you've configured for your bot, and just greet \nthe user who calls it, tagging them in the reply. \n\n```python\nfrom slack_serverless import slack_slash_command_gcp\nfrom slack_messaging import slack_in_channel_text_response, slack_tags\n\n@slack_slash_command_gcp(slack_signing_key=YOUR_SIGNING_KEY)\ndef command_handler(payload):\n    return slack_in_channel_text_response(f\"Hi there <@{slack_tags([payload['user_id']])}>\")\n```\n\n### Message Deferral\n\nIf you need to take more than three seconds to reply to a Slack message, the usual\nthing to do in a serverless environment is hand off the message to another function,\nand have the first one acknowledge receipt back to Slack within three seconds. This \nis required - failing to respond in a timely fashion will result in the user seeing\nan error message.\n\nThis library provides a comfort wrapper around this use case - all you need to do is\nset up a PubSub topic (or your cloud's equivalent, though only GCP is supported as yet)\nand defer the message in your main Slack handler with the `slack_defer` function.\n\nYou then have a second lambda, triggered by the pubsub (Eventarc or equivalent) in \nwhich the main function is decorated with `@slack_deferred_slash_handler_gcp`\n(despite the name, it supports both events and slash commands - it'll be \nchanging soon) and handles the event.\n\nThis will take care of wrapping and unwrapping the event appropriately and generally\ntrades of some ease of use for a little flexibility. If it doesn't meet your needs\nyou can of course just ignore it and code up the functionality yourself.\n\n\n### Other Cloud Providers\n\nThings will be a bit more manual here (but I'll happily add comfort wrappers if\nthere's enough call and a PR that contributes them \ud83d\ude09).\n\nThe easiest thing to do is use the `slack_slash_command` decorator, which \nis similar to the `gcp` one above but needs you pass in a couple of `Callable`s\nthe code will use to get access to the data in a provider-specific way.\n\nTake a look at the code in `slack_serverless.py` for examples to get you started.\n\n### Developing\n\nDon't forget to set up `pre-commit` if you're developing things, especially if you\nplan to push a PR.\n\n### Legal Mumbo-Jumbo\n\nCopyright (c)2023 Ross Bamford (and contributors)\n\nLicense: MIT (see `LICENSE.md` for details).\n",
    "bugtrack_url": null,
    "license": "Copyright 2023 Ross Bamford & Contributors  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Simplified serverless Slack bot interactions",
    "version": "2024.1006a0",
    "project_urls": {
        "Homepage": "https://github.com/roscopeco/slack-serverless"
    },
    "split_keywords": [
        "slack",
        "serverless",
        "cloud",
        "chatbot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "20664351056e262212e9237861435899d9a525e056544b024814c0ac5a7f10b2",
                "md5": "8d7976a672a5e01b5f03dad71d901f5c",
                "sha256": "9506e370239a430a6d38899d3c5ccc7901a8ea35be19760a97717a2a31fc0c77"
            },
            "downloads": -1,
            "filename": "slack_serverless-2024.1006a0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d7976a672a5e01b5f03dad71d901f5c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8968,
            "upload_time": "2024-02-03T10:32:11",
            "upload_time_iso_8601": "2024-02-03T10:32:11.116836Z",
            "url": "https://files.pythonhosted.org/packages/20/66/4351056e262212e9237861435899d9a525e056544b024814c0ac5a7f10b2/slack_serverless-2024.1006a0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1deda8feb2c859293e425db480f06cb14b861478bf9abc8eb98013f185e161dc",
                "md5": "97ebeb95500ba9af03240f6b6c181f45",
                "sha256": "0583d0d3930b76d2d09d9f6d1e125ecd8dfe88ca0b007ee9d07601aeb14c9e87"
            },
            "downloads": -1,
            "filename": "slack-serverless-2024.1006a0.tar.gz",
            "has_sig": false,
            "md5_digest": "97ebeb95500ba9af03240f6b6c181f45",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7772,
            "upload_time": "2024-02-03T10:32:12",
            "upload_time_iso_8601": "2024-02-03T10:32:12.871459Z",
            "url": "https://files.pythonhosted.org/packages/1d/ed/a8feb2c859293e425db480f06cb14b861478bf9abc8eb98013f185e161dc/slack-serverless-2024.1006a0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-03 10:32:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "roscopeco",
    "github_project": "slack-serverless",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "slack-serverless"
}
        
Elapsed time: 0.18476s