Creating Group Bot

To create a BOT that will be assigned to group for active monitoring, use Telegram’s BotFather as described below:

  • Login to your Telegram account, if you do not have one you can
  • Click the button „Open in Web“
  • To get a list of available commands available type command /start in the chat window.
  • To create a new bot type the command /newbot in the chat to create new BOT
  • Once BotFather asks for the bot name, enter the prefered name of your new BOT, e.g. MyGroupBOT. Each bot name must be unique, if you type in a invalid name for your bot you will recieve a warning to change it to a new one.
  • Enter the username for your new BOT (it must end with the word bot), e.g. MyGroupBOTTestbot. The username must be unique for each bot. If the username you enter is invalid you will receive a warning and you can pick a different username
  • Once the bot creation is finished sucessfully you will receive a BOT token used to access the Telegarm HTTP BOT API (Marked in red text in the image). If you misplace this token you can always return to the chat window for BotFather to view it.Once you noted down your token key please click on the link provided by BotFather to continue.
  • Once you click on the provided link you will be taken to a new chat window. To continue the setup click the ”Start” button located at the bottom of the chat window.
  • Once the button is clicked the bot will be initialized.
  • To allow the BOT to receive messages from your group, Privacy mode of the BOT needs to be disabled. To disable it, return to the BotFather chat window and execute the following commands / actions:

a. type /mybots

b. click on the BOT you want to configure

c. click on BOT Settings

d. click on Group Privacy

e. click Turn off

Note: Privacy mode needs to be disabled before adding BOT the the group.

  • Click on the link of your BOT displayed in the message from the BotFather above (t.me/MyGroupBOTTestbot) and click the button Start

Assign the BOT to Telegram Group

To allow the BOT to monitor group memebers BOT needs to be assigned to your group as administrator. To assign BOT to your group, please follow the instructions below:

  • While in the group, click on the group name in the header
  • Click the button Add member and enter name of your BOT. Select the BOT from the list and click Next.
  • After the BOT is added as group member, click of group name in header to display group details and double check that BOT has access to messages as on the screen below:

If that is not the case, remove the BOT, disable privacy mode as described in step #10 of Creating Group BOT.

Download and install service

To run the service, you first need to download the source code, install dependencies and configure the service. You need to have node.js, npm and mysql database installed on your computer or server.

  • Run npm install in root folder (or from the download location for windows)
  • Create database and import database schema from file bot_db.sql located in folder db.
  • Open configuration file ts located in src/environments folder and set following parameters:

a. Update database connection details by entering database host, port, name, username and password

b. Enter BOT token obtained in step #8 or Creating Group BOT

c. Enter Chat Id of the group you ant to monitor. To retrieve Chat Id, do the following:

I. send one message to your group as owner of the group

II. call the url below in the browser:

https://api.telegram.org/bot<botToken>/getUpdates

Note: Replace <botToken> with your BOT token obtained in step #7 or Creating Group BOT

III. You will find Chat Id within parameter chat.id as shown on image below:

IV. Set your Admin’s details. You can defined multiple admin entries

  • Start the service by running command in the root folder

node node_modules\ts-node\dist\bin.js src/bot.ts

  • Now proceed to Telegram and configure as you wish. Type /start to get a list of available commands.

Congratulations! Your bot is now ready to be used live in your group!