WordPress Telegram Bot - Use Case - How to Create a Bot on Telegram That Responds to Group Messages


Use Case – How to create a bot on Telegram that responds to group messages.

Back to User Guides

Note: This guide requires:


Video Use-Case

Introduction

WordPress Telegram Bot is a WordPress plugin that allows you to send automatic messages, emails and SMS based on Telegram conversations and much more. You can use the WordPress Telegram Bot plugin to automate business workflows involving the messenger app.

Main functionalities:

  • Email Repeater – Send messages sent on a Telegram group to one or many emails. Mark words as “stop words” to prevent them from triggering the bot.
  • Personal Messages – Mention a user after certain words or expressions are sent to the group together with a message to this user.
  • Group Messages – Emit message to all users based on certain conditions in a specific group.
  • SMS Repeater – Send a copy of Telegram group conversations to a mobile device.
  • SMS Alerts – Send notifications to multiple phone devices whenever certain keywords are used.
  • WordPress Repeater – Store all messages from a specific group or several groups in WordPress and output the content using a shortcode.

Use Case Front-End

Example: on the chosen Telegram group the bot must respond to group messages when someone types words "hi", "hey" or "hello". The message must include the words "bot" or "help", and must not include the word "robot".

Example of the rule - WordPress Telegram Plugin
Example of the rule

Result:

Example of the rule - WordPress Telegram Plugin
Example of the rule

Use Case Assumptions

In this example we will consider how to create a bot on Telegram and how to teach it to respond to specific terms or phrases to Group Messages.

Requirements

  • The WordPress Telegram Bot plugin will only work on sites with installed SLL certificates (HTTPS).
  • You cannot use the same access token (bot API) on different sites.
  • The bot may not perform properly with supergroups.

It follows:

Installing the Plugin

The process is the same for all CM plugins and add-ons.

CreativeMinds Customer Account Dashboard - Downloads tab
CreativeMinds Customer Account Dashboard
  • Download the plugin from your customer dashboard.
  • Log in to WordPress and navigate to the WordPress Admin → Plugins settings.
  • Click on Add New.
  • Activate it and add the license.

Learn more: Getting Started - Plugin Overview


Creating a Telegram Account

To start working with the plugin, first thing you need to do is to create a Telegram account. The phone number is required. To create an account you can use web browser or application that is supported for different types of devices. You can learn more about it in official documentation.

When the account is created, you need to create a bot. 

Creating a Bot and Connecting It to Plugin

Telegram Resources

Official Telegram documentation: How To Create a Bot | @BotFather Commands

This feature depends on Telegram, so steps and interface may change at any time.

If you feel this article is deprecated, please get in touch with us.

In order to create a Telegram Bot, follow these steps:

1) Contact the user @BotFather on Telegram and start a chat.

Either follow the link @BotFather or look for its username.

Using BotFather for creating a bot - Telegram Plugin for WordPress
Using BotFather for creating a bot

2) Write /newbot to @BotFather and choose a friendly bot name. Friendly names can contain spaces. Example: Creative Minds Bot.

Specifying a friendly bot name - Telegram Group Bot Manager
Specifying a friendly bot name

3) Specify the bot username. This name can't contain spaces and must end with "bot". Example: CmindsBot.

Specifying a bot username - Telegram Bot Plugin for WordPress
Specifying a bot username

Your bot has been created! You will now receive the access token.

You can find it on the @BotFather message logs. Alternatively, message /token @xxx to it, with xxx being the bot name. For example: /token @CmindsBot.

Copying the API key - WordPress Telegram Plugin
Copying the API key

4) Copy this token and navigate to the plugin: Admin Dashboard → CM Telegram Bot → Settings → API Settings tab.

Navigation to the plugin settings - Telegram WordPress Widget
Navigation to the plugin settings

There in the section Telegram API Settings you need to fill the following fields:

Connecting the created bot with the plugin - Telegram Plugin for WordPress
Connecting the created bot with the plugin
  1. Bot API Key - Paste here copied token.
  2. Bot Username - Here you need to write bot username without @. In our example it's CmindsBot.

    Remember: the username is the one without spaces and ends with bot:

    Bot username example - Telegram Group Bot Manager
    Bot username example
  3. Default sender name - If the bot can't detect the sender's name then he will use this one.

And then click the Save button.

Saving the changes - Telegram Bot Plugin for WordPress
Saving the changes

TIP: Edit the Bot

Using the @BotFather you can edit your bot: name, description, about info, profile photo and list of commands. Just follow the instructions by @BotFather.

BotFather settings - WordPress Telegram Plugin
BotFather settings

Creating a Group and Adding the Bot as Admin

Note: the following steps are shown in a desktop application, as there's no possibility to set a bot as admin on the web version of Telegram.

The WordPress Telegram Bot plugin requires the bot to be part of one or multiple groups to fetch messages and interact with users.

It can only perform actions if it has admin permissions. So, next step - you need to create a new group (if you haven't done it yet) and add your bot as administrator.

Open the Telegram's menu and click New group.

Creating new group - Telegram WordPress Widget
Creating new group

In the pop-up window you need to write a name for your group and click  Next.

Giving a name to the group - Telegram Plugin for WordPress
Giving a name to the group

On the next step invite new members to the group. Now you need to find your bot, choose it and click  Create.

Creating the group - Telegram Group Bot Manager
Creating the group

And the final step: setting the bot as administrator. Navigate to the group settings, click Manage Group → Administrators → Add Administrator. Then choose the bot and click Save and Close.

Setting up a bot as an admin - Telegram Bot Plugin for WordPress
Setting up a bot as an admin

Creating Rules - Group Messages

Now it's time to teach our bot to respond on some definite words or phrases. Rules are the main features of the WordPress Telegram Bot plugin and you can create multiple of them.

Examples:

  • Send all messages from a group to an email address of choice, except it they have the word "hey" or "hi"
  • If someone writes "help" in a group, send an SMS with contact information to a chosen number

In this use case we will consider responses by the bot on Telegram to group messages, when someone sent the message containing the words or phrases from the rule. So, navigate to Admin Dashboard → CM Telegram Bot → Settings  Group Messages tab.

Creating a Group Messages rule - Telegram Group Bot Manager
Creating a Group Messages rule

There you can find the following fields and options:

  • Restrict to group ID - Here you need to write ID of your Telegram group. This field can contain multiple IDs for different groups. Must follow the format "-xxxxxxxx" (the character "-" followed by nine numerals). Note: leaving this field empty will apply the rule to ALL groups, where the bot is set as administrator.

    To get ID navigate to Telegram and type /getGroupId in your group.

    Note: Telegram bot commands are case-sensitive! As such, /getGroupId will work and /getgroupid will not work.

    In respond you will get group ID:

    Getting a Group ID - Telegram Bot Plugin for WordPress
    Getting a Group ID
  • Telegram group message - The message to be sent to the group.
  • Detect phrase/s - The rule will only run if it DOES include AT LEAST ONE of these words or phrases.
  • Status - Set the rule as active or paused.
  • Must not include - The rule will only run if it DOES NOT include ANY of these words.
  • Must include - The rule will only run if it DOES include at least one of these words.
  • Snooze for - Set a number in hours in the field. After the rule is activated, it will "snooze" for X hours before being ready to activate again. Useful to avoid spamming.
  • Execute every - Execute the rule after every X times the trigger is activated. For example, if detection is set to 3 the rule will be set on the following 1,4,7. 
    • Reset count - Click the button to set the count of Execute every to 0. Example: the rule is executed every 10 messages and 9 have been sent, so it will be executed again in the next message. Click on Reset Count and the rule will start counting from start.
  • Fire Shortcodes - You can place here one or multiple shortcodes which should be executed on the site running the bot once the message has been fired. The output of this shortcode will be printed to the telegram group associated with this message. Have a note that not all shortcodes can be executed in order to print the output in Telegram group. Learn more about how it works in this guide. Note: this option was introduced in version 1.0.5.

Let's fill this form for our example in the following way: the rule must respond to the group when someone types words "hi", "hey" or "hello". The message must include the words "bot" or "help", and must not include the word "robot".

Example of the created rule - WordPress Telegram Plugin
Example of the created rule

And then click the  Save button:

Saving the changes - Telegram WordPress Widget
Saving the changes

Keyword Conditions Summary

Within this rule, you can set three conditions involving keywords. They all work in tandem.

For example, if you have these:

  • Detect phrase(s) - "Hi", "Hey", "Hello"
  • Must include - "bot", "help"
  • Must not include - "robot"

The following will happen with each message:

  • "hello, bot, help me" - Will trigger the rule
  • "hey, bot, can you answer me?" - Will trigger the rule
  • "hello, can anyone help me?" - Will trigger the rule
  • "hi, robot, I need your help" - Will not trigger the rule, because it has "robot"
  • "help me, bot" - Will not trigger the rule, because it doesn't have "Hi", "Hey" or "Hello"

Let's see the result on the front-end:

Front-end result - Telegram Plugin for WordPress
Front-end result

Creating, Duplicating and Deleting a Rule

Every tab comes with an empty rule. 

Creating, duplicating and deleting a rule - Telegram Bot Plugin for WordPress
Creating, duplicating and deleting a rule
  1. Add rule - Create more rules at any time by clicking this button.
  2. Duplicate rule - You can duplicate rules and edit the copies.
  3. Delete rule - Delete the rule. Note: be careful, as there is no confirmation for this action.

All changes (including deletion) are only performed after you click the Save button. 

Viewing the Log - Checking Performed Rules

You can check all performed actions in the log. It helps you monitor the bot responses and operation and, in case of errors, lets you understand what is the rule that did not work as expected.

Capturing Group ID

The log is also useful for detecting the group ID. Once adding the Bot to a group as an admin, it will start sending the content of that group to the plugin. In such case you can find out what is the group number without using the command line within the group stream.

To see the log navigate to Admin Dashboard → CM Telegram Bot → Log.

Navigation to the plugin log - WordPress Telegram Plugin
Navigation to the plugin log

The log shows the information about each action:

  • Group ID - This column can be useful to retrieve this number (you can also order this column by ID).
  • User Name - You can order this column by user names.
  • Message - All group messages are logged, even if they don't trigger any rule.
  • Actions - Identifies the rules and, and if it was processed successfully or failed by some reason.
  • Status - Status of the message.
  • Date - Date when the message was sent.
Example of the log - Telegram WordPress Widget
Example of the log

You can clear the log at any moment by clicking the button Clear log.

Clearing the log - Telegram Plugin for WordPress
Clearing the log

End Result

As you can see, using the WordPress Telegram Bot plugin you can create the rules, and the bot will respond reacting only on definite word or phrases, that optionally must include or not include some definite keywords. You can create any number of different rules that will respond to different words of phrases.

Use Case Front-End

End result - Telegram Group Bot Manager
End result

More information about the WordPress Telegram Bot plugin

Other WordPress products can be found at CreativeMinds WordPress Store

Let us know how we can Improve this Product Documentation Page

To open a Support Ticket visit our support center
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.