Merge pull request #202 from jessesung/telegram

Add support for sending notifications via Telegram
This commit is contained in:
John Reese 2016-07-28 15:30:38 -04:00 committed by GitHub
commit ca11c9b100
3 changed files with 42 additions and 1 deletions

View File

@ -23,6 +23,7 @@ conditions. ZNC Push current supports the following services:
* [Nexmo][] * [Nexmo][]
* [Pushalot][] * [Pushalot][]
* [Pushjet][] * [Pushjet][]
* [Telegram][]
* Custom URL GET requests * Custom URL GET requests
This project is still a Work In Progress, but should be functional enough and stable enough This project is still a Work In Progress, but should be functional enough and stable enough
@ -249,6 +250,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
* `airgram` * `airgram`
* `nexmo` * `nexmo`
* `pushjet` * `pushjet`
* `telegram`
* `url` * `url`
* `username` Default: ` ` * `username` Default: ` `
@ -264,7 +266,7 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
Authentication token for push notifications. Authentication token for push notifications.
This option must be set when using Notify My Android, Pushover, Prowl, Supertoasty, Airgram authenticated services, PushBullet, Nexmo or Pushjet. This option must be set when using Notify My Android, Pushover, Prowl, Supertoasty, Airgram authenticated services, PushBullet, Nexmo, Pushjet, or Telegram.
When using the custom URL service, if this option is set it will enable HTTP basic When using the custom URL service, if this option is set it will enable HTTP basic
authentication and be used as password. authentication and be used as password.
@ -283,6 +285,8 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
When using Airgram, this is the email address of the end user. When using Airgram, this is the email address of the end user.
When using Telegram, this is the id of the chat that receives the message.
### Notifications ### Notifications
@ -534,6 +538,7 @@ from me and not from my employer. See the `LICENSE` file for details.
[Nexmo]: https://www.nexmo.com [Nexmo]: https://www.nexmo.com
[Pushalot]: https://pushalot.com/ [Pushalot]: https://pushalot.com/
[Pushjet]: http://pushjet.io [Pushjet]: http://pushjet.io
[Telegram]: https://telegram.org/
[faq]: https://github.com/jreese/znc-push/blob/master/doc/faq.md [faq]: https://github.com/jreese/znc-push/blob/master/doc/faq.md
[examples]: https://github.com/jreese/znc-push/blob/master/doc/examples.md [examples]: https://github.com/jreese/znc-push/blob/master/doc/examples.md

18
doc/telegram.md Normal file
View File

@ -0,0 +1,18 @@
ZNC Push via Telegram
=====================
This section contains the specific steps to configure for [Telegram][] after you install the
module by following the above steps.
* First of all, you need to have a telegram account.
* Talk to [BotFather][] to create a new bot and get an api key.
* Create a chat with the bot and say something in the chat.
* Use browser to connect to https://api.telegram.org/bot[apikey]/getUpdates (replace the apikey with
the key generated by BotFather). You should see messages sent from you, and there will be several
id fields in the reply. We'll use the one in the chat session.
* set service to 'telegram': <code>/msg *push set service telegram</code>
* set secret to the **api key**: <code>/msg *push set secret your-api-key</code>
* set target to chat ID: <code>/msg *push set target your-chat-id</code>
[Telegram]: https://telegram.org
[BotFather]: https://core.telegram.org/bots#6-botfather

View File

@ -676,6 +676,20 @@ class CPushMod : public CModule
params["level"] = options["message_priority"]; params["level"] = options["message_priority"];
} }
} }
else if (service == "telegram")
{
if ((options["secret"] == "") || (options["target"] ==""))
{
PutModule("Error: secret (API key) or target (chat_id) not set");
return;
}
service_host = "api.telegram.org";
service_url = "/bot" + options["secret"] + "/sendMessage";
params["chat_id"] = options["target"];
params["text"] = message_content;
}
else else
{ {
PutModule("Error: service type not selected"); PutModule("Error: service type not selected");
@ -1423,6 +1437,10 @@ class CPushMod : public CModule
{ {
PutModule("Note: Pushjet requires setting 'secret' (service key) option"); PutModule("Note: Pushjet requires setting 'secret' (service key) option");
} }
else if (value == "telegram")
{
PutModule("Note: Telegram requires setting both the 'secret' (api key) and 'target' (chat_id)");
}
else else
{ {
PutModule("Error: unknown service name"); PutModule("Error: unknown service name");