Skip to content

[Daemon] telegram chat bot

Houzuo Guo edited this page Oct 14, 2020 · 4 revisions

Introduction

Telegram Messenger is a popular mobile messaging app that excels in communication security.

The chat bot enables you to invoke app commands via chat messages.

Preparation

Acquire an AuthorizationToken from Telegram Messenger by creating your own chat bot. Download and install Telegram Messenger, then follow the guide How do I create a bot? to talk to "BotFather" and register your chat bot.

After chat bot is successfully created, Telegram Messenger will tell you the AuthorizationToken, which you have to place into the configuration.

Configuration

  1. Construct the following JSON object and place it under JSON key TelegramBot in configuration file:
Property Type Meaning Default value
AuthorizationToken string Registered bot authorisation token. (This is a mandatory property without a default value)
PerUserLimit integer Maximum number of app commands a chat may send in a second. 2 - good enough for personal use
  1. Follow command processor to construct configuration for JSON key TelegramFilters.

Here is an example setup:

{
    ...

    "TelegramBot": {
        "AuthorizationToken": "425712345:ABCDEFGHIJKLMNOPERSTUVWXYZ"
    },
    "TelegramFilters": {
        "PINAndShortcuts": {
            "Passwords": ["VerySecretPassword"],
            "Shortcuts": {
                "watsup": ".eruntime",
                "EmergencyStop": ".estop",
                "EmergencyLock": ".elock"
            }
        },
        "TranslateSequences": {
            "Sequences": [
                ["#/", "|"]
            ]
        },
        "LintText": {
            "CompressSpaces": false,
            "CompressToSingleLine": false,
            "KeepVisible7BitCharOnly": false,
            "MaxLength": 4096,
            "TrimSpaces": false
        },
        "NotifyViaEmail": {
            "Recipients": ["me@example.com"]
        }
    },

    ...
}

Run

Tell laitos to run chat bot daemon in the command line:

sudo ./laitos -config <CONFIG FILE> -daemons ...,telegram,...

Usage

On Telegram Messenger application, find your newly created chat bot via the in-app Search function, then send app command in a chat message. Wait a short moment, and the command response will be sent back to you via the same chat.

Remember to put password in front of the app command.

Tips

  • The chat bot server will not process messages that arrived before the server started, which means, you cannot leave a message to the chat bot while server is offline.
  • If you run multiple instances of laitos, feel free to use identical AuthorizationToken in all of their configuration. Your app command will be processed by all laitos instances simultaneously, and each instance will reply with their own command response.
Clone this wiki locally