walkboy/yii2-slack

Yii2 slack客户端

安装: 49

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 10

类型:扩展

1.0.1 2022-11-08 05:09 UTC

This package is auto-updated.

Last update: 2024-09-08 09:13:28 UTC


README

设计用于向Slack消息传递发送消息

How it looks

基于未维护的https://github.com/Understeam/yii2-slack

安装

composer require walkboy/yii2-slack:^1.0

此外,您应该在Slack团队内部配置入站Webhook

用法

首先,配置yiisoft/yii2-httpclient组件

...
    'components' => [
        'httpclient' => [
            'class' => 'yii\httpclient\Client',
        ],
    ],
...

您也可以只在Slack客户端内设置它

...
    'components' => [
        'slack' => [
            'httpclient' => [
                'class' => 'yii\httpclient\Client',
            ],
            ...
        ],
    ],
...

配置组件

...
    'components' => [
        'slack' => [
            'class' => 'walkboy\slack\Slack',
            'url' => '<slack incoming webhook url here>',
            'username' => 'My awesome application',
        ],
    ],
...

现在您可以通过以下命令直接将消息发送到Slack频道

Yii::$app->slack->send('Hello', ':thumbs_up:', [
    // block object 1
    [
        'type' => 'context',
        'elements' => [
            [
                'type' => 'mrkdwn',
                'text' => 'Your markdown text here',
            ]
        ],
    ],
    // block object 2
    [
        'type' => 'divider',
    ]
]);

要了解更多关于块的信息,请阅读Slack文档

您还可以将Slack用作日志目标

...
'components' => [
    'log' => [
        'traceLevel' => 3,
        'targets' => [
            [
                'class' => 'walkboy\slack\LogTarget',
                'categories' => ['commandBus'],
                'exportInterval' => 1, // Send logs on every message
                'logVars' => [],
            ],
        ],
    ],
],
...