Skip to content

Notify_telegram

Chris Caron edited this page Feb 6, 2019 · 10 revisions

Telegram Notifications

  • Source: https://telegram.org/
  • Icon Support: Yes
  • Message Format: Text
  • Message Limit: 4096 Characters per message

Account Setup

Telegram is slightly more complicated then some of the other notification services, so here is quick breakdown of what you need to know and do in order to send Notifications through it using this tool

At the very start, you will need to connect with a phone. The site uses your phone number as it's credential to let you into your account. So download and install the phone app first via Android or Apple.

Once you're set up, it can be a bit easy to just use their web interface here with a PC (especially for development); but this part is up to you.

Telegram notifications require you need to first access https://api.telegram.org and create a bot. After creating the bot, you will need to acquire it's Token Identifier (bot_token).

To do this you will be required in a chat with the BotFather to type: /newbot. Answer the questions it asks after doing this (which get the name of it, etc). When you've completed this step, you will be provided an bot_token that looks something like this: 123456789:alphanumeric_characters.

You will need to /start the bot to get it going for good. To make your life easier, it would be a good idea to send a message to this new bot you created. The content of your message can be anything; but it will ease the use of this script for you.

Syntax

Valid are as follows:

  • tgram://{bot_token}/

    • Note: apprise is clever enough to determine the chat_id of the bot owner (you) only if you've sent it at least 1 private message first. It doesn't matter what you write to it; but just any message allows your chat_id to be detectable. If the chat_id can't be detected, then this URL will not work.
  • tgram://{bot_token}/{chat_id}/

  • tgram://{bot_token}/{chat_id1}/{chat_id2}/{chat_id3}/

This can also be written like so:

  • tgram://{chat_id}@{bot_token}/

If you don't know the chat_id, this script will attempt to detect the one belonging to the bot owner (which is usually you). So this is a valid URL as well:

  • tgram://{bot_token}/

Note: Please note that there is no guarantee that this script will always be able to determine who the bot owner is (in most cases it will though). When the bot owner is detected, it's {chat_id} is presented in the logs. Ideally you should ideally take this and update your URL to explicitly reference this in the future.

If you want to see the icon/image associated with the notification, you can have it come through by adding a ?image=yes to your URL string like so:

  • tgram://{bot_token}/?image=Yes
  • tgram://{bot_token}/{chat_id}/?image=Yes
  • tgram://{bot_token}/{chat_id1}/{chat_id2}/{chat_id3}/?image=Yes

Parameter Breakdown

Variable Required Description
bot_token Yes The token that identifies the bot you created through the BotFather
chat_id Yes Identify the users you want your bot to deliver your notifications to. You must specify at least 1 chat_id. If you do not specify a chat_id, the notification script will attempt to detect the bot owner's (you) chat_id and use that.
image No You can optionally append the argument of ?image=Yes to the end of your URL to have a Telegram message generated before the actual notice which uploads the image associated with it. Due to the services limitations, Telegram doesn't allow you to post an image inline with a text message. But you can send a message that just contains an image. If this flag is set to true, apprise will send an image notification followed by the notice itself. Since receiving 2 messages for every 1 notice could be annoying to some, this has been made an option that defaults to being disabled.
format No The default value of this is text. But if you plan on managing the format yourself, you can optionally set this to markdown or html as well.

Example

Send a telegram notification to lead2gold:

# Assuming our {bot_token} is 123456789:abcdefg_hijklmnop
# Assuming our {chat_id} is 12315544
apprise tgram:///123456789:abcdefg_hijklmnop/12315544/
You can’t perform that action at this time.