cromwell/slacker
Composer 安装命令:
composer require cromwell/slacker
包简介
Slack notifier
关键字:
README 文档
README
A quick Slack notifier for PHP
Simplified usage
<?php
require __DIR__ . '/vendor/autoload.php';
// setup with a configured Guzzle client
$slacker = new \Slacker\Slack(
$config['webhook'],
new \GuzzleHttp\Client()
);
// or with a default Guzzle client you need not pass it in
$slacker = new \Slacker\Slack($config['webhook']);
$slacker
->channel('#general')
->username('Slacker')
->message('Hello, #general')
->send();
// Or simpler, using the defaults chosen for the webook within Slack:
$slacker->message('Hello!')->send();
Calls to channel or username persist across uses, whereas calls to message reset the message and the attachment.
Regular usage
<?php
require __DIR__ . '/vendor/autoload.php';
$config = require(__DIR__ . '/slack-config.php');
// general setup
$slackPoster = new \Slacker\SlackPoster(
new \GuzzleHttp\Client(),
$config['hookUri']
);
$payload = new \Slacker\Payload\Payload();
$payload->username = $config['username'];
$payload->channel = $config['channel'];
// specific message setup
$payload->text = 'General Message Text';
$attachment = new \Slacker\Payload\Attachment();
$attachment->color = 'good';
$attachment->fallback = 'some fallback message';
$field = new \Slacker\Payload\Field();
$field->short = 'Field Short Message';
$field->title = 'Field Title';
$field->value = 'Field Value';
$attachment->addField($field);
$field = new \Slacker\Payload\Field();
$field->short = 'Field Short Message 2';
$field->title = 'Field Title 2';
$field->value = 'Field Value 2';
$attachment->addField($field);
$field = new \Slacker\Payload\Field();
$field->short = 'Field Short Message 3';
$field->title = 'Field Title 3';
$field->value = 'Field Value 3';
$attachment->addField($field);
$payload->addAttachment($attachment);
// send the message
$slackPoster->send($payload);
统计信息
- 总下载量: 94
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-15