2017 © Pedro Peláez
 

library telegram-notify

Get notifications from multiple services to Telegram

image

rakshazi/telegram-notify

Get notifications from multiple services to Telegram

  • Sunday, November 6, 2016
  • by rakshazi
  • Repository
  • 1 Watchers
  • 2 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Telegram Notify

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

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

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., (*3)

I use mauris/packer (you need dev-master version for exists function) as storage for already sent messages, here is it:, (*4)

<?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):, (*5)

<?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();

The Versions

06/11 2016

dev-master

9999999-dev

Get notifications from multiple services to Telegram

  Sources   Download

MIT

The Requires

 

06/11 2016

1.1

1.1.0.0

Get notifications from multiple services to Telegram

  Sources   Download

MIT

The Requires

 

06/11 2016

v1.0

1.0.0.0

Get notifications from multiple services to Telegram

  Sources   Download

MIT

The Requires

  • ext-curl *
  • ext-iconv *
  • ext-imap *
  • ext-simplexml *