Get your 1,000free online users

More results

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Events
Knowledge Base
News
Press Releases
Reviews
Success Stories
Update
Webinars
Back

How to Control TrueConf Server Using Its API and Telegram Bot

5 min.
How to Control TrueConf Server Using Its API and Telegram Bot 1

The administrator of TrueConf Server can quickly access important server information using popular messengers, such as Telegram. This can be done by creating a bot that will retrieve the necessary data via the TrueConf Server API. The bot can be hosted locally on your own server or on any dedicated machine.

In this example, we will demonstrate how to create a Telegram bot and deploy it on your local machine. We provide a ready-made example of task implementation using Python:

How to Control TrueConf Server Using Its API and Telegram Bot 2

The proposed bot has the following capabilities:

  • Checking server status (running/stopped).
  • Retrieving the list of active conferences.
  • Checking the number of online users.
  • Finding and stopping long-running conferences that were left active by mistake.

In the following text, such mistakenly started conferences are referred to as “forgotten” for brevity, meaning they were not ended by the owner and moderators. For example, during a webinar, the guests left, but the moderator minimized the client application without stopping the event. It continues to run, and if recording was enabled, it unnecessarily occupies space on the SSD or HDD with a growing recording file.

For example, we consider the following conference as “forgotten”:

  • it lasts longer than one hour;
  • only the owner or moderator remains in it;
  • it has participants, but none of them are moderators.
How to Control TrueConf Server Using Its API and Telegram Bot 3

Prerequisites for Launch

For the successful launch of the bot, two conditions must be met:

  • Each monitored server must be accessible by its IP address or DNS name from the PC running the bot.
  • The PC with the bot must have internet access.

The provided code is an example on which you can base your own bot implementation. Note that the bot’s security is ensured at the OAuth 2.0 protocol and HTTPS level, as well as on the network settings side (access rules, firewall, etc.). The bot operates in long_polling mode, independently polling the Telegram server for new updates. Unlike webhook, this connection scheme is completely secure in a corporate environment.

Registering and configuring your bot

To use the Telegram bot, you will need the official BotFather bot.

BotFather is the only bot that manages bots on Telegram. Read more in the official documentation.

To create a bot:

  • Open BotFather and click Run or Start.
  • A list of the bot’s commands will appear. You will need the /newbot command. Click on it in the list or send a new message with /newbot to the bot.

    You can later access the list of available commands by clicking the Menu button or simply by typing / in the message input field in the chat with BotFather.

  • BotFather will then ask you to choose a name for your new bot. Come up with a name, for example, TCS [name_org], where [name_org] is the name of your organization.
  • Now, choose a username for your bot. The name must include the word bot, as it is a requirement from Telegram, for example, server_[name_org]_bot.

    Please note that the bot’s name and its username are public identifiers that can be used to find it via global search.

  • In response, you will receive a message containing information about the created bot and an access token for it via HTTP API in the following format: Click on the token in the message text to copy it to the clipboard. Then save it in a secure location, as you will need it later to use the bot.

To access your bot settings, use the /mybots command and select the appropriate username. A menu will open where you can:

  • revoke the current token, and a new token is automatically generated;
  • edit name, welcome message, description, image;
  • add commands.

Now that the bot is configured, you can proceed to launch it.

Preparing the configuration file

First, you need to prepare a configuration file with the access data for your bot and server parameters.

Copy the settings.example.toml file to a new file named settings.toml:

Now you need to correctly fill in this data structure.

tg-api-token — Telegram HTTP API access token.

tg-users-id — Your numeric Telegram ID. Telegram ensures secure access to the bot using unique user IDs. Therefore, you will need to know your Telegram ID to receive a response from the bot. To obtain it, send any message to the bot @userinfobot.

If you want multiple people to have access to the bot, you can enter their IDs separated by commas.

locale — The language code in which the bot will respond. You can edit phrases or add your translation in the app/locales folder.

In [servers.<server_name>], replace <server_name> with the preferred server name. It will be displayed in the button names:

How to Control TrueConf Server Using Its API and Telegram Bot 4

ip — The FQDN or IP address of the server.

client_id and client_secret will be available to you after creating an OAuth2 application. For instructions on how to create one, refer to our documentation.

For our example, you will need to select the following permissions in the OAuth application:

  • conferences;
  • users:read;
  • logs.calls:read;
  • logs.calls.participants:read.

server_status.state — enables or disables the automatic server availability check. Values: true or false.

server_status.timeout — the time in seconds after which the bot will check the server’s availability (Running, Disconnected). The default is set to 15 seconds, but you can enter your own value.

ssl_certificate — TLS certificate verification setting. If true, each server request will undergo verification. If your server uses a self-signed certificate, specify the path to it in this parameter (use a forward slash /). If the bot is used in a trusted zone (for example, a server located in your corporate network and accessible only by you), specify false to disable certificate verification. If nothing is specified "", it is equivalent to false.

After completing the file, you should have a structure similar to the example below:

Launching the bot

  • Install Python.
  • Download the project. On the main page of the repository, click the Code → Download ZIP button and extract the downloaded archive.
  • Install pipenv:
  • Install the dependencies. To do this, run the following command in the terminal in the project folder: where --python 3.x is your Python version. We recommend using 3.7 and above.
  • Start the bot:

When the bot is successfully launched, the terminal will display the message Bot is running…

Deploying the Bot on Cloud Services

You can run your bot not only on a local machine but also in the cloud, which is convenient for continuous operation and accessibility from anywhere. For this purpose, you can use various cloud platforms that offer convenient tools for developing, testing, and deploying applications. Below, we list a few popular services where you can host your bot:

  • Replit is a service for running and developing applications directly in the browser.
  • Heroku is a platform for deploying and hosting applications with seamless integration with GitHub.
  • Google Cloud Platform (GCP) is a powerful platform with extensive capabilities for hosting and managing applications.
  • AWS (Amazon Web Services) is a cloud platform from Amazon for scalable applications with a multitude of tools and services.
  • Microsoft Azure is a platform for developing and managing applications in the cloud with integration into the Microsoft ecosystem.
  • Glitch is a service for quick hosting and app development with a simple interface and GitHub integration.

These services allow you not only to deploy a bot but also to scale it easily and ensure its availability to users anywhere in the world.

Previous article Next article

Try out the secure video conferencing platform TrueConf!

Video conferencing solution TrueConf Server works inside of your closed network without an internet connection
and allows you to gather up to 1,500 people in one conference!

Content