0 Section Telegram (basic)
Mark Glasgow edited this page 2022-03-18 13:40:21 +00:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[telegram.mytelegram]
#See https://core.telegram.org/bots#6-botfather 
#and https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
Token="Yourtokenhere"
RemoteNickFormat="({PROTOCOL}) {NICK} "
MessageFormat="HTMLNick"

Retrieving your chat number from Matterbridge

Setup

Matterbridge can output your chat number as debug information. Heres how. - Bring up a bot as described above and retrieve your API token. - Make sure to disable privacy mode on the bot. - Configure Matterbridge as illustrated above - Join the bot to your Telegram group

Via /chatId

  • Available in matterbridge 1.24.0, enter /chatId in the chat and the bot will reply with the ID

Generate events / output

  • Start Matterbridge with your new configuration in debug mode like so: matterbridge -debug -conf matterbridge.toml
  • Create traffic in your group, chat up your bot.
  • Matterbridge will output debug information, this will look similar to this [0009] DEBUG telegram: <= Message is config.Message{Text:"test from telegram", Channel:"-987654321", Username:"John Doe", UserID:"123456789", Avatar:"", Account:"telegram.mytelegram", Event:"", Protocol:"", Gateway:"", Timestamp:time.Time{wall:0x0, ext:> 0, loc:(*time.Location)(nil)}, ID:"31", Extra:map[string][]interface {}{}} or [0024] DEBUG telegram: => Receiving config.Message{Text:"test from xmpp", Channel:"-987654321", Username:"[xmpp] <userredacted> ", UserID:"example@conference.redacted.com/userredacted", Avatar:"", Account:"xmpp.myxmpp", Event:"", Protocol:"", Gateway:"gateway1", Timestamp:time.Time{wall:0xbeed3ca55451a133, ext:24805708196, loc:(*time.Location)(0x55cad0c84140)}, ID:"", Extra:map[string][]interface {}(nil)}
  • The large negative number in behind Channel: is your channel number. Go configure the Matterbridge gateway section with it.

Note: for you to view messages from the channel in the matterbridge output, you need to adjust privacy settings for your bot or give your bot admin privilages in your channel.

Sequence within a BotFather chat:

You: /setprivacy

BotFather: Choose a bot to change group messages settings.

You: @your_name_bot

BotFather: Enable - your bot will only receive messages that either start with the / symbol or mention the bot by username.

  • Disable - your bot will receive all messages that people send to groups.
  • Current status is: ENABLED

You: Disable

BotFather: Success! The new status is: DISABLED. /help

(copied from this stack overflow answer)

Tutorial

This basic example will guide you through getting started on your first Telegram bridge.

  • Create your bot and retrieve your API token.
  • Make sure to disable privacy mode.
  • Add the bot to your Telegram group
  • Set up the Matterbridge configuration.

1. Speak to the BotFather.

Message the BotFather bot and run the /newbot command to get started. Once you pick a name it will provide you with a token used to access the HTTP API.

Disable bot privacy

You: /setprivacy

BotFather: Choose a bot to change group messages settings.

You: @your_name_bot

BotFather: Enable - your bot will only receive messages that either start with the / symbol or mention the bot by username.

  • Disable - your bot will receive all messages that people send to groups.
  • Current status is: ENABLED

You: Disable

BotFather: Success! The new status is: DISABLED. /help

Now add this newly created bot to the Telegram chat youre trying to bridge.

2. Add your config to Matterbridge.

Here is an example gateway bridging Discord<>Telegram which should be placed in your matterbridge.toml (or equivalent)

# / 
# SERVERS
# / 
[telegram]
    [telegram.mytelegram]
        Token="your_token_from_botfather" 
        RemoteNickFormat="<{NICK}> " # How your message will be formatted when bridged. 
        MessageFormat="HTMLNick :"
        QuoteFormat="{MESSAGE} (re @{QUOTENICK}: {QUOTEMESSAGE})"
        QuoteLengthLimit=46 # Truncuate long quotes to prevent spammy bridged messages
        IgnoreMessages="^/" # Don't bridge bot commands (as the responses will not be bridged)

# / 
# GATEWAYS
# / 
[[gateway]]
name="YourUniqueGateWayName"
enable=true

    [[gateway.inout]]
    account="telegram.mytelegram"
    channel="-100xxx"

    [[gateway.inout]]
    account="discord.mydiscord"
    channel="channel-name" 

See all possible settings here

The easiest way to retrieve your channel id is to navigate to https://web.telegram.org/ and simply copy the numbers at the end of the hyperlink into the xxx position in the example snippet above.

To add more nodes to this bridge, you simply need to add additional [[gateway.inout]] fields.

Make sure to test your config with the -debug flag after each change.

Limitations

  • The Telegram API does not report any changes when messages are deleted so Matterbridge is unable to remove any bridged messages after theyve been sent (This will render many common spam solutions useless). Use regexp with the IgnoreMessages= field to remove any common spam messages.