Discourse Chat Bridge (Telegram)

:information_source: Summary Bridge your discourse chat to telegram
:hammer_and_wrench: Repository Link https://github.com/Lhcfl/discourse-chat-bridge
:open_book: Install Guide How to install plugins in Discourse

I’m working on bridging Discourse to other platforms. Currently it only supports Telegram, but I plan to support Matrix, and maybe Discord or QQ in the future, depending on my energy and the support I receive.

This plugin only supports the absolutely latest Discourse test-passed branch. Why? Because Discourse Chat changes their code frequently, I have to sync with them.

So if the plugin is available on your site and the plugin is important to you, please reduce the frequency of updating discourse, because I may not have time to synchronize the version of the patch code with discourse.

Telegram bridge

IMPORTANT NOTES

This plugin uses usernames with .tgid and .tg suffixes to synchronize user information (Telegram
→ Discourse)

If there are usernames with the above suffixes on your website, the user may be taken over by this plugin!

Feature list

This plugin is currently my own work. It is difficult for me to spend too much energy to fix bugs that I think are not urgent enough. So if the bug you find is not in this list, please consider PR.

This plugin supports syncing the following content:

  • Plain Text (Certainly!)

  • Formated Text: Bold, Italic, strikethrough, spoiler, inline code and

    "code block"
    
  • Quotations (only Discourse → Telegram)
    We do not support quotations for Telegram → Discourse now because Telegram does not yet updated their API for quotes.

  • Pictures, stickers and videos
    As I write this sentence, there seems to be something broken in Discourse. Simply posting a picture without a caption will not trigger the :chat_message_created event. Therefore, it is impossible to forward Discourse pictures to Telegram. This error may be solved automatically in the future, but no matter what, I will fix it.

  • Reply

  • Message edition (Text only)

  • Forward messages (Telegram → Discourse)

  • Message deletion (Discourse → Telegram)
    We will NOT support message deletion for Telegram → Discourse because the Telegram bot api does not provide an interface for listening to message deletion events.

  • User avatar and usernames (Telegram → Discourse)

The following content are not implemented and are planed to be supported in the future

  • Quotation (Telegram → Discourse)
  • Album pictures (Discourse ↔ Telegram)
    Currently only supports syncing the first picture

Preview


Configuration

SiteSetting.chat_telegram_bridges

It is a list and you need to fill in each column in this format:

discourse_chat_channel_id,telegram_chat_id,bot_token

For example

3,-123456789,123456789-XXXXXXXXXXXXXXXXXXXXXXXXXXXX

will bridge discourse chat channel 3 ↔ telegram chat -123456789 using bot with token 123456789-XXXXXXXXXXXXXXXXXXXXXXXXXXXX

DO NOT add spaces after commas.

It’s certainly not elegant, but I don’t have the extra energy to write a beautiful configuration interface for it. Please PR if you want it.

Allow sync videos and video stickers

Telegram’s dynamic stickers, gifs, and videos are basically in webp format. You need to allow uploading it in the SiteSettings.authorized_extensions, otherwise you will only get a [This message is not supported yet]

CHANGELOG

  • 2023/11/07 Released 0.0.1

TODO

  • Bridge Matrix to discourse
22 Likes

This looks amazing, good job! :+1:

This should be site_settings :slight_smile:

2 Likes

Oh my god, thank you, I’ll change it right away

…And it shoud be in client.en.yml. I wrote the code in the early morning, and it looks like the code quality is a bit bad. :melting_face:

3 Likes

Amazing work, thanks for creating this!

4 Likes

I tested it a little, and it works fine! :+1:

2 Likes

Hello!
Thank you for such a wonderful plugin :raised_hands: This is what I’ve been thinking about for the last couple of months :confetti_ball:. You seem to have captured my thoughts :sweat_smile:
I want to clarify. Will the plugin only work for chat mode or can it also be connected to a topic?

Can you elaborate a little more specifically?

2 Likes

Hello! Sorry if I didn’t express my thoughts enough :pray:. I’m using Google Translate and can’t be sure I’m understanding the posts on this forum correctly. And I don’t know how to program, so I don’t always understand programmers’ messages. Let me show you my question in diagram form:

I probably understand what you mean… Do you want the content in chat to be published in the topic simultaneously?
I had a ready-made nodejs software before this, but it needed to be adapted to other forums. And I have been very busy recently and have no time to do this.
For a while, it will only support chat.

2 Likes

I’m not entirely sure if I understood your question correctly, but I’ll try to explain step by step what I envision. In the period from 2021 to 2022, I attempted to create a forum based on Discourse. However, despite the relevance of the forum, the project was unsuccessful because, in our region (Central Asia), the majority of residents prefer using messengers such as Telegram and WhatsApp instead of registering and using new features on websites.

With the advent of artificial intelligence, I observed changes in the rules of the game. Various services, including websites and applications designed for the use of artificial intelligence, emerged. Messengers cannot fully provide functionality for working with artificial intelligence, although Telegram is more advanced than WhatsApp. Learning about new plugins in Discourse, such as Discourse AI and Chatbot, I realized that this was a new opportunity for my website.

I want to fully utilize the ability to create thematic posts (topics). Recently, I asked a question here - on Meta about the Chatbot plugin, wondering if the GPT chat can remember the first post and not forget the content of the main topic after numerous messages in the thread. Then, @merefield replied that the chatbot will always remember the first post. This became the main criterion for applying this plugin on my site.

I plan to create thematic sections on the forum for interaction with artificial intelligence and real people. The communication format in Discourse through creating topics is more advanced technically compared to chats. Therefore, chats are not entirely suitable for training the bot since in a chat, the bot may not remember the initial topic among numerous recent messages. I plan to use the capability of creating thematic posts, training the bot in the first post so that it can respond to user questions within the specified topic.

However, considering the popularity of messengers in our region and people’s habit of using chats, I am contemplating how to provide users with the Discourse forum experience without abandoning their familiar messengers. After installing the Discourse Chat Bridge plugin, I found that it connects the Discourse chat with the Telegram chat but does not create a bridge between a published post on the forum and the Telegram chat.

My plans include:

  1. A user (possibly site personnel) sends a private message (PM) to the AI bot on the forum with instructions on how the bot should respond to subsequent messages, such as advising other users on using the forum.

  2. The user links this private message to the artificial intelligence in a regular Telegram bot.

  3. The user shares the link to the Telegram bot with other users who are not yet registered on the forum but want to learn more about it.

  4. Each user, clicking on the link in the Telegram bot, starts a private conversation with artificial intelligence, which responds and advises according to the instructions posted on the forum.

  5. All user messages directed to artificial intelligence are published in a private forum topic. Thus, Telegram users do not see messages from other Telegram users, as each user communicates separately with the Telegram bot.

So you plan to use the Telegram bot as a funnel for users coming to the forum or you want to allow users to stay only in Telegram interacting with the Ai bot (the Ai bot being a proxy between the forum content and the user)?

1 Like

All right… this looks like a very personalized feature and I don’t think I would add this feature for free, because my energy is very limited.

1 Like

Yes, that’s right, the telegram bot/chat will be used as a mirror and duplicate content from the forum and back.

Ok, I got you. I’m currently doing general prep work on my website. If you allow, I will return to this topic in a few weeks with more specific proposals in a personal message to you.

I’m very interested in this and offer to help if you need.

1 Like

Okay, thanks for the offer :raised_hands:, I’ll come back as soon as I’m ready.

1 Like

While testing, it seems I discovered a bug in the plugin. After I send a message to the chat via Telegram → Discourse, nothing appears on the site in the chat (sometimes only 1234567890.tgid username appears). To solve this problem I have to refresh the site page. After updating, the name of the message sender appears, but the contents of the message itself are not shown. To solve this problem, I rearrange the HTML and then the chat message text appears. Here’s a video:

Also, I wanted to clarify. If I send a message via Telegram to a group chat without using the Reply button, the message does not reach the chat in Discourse. It turns out that in order for the message to be sent, I must select the Reply function in telegram chat. But what if I don’t want to respond to anyone’s message in the chat, but just want to send a message with a question to all group members?

1 Like

I noticed this problem a few days ago, I just never got around to fixing it, really. My todo list is piled up right now.

A recent update to Discourse Chat broke this plugin. I need to find time to adapt it, or directly submit the functions I need to the core.

I’m waiting for a response. Now due to the lack of this feature, I need to monkey patch, and my plugin may be broken by a commit at any time.

2 Likes

Ok, I got you. I hope the development team will pay attention to your message :pray:

1 Like