rakshazi/telegram-notify
Composer 安装命令:
composer require rakshazi/telegram-notify
包简介
Get notifications from multiple services to Telegram
README 文档
README
This library collects data from multiple services, converts (transforms) it and send you as Telegram Message.
Usage
- Create Telegram Bot - you need only token here
- Add bot to any chat or send it a message directly
- Open URL
https://api.telegram.org/bot<BOT TOKEN>/getUpdates(replace<BOT TOKEN>with your bot token) and get your chat id(-s). - Write configuration array for Telegram Notify library:
<?php $config = [ 'token' => '<BOT TOKEN>', 'notifications' => [ [ 'chat_id' => '<YOUR CHAT ID>', 'parse_mode' => 'HTML', //currently supported only 'HTML' 'notify' => [ //List of integrations, you can add multiple accounts for each service and multiple services [ //RSS integration will post you messages with new items in feed 'type' => 'RSS', //Integration type 'source' => 'https://www.teamoctos.com/category/changelog/feed/' //Feed source URL ], [ 'type' => 'Email', //Works with any IMAP server 'source' => [ 'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX', //@link https://secure.php.net/manual/ru/function.imap-open.php 'user' => 'example@gmail.com', // your login 'password' => 'example-password' // your password ] ], [ 'type' => 'Trello', //Get all unread notifications from trello 'source' => [ 'api_key' => 'trello-app-key', //https://trello.com/app-key 'token' => 'trello-user-token' //https://developers.trello.com/authorize ], ] ], ], ], ];
Good! Now you need create function, which will check if message was already sent.
I use mauris/packer (you need dev-master version for exists function)
as storage for already sent messages, here is it:
<?php //Arguments: chat id, message text //Must return bool $isSent = function (string $chatId, string $message) { $key = md5($chatId.$message); $sent = new \Packer\Packer('./sent.pack'); if ($sent->exists($key)) { return true; } $sent->write($key, $message); return false; };
Very good! Final run script must be something like this (I use it for my private integration):
<?php require './vendor/autoload.php'; $config = [ 'token' => 'toke', 'notifications' => [ [ 'chat_id' => 'chat_id', 'parse_mode' => 'HTML', 'notify' => [ [ 'type' => 'RSS', 'source' => 'https://www.teamoctos.com/category/changelog/feed/' ], [ 'type' => 'Email', 'source' => [ 'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX', 'user' => 'example@gmail.com', 'password' => 'example-password' ] ], [ 'type' => 'Trello', 'source' => [ 'api_key' => 'key', 'token' => 'token' ], ] ], ], ], ]; $isSent = function (string $chatId, string $message) { $key = md5($chatId.$message); $sent = new \Packer\Packer('./sent.pack'); if ($sent->exists($key)) { return true; } $sent->write($key, $message); return false; }; $notify = new \Rakshazi\TelegramNotify($config, $isSent); $notify->run();
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-06