Telegram Notifications

Telegram is a free & open-source messenger.

This article describes Telegram configuration for CAS when operating your own CAS server to receive notifications from CAS regarding transactions and other events relevant to your BATM operation.

  • Server: Notifications can be delivered via Telegram.

  • Extensions: You can talk to extensions via Telegram.

  • See ChatBotExtensionExample

To use Telegram as a notification method, you must build the extension and load it in CAS.

Extensions are only supported by the GB official Github channels.

Example compilation instructions (below): Compiling from Source

  • Once the extension is loaded, you can proceed to use the instructions that follow.


1. Create a new bot in Telegram:

Search for the "BotFather" in the Telegram GUI:

Create a name for your new bot.

  • In this example, we'll use "gb_kb_example_bot".

NOTE: the bot name MUST end with the word "bot"!

In a message to BotFather, type:

/start /newbot [name of your bot]

Example:

/start
/newbot gb_kb_example_bot

  • The BotFather will now ask you to invent a "username". 

Create a descriptive name for your bot ("ExampleBot").

Save the received HTTP API token.

Example conversation:


Configure CAS from the CLI to use the new bot you created:

Create a Telegram configuration file for CAS:

sudo touch /batm/config/telegram sudo nano /batm/config/telegram

Enter the following data:

telegram_bot_username=your_unique_bot_name telegram_bot_token=APIKey:APIToken
  • The resulting file will look like this (using our example):

    • Save the file (type Ctrl+x and save when asked).

Restart CAS:

  • The bot won't work until the CAS Admin service is running!


Setup CAS to use your new Bot:

Identify your Telegram User ID for CAS:

  1. Open Telegram and locate your new bot:

  2. Click on the start button:

  3. Receive your Telegram User ID in a reply:

Add your Telegram User ID to the appropriate CAS Person:

  • Be sure to SAVE the setting (SUBMIT).

Configure your Notification Policy:

  1. Create a Notification Rule:

  • Set the Action Parameter to the same Telegram User ID previously identified.


Troubleshooting:

You can search the master log for the TelegramBot string.  You should see the TelegramBot registering command.


Compiling from source:

Test to see if the extension already exists:

  • If the extension already exists, building it from source is optional.

Overview:

  1. Clone the GB repository.

  2. Compile the CAS extension (JAR).

  3. Copy that JAR to the correct destination in your CAS host.

  4. Test it.

1. Clone the GB repository:

Install Git:

Clone the GB repository.

These instructions assume you’ll use your home directory. If you choose to clone into another, different directory, then adjust this next command to change to it instead:

Now clone the batm_public repository:


2. Compile the CAS extension (JAR).

Compilation currently requires OpenJDK version 8.

Build the batm_server_extensions_examples.jar extension with:

After each build (above), you should see “BUILD SUCCESSFUL”:


3. Copy that JAR to the correct folder in your CAS host.

You’ve prepared CAS (in step 1) to look for an extension in a specific place. Put it in it’s place.

The default compiled location of the JAR (using above instructions) is:

$HOME/batm_public/server_extensions_examples/build/libs/batm_server_extensions_examples.jar

We want to copy it to this folder:

/batm/app/master/extensions/

Use this command to copy it:

Modify file ownership:

Restart CAS to implement the new extension.

Copyright © 2020-2024 General Bytes USA LLC