Telegram Notifications Plugin (discourse-telegram-notifications)

(David Taylor) #1

Discourse Telegram Notifications Plugin

This plugin allows users to receive their notifications via a Telegram bot, allowing them to turn off email notifications and still keep up-to-date. :success:

You can “like” posts, and respond to them via the bot.

Here’s a quick demo video:

Before Starting

  • Your forum must be using HTTPS, and have force_https turned on
  • Your forum must be accessible to the internet, not only an internal network (in development, give ngrok a try).

Getting the plugin setup

  1. Install the plugin using the instructions here: How to install a plugin
  2. Create a telegram bot by talking to the BotFather (instructions here)
  3. Paste the “token” into the site setting “telegram access token”
  4. Tick “telegram notifications enabled”

I strongly recommend you use the BotFather’s /setjoingroups command to disable the bot being used for group chats. It is not designed for it, and risks leaking information that users are not supposed to be able to access (e.g. you don’t want private messages being sent to a group chat).

You can set the name/picture/description of your bot using the instructions here

For users to receive notifications

  1. Send a message to the bot, you’ll receive a message back that looks like

To get notifications for Discourse, enter the ‘Chat ID’ 1234567 in your user preferences

  1. Visit your user preferences, and paste the number in the Telegram Notifications box
  2. You should now receive notifications by telegram message!

Find out who’s using telegram for notifications

Here’s a query for the data explorer plugin:

SELECT user_id, updated_at, value from user_custom_fields
WHERE name = 'telegram_chat_id'

This is still a work in progress. I think the next task would be to improve the setup flow for the user, so they don't have to copy/paste numbers between telegram and the forum.

Related discussions are: here, here, here and here

As always, suggestions and comments are very welcome :slight_smile:

Set up Telegram notifications using the discourse-chat-integration plugin
Notifications via Facebook
Confused about the "Nice Share" badge
Better terms for watching (and tracking?)
How to link your community to the discourse app?
iOS Mobile App Notifications
Set up Telegram notifications using the discourse-chat-integration plugin
Chatroom Integration Plugin (discourse-chat-integration)
(Алексей Копаев) #2

It would be nice to be able to respond with Telegram on notice.
2) Create a new post
3) View popular topics

(Ed Arcos) #3

@david thanks a lot for the plugin! I just send a pull request with spanish localization files :slight_smile:


Hi, thanks for awesome work.
But I failed to set it up: created a bot in Telegram, got token, installed plugin and set settings (enabled + token), open bot in telegram, sent “/start” (or any other message). But the bot doesn’t answer anything…
What can be wrong?

(David Taylor) #5

Can you check the logs and see if there is anything there?

I should probably mention this will only work for https forums which are accessible to the internet (not just internal networks) - will add that to the top post.


Beautiful, too bad I can’t hop in yet as we don’t have https on our domain yet.

(David Taylor) #7

Unfortunately the HTTPS thing is a restriction from the telegram API, so there’s nothing I can do about it :frowning:


What about it? The Telegram for Wordpress bot functions without it. And it works well to push updates as seen here.

(David Taylor) #9

I’m using the webhook api to save maintaining a constant connection between the discourse server and the telegram server. It may be that the Wordpress plugin uses other parts of the API

Telegram Bot API


Yeah, there’re a lot of errors:

Job exception: undefined method `length' for nil:NilClass


/var/www/discourse/plugins/discourse-telegram-notifications/plugin.rb:102:in `execute'
/var/www/discourse/app/jobs/base.rb:154:in `block (2 levels) in perform'

Sure, my site have https and Internet access.

(David Taylor) #11

Well, that’s not gone well! I’ve just committed a fix for that particular error, so can you please try updating and see if that helps?

(Arun Sathiya) #12

Rooting to see these features soon. Will be very handy!


I’ve updated plugin, errors stop appearing , but my bot still doesn’t answer anything…

(David Taylor) #14

In case anyone else has the same issue, “force_https” needs to be turned on. I will update the first post.


Feature request:
an ability to filter categories from which notifications should go via Telegram

(Gilang) #16

This is real nice.
i’ve tried and works. but yes, keep it going so user not must put manual ID to forum settings

(David Taylor) #17

You can now like & respond to posts using the bot :slight_smile:

(Ed Arcos) #18

Oh wow!! This is amazing. Let me update the spanish translation, I’ll send a pull request in a few minutes :slight_smile:

(GoXonLine) #19

Hi, I got an error went I try to activate the plugin. I have a full https server with a valid certificate and internet access. But went I active the plugin, I get this error in the logs:

ActionView::MissingTemplate (Missing template discourse_telegram_notifications/telegram/hook, application/hook with {:locale=>[:es, :en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. Searched in:
  * "/var/www/discourse/app/views"
  * "/var/www/discourse/plugins/docker_manager/app/views"
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/actionview-4.2.8/lib/action_view/path_set.rb:46:in `find'


NoMethodError (undefined method `user_id' for nil:NilClass)
/var/www/discourse/plugins/discourse-telegram-notifications/plugin.rb:57:in `hook'

Im using the last version of Discourse, with the Spanish locate and Cloudflare CDN (I disable the cloudflare CDN for a test an I get the same error).

I dont know where is the error, but if you need more information just let me know.

Regards, GoX

(David Taylor) #20

I’ve just pushed a fix for this one - update to the latest version and it should be fixed.

As for this one, can you try removing your telegram API key from the site settings, and then re-adding it. Hopefully that’ll reset the callback URL with telegram.

Let me know how it goes :slight_smile: