rakshazi/telegram-notify 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rakshazi/telegram-notify

Composer 安装命令:

composer require rakshazi/telegram-notify

包简介

Get notifications from multiple services to Telegram

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

This library collects data from multiple services, converts (transforms) it and send you as Telegram Message.

Usage

  1. Create Telegram Bot - you need only token here
  2. Add bot to any chat or send it a message directly
  3. Open URL https://api.telegram.org/bot<BOT TOKEN>/getUpdates (replace <BOT TOKEN> with your bot token) and get your chat id(-s).
  4. 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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固