slack-serverless


Nameslack-serverless JSON
Version 2024.1014 PyPI version JSON
download
home_pageNone
SummarySimplified serverless Slack bot interactions
upload_time2024-07-10 19:46:08
maintainerNone
docs_urlNone
authorNone
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

> **Note** to avoid dependency conflicts, this library does not depend on the
> cloud provider APIs that are needed. For GCP, be sure to add `google-cloud-pubsub>=2.18.1`
> to your `requirements.txt` (or whatever) if you're using 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.


### AWS

AWS is supported (at least, Lambdas with API Gateway proxy triggers are), and it's
much the same as for GCP - just use the `slack_slash_command_aws_api_gateway_proxy`
and `slack_event_webhook_aws_api_gateway_proxy` decorators instead of the GCP 
ones, and you should be good to go.


### 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": null,
    "name": "slack-serverless",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "slack, serverless, cloud, chatbot",
    "author": null,
    "author_email": "Ross Bamford <roscopeco@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/63/de/fb4fc188693bbb175e0840265ec01d53988f00b06b27dae018fe82cce291/slack_serverless-2024.1014.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\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\n> **Note** to avoid dependency conflicts, this library does not depend on the\n> cloud provider APIs that are needed. For GCP, be sure to add `google-cloud-pubsub>=2.18.1`\n> to your `requirements.txt` (or whatever) if you're using 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### AWS\n\nAWS is supported (at least, Lambdas with API Gateway proxy triggers are), and it's\nmuch the same as for GCP - just use the `slack_slash_command_aws_api_gateway_proxy`\nand `slack_event_webhook_aws_api_gateway_proxy` decorators instead of the GCP \nones, and you should be good to go.\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.1014",
    "project_urls": {
        "Homepage": "https://github.com/roscopeco/slack-serverless"
    },
    "split_keywords": [
        "slack",
        " serverless",
        " cloud",
        " chatbot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e19df2f8f84bd3a847fdac2c763d92837773d9b7a29db875d4caa60c9384bbe",
                "md5": "f8b22d6b98b2abc8c4c4fdeb6d1bd3a7",
                "sha256": "0f19fa24ee914838ecee9a8c53a7158f8b0d9997a2a40496eaa33e9514483434"
            },
            "downloads": -1,
            "filename": "slack_serverless-2024.1014-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f8b22d6b98b2abc8c4c4fdeb6d1bd3a7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10951,
            "upload_time": "2024-07-10T19:46:06",
            "upload_time_iso_8601": "2024-07-10T19:46:06.482167Z",
            "url": "https://files.pythonhosted.org/packages/4e/19/df2f8f84bd3a847fdac2c763d92837773d9b7a29db875d4caa60c9384bbe/slack_serverless-2024.1014-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63defb4fc188693bbb175e0840265ec01d53988f00b06b27dae018fe82cce291",
                "md5": "75f3ab08e7ff72d9d7d495540e770954",
                "sha256": "e83bf89fbafde63bd2ff09271a15de755abff8c492f20df28f33441b84300094"
            },
            "downloads": -1,
            "filename": "slack_serverless-2024.1014.tar.gz",
            "has_sig": false,
            "md5_digest": "75f3ab08e7ff72d9d7d495540e770954",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 10857,
            "upload_time": "2024-07-10T19:46:08",
            "upload_time_iso_8601": "2024-07-10T19:46:08.208229Z",
            "url": "https://files.pythonhosted.org/packages/63/de/fb4fc188693bbb175e0840265ec01d53988f00b06b27dae018fe82cce291/slack_serverless-2024.1014.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-10 19:46:08",
    "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: 1.79733s