Rate this page:

Function for adding buttons to a Telegram chat

In this article, you will create functions for adding buttons to a Telegram chat and route customer messages to these functions.

Telegram supports two types of buttons: Inline-buttons and Reply-buttons. In the below examples, you will create functions for adding various button types.

Adding Inline-buttons

Copy URL

In the first example, create a function for adding Inline-buttons.

Each Inline-button should contain a required text field and one of the optional fields: url or callback_data. If a button contains only callback_data, when a customer presses it, the function is called and the callback_data text displays. If a button has a url and callback_data, or only a url, the button works as a link.

Let us assume that a customer writes to a chat room of a communication services and apps developer in search of a solution for their contact center. According to the function conditions, if the customer writes Hello, the bot displays a keyboard with the following buttons:

  • Button that goes to the voximplant.com website, where the customer can see the entire product line of the company

  • Button that goes to the voximplant.com/kit website, where the customer can navigate to the smart contact center section

  • Button that transfers the customer to an agent

If the customer writes Hello. No keyboard, no keybord displays.

  1. Create a Telegram channel as shown here.
  2. Go to Administration > Functions > Management.
  3. Click New function.
New function
  1. Copy the following code and paste it into the function.
Function for adding Inline-buttons

Function for adding Inline-buttons

  1. Click Create.
Add function
  1. Go to Setup > Conversations > Channels and select the Telegram channel you created earlier.
  2. Select Functions in the Redirect channel messages field.
  3. From the drop-down list, select the function you added.
Redirect chat messages to the function
  1. Click Save changes.

After a welcome message, the buttons will now display in response to a customer.

Buttons

Adding Reply-buttons

Copy URL

Now, create a function for adding Reply-buttons. These can be regular buttons or buttons that contain a location or contact.

Let us assume that a customer writes to the Find a friend nearby service. According to the function conditions, if the customer writes Hello, the bot displays a keyboard with the following buttons:

  • Button that will share the location to find people nearby

  • Button that will share a contact to find a specific person

  • Hide keyboard button (if the customer wants to stay in the chat)

If the customer writes Remove keyboard or presses the respective button, the keyboard is removed.

According to the function conditions, if the customer message contains No keyboard, the bot does not display the keyboard.

For more information on the optional keyboard settings, go here.

  1. Go to Administration > Functions > Management.
  2. Click New function.
New function
  1. Copy the following code and paste it into the function.
Function for adding Reply-buttons

Function for adding Reply-buttons

  1. Click Create.
Add function
  1. In the Redirect channel messages field in the channel settings, select Function.
  2. Select the function you added earlier from the drop-down list.
Route channel messages
  1. Click Save changes.

After a welcome message, the buttons will now display in response to a customer.

Buttons

The button options offered to the customer or the selected option then display in the History > Messaging history and Reporting > Live monitoring > Conversations sections.