未提供项目描述
项目描述
slacktools 命令
一个使用 Slack 斜杠命令的简单框架 ( https://api.slack.com/interactivity/slash-commands )。
使用注册您的自定义Command
类,
ComandFactory
当您收到来自 Slack 的命令请求时,只需从工厂获取命令实例并执行它。
安装
pip install slacktools-commands
基本用法
定义你的命令:
from commands import register_command, Command, CommandValidationError
from myproject import get_status, post_status
@register_command("/status")
class StatusCommand(Command):
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)
处理 Slack 命令请求:
from rest_framework.views import APIView
from rest_framework.response import Response
from commands import CommandFactory
class CommandsView(APIView):
def post(self, request):
command = CommandFactory.make_commmand(request.data)
command.execute()
return Response()
动作命令
操作命令允许您从单个 Slack 命令执行许多不同的操作。命令后面的文本用于确定应执行的操作。文本由空格分隔,第一个字符集确定操作,其余字符集作为选项/参数传递给操作。
例子
以下类定义将处理以下命令:/status service api
from commands import ActionCommand, Action, CommandValidationError, register_command
from myproject import post_status_msg
class ServiceStatus(Action):
def validate(self):
if len(self.options) == 0:
CommandValidationError(self.payload, "Missing service name")
def execute(self):
post_status_msg(self.options[0])
@register_command("/status")
class StatusCommand(ActionCommand):
ACTIONS = {
"service": ServiceStatus
}
项目详情
关
slacktools -commands-1.0.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c6248e9363eb4c555cdcb7e46c0e42dee3bba646e67f084e51082b1463efe589 |
|
MD5 | 20c7f625c161c72b61a7a6dd19e846f2 |
|
布莱克2-256 | 3101c0b70cb46d1d63be1e8b1fb4fc8994d8921f1cc45b32cff9bab6d76a4e1c |
关
slacktools_commands -1.0.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5e204d0cb373f84e2676264f044a7927348bd6c8f80e527ac132962349262501 |
|
MD5 | a4b961cc4a1e136172679ec0d124a920 |
|
布莱克2-256 | c574c8562059294f9191dc243946b51008ba2610b9df137b5355434b6d2dbdb7 |