diff --git a/README.md b/README.md index 5e3864a..90d4aa3 100755 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ conditions. ZNC Push current supports the following services: * [Nexmo][] * [Pushalot][] * [Pushjet][] +* [Telegram][] * Custom URL GET requests 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` * `nexmo` * `pushjet` + * `telegram` * `url` * `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. - 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 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 Telegram, this is the id of the chat that receives the message. + ### Notifications @@ -534,6 +538,7 @@ from me and not from my employer. See the `LICENSE` file for details. [Nexmo]: https://www.nexmo.com [Pushalot]: https://pushalot.com/ [Pushjet]: http://pushjet.io +[Telegram]: https://telegram.org/ [faq]: https://github.com/jreese/znc-push/blob/master/doc/faq.md [examples]: https://github.com/jreese/znc-push/blob/master/doc/examples.md diff --git a/doc/telegram.md b/doc/telegram.md new file mode 100644 index 0000000..0981973 --- /dev/null +++ b/doc/telegram.md @@ -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': /msg *push set service telegram +* set secret to the **api key**: /msg *push set secret your-api-key +* set target to chat ID: /msg *push set target your-chat-id + +[Telegram]: https://telegram.org +[BotFather]: https://core.telegram.org/bots#6-botfather diff --git a/push.cpp b/push.cpp index 57fef1b..77a2758 100755 --- a/push.cpp +++ b/push.cpp @@ -676,6 +676,20 @@ class CPushMod : public CModule 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 { PutModule("Error: service type not selected"); @@ -1423,6 +1437,10 @@ class CPushMod : public CModule { 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 { PutModule("Error: unknown service name");