Skip to main content

slacktools-interactivity

A simple framework for working with Slack interactivity (https://api.slack.com/interactivity).

Install

pip install slacktools-interactivity

Commands

Register your CommandHandler class with the ComandFactory and when you receive a command request from Slack simply grab the command instance from the factory and execute it.

Basic Usage

Define your command:

from interactivity import CommandFactory, CommandHandler, CommandValidationError

from myproject import get_status, post_status


@CommandFactory.register("/status")
class StatusCommand(CommandHandler):
    def _validate(self):
        if not get_status(id=self.payload.text):
            raise CommandValidationError("Not a valid id.")

    def _execute(self):
        post_status(id=self.payload.text)

Handle the Slack command request:

from rest_framework.views import APIView
from rest_framework.response import Response

from interactivity import CommandFactory

class CommandsView(APIView):
    def post(self, request):
        handler = CommandFactory.make_handler(request.data)
        handler.execute()
        return Response()

Action Commands

Action commands allow you execute many different actions from a single Slack command. The text following the command is used to determine which action should be performed. The text is split by spaces, the first character set determines the action and the remain character sets are passed to the action as options/parameters.

Example

The below class definitions will handle the following command: /status service api

from interactivity import (
    ActionCommandHandler, 
    CommandAction, 
    CommandValidationError,
    CommandFactory
)

from myproject import post_status_msg


class ServiceStatus(CommandAction):
    def validate(self):
        if len(self.options) == 0:
            CommandValidationError(self.payload, "Missing service name")

    def execute(self):
        post_status_msg(self.options[0])


@CommandFactory.register("/status")
class StatusCommand(ActionCommandHandler):
    ACTIONS = {
        "service": ServiceStatus
    }

Views

To document

Actions

To document

Metadata

Release files for slacktools-interactivity 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slacktools-interactivity 1.2.1
File Size Uploaded Provenance Actions
slacktools-interactivity-1.2.1.tar.gz 10.4 kB Without provenance Details for slacktools-interactivity-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for slacktools-interactivity 1.2.1
File Interpreter ABI Platform Actions
slacktools_interactivity-1.2.1-py3-none-any.whl Python 3 none any Details for slacktools_interactivity-1.2.1-py3-none-any.whl

Total release size: 28.5 kB

Release files / slacktools-interactivity-1.2.1.tar.gz

Download URL slacktools-interactivity-1.2.1.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4c794c05f7472cc921651ff15c9b402296d80a4e02694f403bc937bdbdf9e837
BLAKE2b-256 checksum
How to use checksums
62452dcfbcdfd0afd8df16ed66560709fc426ce35d11fee85b25eab634ba3365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

Release files / slacktools_interactivity-1.2.1-py3-none-any.whl

Download URL slacktools_interactivity-1.2.1-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4c9a7b8705d49328fe90ec0ea926c926232cd0cd7c78a5ca6fadf36abfe96cf
BLAKE2b-256 checksum
How to use checksums
6bb78eddfeb0904758c3b9e567baffccd92072d441cfac632b0db36c24f006f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

Security for slacktools-interactivity 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page