kriss/yii2-beary-chat yii2 bearyChat component

bearychatincomingwebhookrobot

yii2 bearyChat

yii2 bearyChat 组件,依赖BearyChat for PHP

安装

推荐使用 composer.

php composer.phar require --prefer-dist kriss/yii2-beary-chat "*"

或添加下面代码到composer.json文件

"kriss/yii2-beary-chat": "*"

然后使用

php composer.phar update

使用方式

单独使用

1.进行配置

basic 模版为 config/web.php, advanced 模版为对应入口的 config/main.php

示例配置如下:

'components' => [
    .....
    'bearyChat' => [
        'class' => 'kriss\bearyChat\Incoming',
        'clients' => [
            'default' => [
                'webhook' => 'https://hook.bearychat.com/=XXXX/incoming/XXXXXXXXXXXXXX',
                 'message_defaults' => [
                     'attachment_color' => '#f5f5f5',
                 ]
            ],
            // 'admin' => [
            //     'webhook' => '',
            // ],
        ]
    ],
    ...
]

2.进行使用

最简单的使用方式:

Yii::app->bearyChat->client()->sendMessage(json_encode(['text'=>'hello world']));

更多使用方式参看: BearyChat for PHP

tips:Yii::app->bearyChat->client()获得的即是\ElfSundae\BearyChat\Client

配合 yii2-thread 使用

发送一条 BearyChat 消息实际上是向 Incoming Webhook 发送同步 HTTP 请求,所以这在一定程度上会延长应用的响应时间。可以使用 yii2-thread (或任意多线程方式)来异步发送消息。

使用 yii2-thread 只需要在对应位置使用发送消息的代码就可以,使用方式不变

参考链接:yii2-thread

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

  • 1.014 July 2016

Comments



1.0 is the latest of one release



MIT license
Stats
2 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
109 total downloads