nathanmac / instant-messenger
即时通讯包。
v1.2
2015-03-09 13:30 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~4.0
- illuminate/container: 5.0.*
- illuminate/contracts: 5.0.*
- illuminate/support: 5.0.*
- psr/log: ~1.0
Requires (Dev)
- henrikbjorn/phpspec-code-coverage: 1.0.1
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 16:55:32 UTC
README
支持的服务
- HipChat
- Slack
- Hall
- Jaconda
- Sqwiggle
- Gitter
- FlowDock
- Campfire
- Grove
- Telegram
- Twillo (SMS)
- IRC
安装
首先,通过Composer安装此包。编辑您的项目composer.json
文件,以要求nathanmac/instant-messenger
。
"require": {
"nathanmac/instant-messenger": "1.*"
}
接下来,从终端更新Composer
composer update
Laravel用户
如果您是Laravel用户,则可以使用一个服务提供商来自动准备绑定等。
// app/config/app.php 'providers' => [ '...', 'Nathanmac\InstantMessenger\MessengerServiceProvider' ];
配置
安装后,您可以通过运行以下命令将包配置文件发布到您的应用程序
php artisan vendor:publish nathanmac/instant-messenger
控制台命令
安装并添加服务提供商到配置文件后,现在您可以访问messenger:send
命令,该命令允许您从命令行发送简单通知。以下演示了发送简单消息的过程。
$ php artisan messenger:send "This is a test message to be sent using the configured service." --from "Auto Notifier"
示例
<?php require 'vendor/autoload.php'; use Nathanmac\InstantMessenger\Messenger; use Nathanmac\InstantMessenger\Services\HipChatService; use Nathanmac\InstantMessenger\Services\SlackService; use Nathanmac\InstantMessenger\Services\HallService; use Nathanmac\InstantMessenger\Services\JacondaService; use Nathanmac\InstantMessenger\Services\SqwiggleService; use Nathanmac\InstantMessenger\Services\GitterService; use Nathanmac\InstantMessenger\Services\FlowDockService; use Nathanmac\InstantMessenger\Services\CampFireService; use Nathanmac\InstantMessenger\Services\GroveService; use Nathanmac\InstantMessenger\Services\TelegramService; use Nathanmac\InstantMessenger\Services\TwilioService; // Twilio $transport = new TwilioService('TWILIO ACCOUNT SID', 'TWILIO AUTH TOKEN', 'FROM PHONE', 'TO PHONE'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); }); // Telegram $transport = new TelegramService('TELEGRAM TOKEN', 'CHAT ID'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); }); // Grove $transport = new GroveService('GROVE CHANNEL TOKEN'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->from('Bot'); $message->body('Hello this is a simple notification.'); }); // CampFire $transport = new CampFireService('CAMPFIRE SUBDOMAIN', 'CAMPFIRE API TOKEN', 'CAMPFIRE ROOM ID'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); }); // FlowDock $transport = new FlowDockService('FLOW API TOKEN', ['any', 'tags', 'for', 'the', 'message']); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); $message->from('Bot'); $message->tags('more', 'tags', 'as', 'required'); $message->tag('OMG'); }); // Gitter $transport = new GitterService('GITTER API TOKEN'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); }); // Hipchat $transport = new HipChatService('HIPCHAT API TOKEN', 123456); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); }); // Sqwiggle $transport = new SqwiggleService('SWIGGLE_TOKEN', 12345); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); }); // Slack $transport = new SlackService('WEBHOOK TOKEN', '#channel'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); $message->from('John Smith', 'john.smith@example.com'); }); // Hall $transport = new HallService('API TOKEN'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); $message->from('John Smith'); }); // Jaconda $transport = new JacondaService('account', 'ROOM TOKEN', 'room'); $messenger = new Messenger($transport); $messenger->send(function($message) { $message->body('Hello this is a simple notification.'); $message->from('John Smith'); });