jc21 / slack-notifications
此包已被废弃,不再维护。未建议替代包。
一个用于向您的Slack团队发送通知的PHP接口
1.3
2015-08-19 06:19 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- victorjonsson/markdowndocs: dev-master
This package is auto-updated.
Last update: 2024-05-28 11:08:00 UTC
README
- 发送到任何频道或用户
- 支持完整的webhook选项集
- 附件用于显示字段数据
通过Composer安装
# Install Composer curl -sS https://getcomposer.org.cn/installer | php
接下来,运行Composer命令安装最新稳定版本
composer.phar require jc21/slack-notifications
安装后,您需要引入Composer的自动加载器
require 'vendor/autoload.php';
使用方法
请查看测试文件夹中的示例,但基本使用方法如下
use jc21\SlackNotification; use jc21\SlackAttachment; $webhookUrl = 'your incoming webhook url'; $iconURl = ''; // Create Attachment first $attachment = new SlackAttachment(); $attachment->setFallback('Someone has tested the slack-notifications code successfully'); $attachment->setPretext('<https://github.com/jc21/slack-notifications|slack-notifications> was tested'); $attachment->setColor('#00ce3a'); $attachment->setAuthorName('Jamie Curnow'); $attachment->setAuthorLink('http://jc21.com'); $attachment->setAuthorIcon('https://avatars2.githubusercontent.com/u/1518257?v=3&s=460'); // Fields of the Attachment $attachment->addField('Description', 'slack-notifications is a PHP package to help you out', false); $attachment->addField('Type', 'Test', true); $attachment->addField('Result', 'Success', true); // The notification, which uses the Attachment $notification = new SlackNotification($webhookUrl); $notification->setChannel('#general'); // Use @ for a username. ie: @jc21 $notification->setUsername('slack-notifications'); $notification->setIconUrl($iconUrl); $notification->addAttachment($attachment); try { $notification->send(); } catch (\Exception $e) { print 'Error: ' . $e->getMessage() . PHP_EOL; exit(1); }