nexylan/slack-bundle

nextylan/slack 库的 Symfony 扩展包集成

安装次数: 1,125,670

依赖者: 0

建议者: 8

安全性: 0

星星: 109

关注者: 6

分支: 20

开放问题: 10

类型:symfony-bundle

v2.3.0 2021-03-31 13:25 UTC

This package is auto-updated.

Last update: 2024-08-29 04:14:32 UTC


README

nextylan/slack 库的 Symfony 扩展包集成(旧流行 maknz/slack)。

Latest Stable Version Latest Unstable Version License Dependency Status Reference Status

Total Downloads Monthly Downloads Daily Downloads

Build Status Scrutinizer Code Quality Code Climate Coverage Status SensioLabsInsight

文档

所有的安装和使用说明都位于本 README 中。请查看特定版本

  • 1.x 支持 Symfony >=2.7
  • 2.x 支持 Symfony >=3.4

先决条件

本项目版本需要

  • PHP 7.1+
  • Symfony 3.4+

安装

首先,您需要通过 composer 引入此库

$ composer require nexylan/slack-bundle php-http/guzzle6-adapter

为什么是 php-http/guzzle6-adapter? 我们通过 HTTPlug 与任何 HTTP 消息客户端解耦。

然后,在 AppKernel 类中启用此扩展包

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Http\HttplugBundle\HttplugBundle(),
        new Nexy\SlackBundle\NexySlackBundle(),
    );

    // ...

    return $bundles
}

配置

如果尚未完成,您必须首先配置 httplug-bundle。请参阅此处的官方文档。

根据您的需求配置此扩展包(示例使用默认值)

nexy_slack:

    # If you want to use an another httplug client service.
    http:
        client: httplug.client

    # The Slack API Incoming WebHooks URL.
    endpoint:             ~ # Required
    channel:              null
    username:             null
    icon:                 null
    link_names:           false
    unfurl_links:         false
    unfurl_media:         true
    allow_markdown:       true
    markdown_in_attachments: []

endpoint 外,所有其他配置键都与 Slack 客户端默认设置相关。

所有这些设置在 nexylan/slack 文档 中都有描述。

用法

可以从 nexy_slack.client 服务获取 Slack 客户端实例。

以下是一个示例

<?php

namespace AppBundle\Controller;

use Nexy\Slack\Attachment;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $slack = $this->get('nexy_slack.client');

        $message = $slack->createMessage();

        $message
            ->to('#test')
            ->from('John Doe')
            ->withIcon(':ghost:')
            ->setText('This is an amazing message!')
        ;

        $message->attach((new Attachment())
             ->setFallback('Some fallback text')
             ->setText('The attachment text')
         );

        $slack->sendMessage($message);
    }
}

有关如何操作 Slack 客户端的更多信息,请参阅 nexylan/slack 文档