gotoemma/slack-bundle

此包的最新版本(0.4.0)没有可用的许可信息。

此捆绑包提供了基本功能,可以快速通过斜杠命令将您的 Slack 机器人与 symfony 项目连接起来。

安装量: 3,474

依赖项: 0

建议者: 0

安全性: 0

类型:项目

0.4.0 2018-05-17 16:30 UTC

This package is auto-updated.

Last update: 2024-09-18 06:54:07 UTC


README

此捆绑包提供了基本功能,可以快速通过斜杠命令将您的 Slack 机器人与 symfony 项目连接起来。

简单地创建一个类,实现提供的 CommandInterface,并标记为 "slack.command",您的斜杠命令就准备好了!

SlackBundle 会验证请求中发送的令牌,以确保此请求经过授权且来自 Slack。然后它搜索标记为 slack.command 的服务,以确定是否支持给定的请求。收集所有支持服务的数据后,它将向 Slack 发送响应。

The default list command

依赖项

  • Symfony 3.1
  • PHP 7.0

设置

  • 创建您自己的命令类并实现 Gotoemma\SlackBundle\Service\CommandInterface
  • 使用 "slack.command" 标记您的服务
  • 访问 https://api.slack.com/apps 并创建一个应用
  • 将 clientId、clientSecret 和 token 添加到您的 config.yml 中
  • 设置您的第一个斜杠命令,并将 https://your.url/webhook/slack 设置为 webhook url(使用 POST 请求)

您项目的主要 composer.json

"repositories": [
        {
            "type": "git",
            "url": "https://bitbucket.org/gotoemma/slack-bundle.git"
        }
    ],

然后输入 composer require gotoemma/slack-bundle

app/config/config.yml

slack:
  client_id:      "%slack_client_id%"
  client_secret:  "%slack_client_secret%"
  token:          "%slack_token%"

app/config/routing.yml

加载在 UploadAction 类的 __invoke() 方法上配置的 upload 行为的路由作为注释。

slack_action:
    resource: '@SlackBundle/Action/'
    type:     'annotation'

您的第一个命令提供者

SlackBundle 随附一个默认命令:/list。此命令列出在 Slack 中注册的所有命令。您需要做的只是将斜杠命令添加到 api.slack.com/apps。

此命令也可以用作您第一个自定义命令的基础。

<?php

namespace YourNamespace\YourBundle\Provider;

use Doctrine\Common\Collections\ArrayCollection;
use Gotoemma\SlackBundle\Dto\Attachment;
use Gotoemma\SlackBundle\Dto\Field;
use Gotoemma\SlackBundle\Provider\CommandProviderInterface;

class YourCommandProvider implements CommandProviderInterface
{

    /**
     * Return true if this CommandProviders handleCommand() method should be called for the given arguments
     *
     * @param string $command
     * @param array $parameters
     * @return boolean
     */
    public function supportsCommand(string $command, array $parameters);

    /**
     * Return true if the registeredCommands argument should be set on handleCommand() call
     *
     * @return boolean
     */
    public function injectRegisteredCommands();

    /**
     * @param string $command
     * @param array $parameters
     * @param ArrayCollection $registeredCommands ArrayCollection of all CommandProviders that registered for SlackBundle
     * @return Attachment
     */
    public function handleCommand(string $command, array $parameters, $registeredCommands = null);

    /**
     * Return a Field object containing some user instructions how to use your command
     * which will be shown in slack if one uses the ListCommand
     *
     * @return Field
     */
    public function getDescription();
}