Build a telegram robot with Voiceflow

Telegram has become one of the most important messaging programs in the world today. Free and open-source instant messaging software offers many useful features that make it suitable for implementing complex robots. Since its inception, there have been several ways to develop robots for Telegram. With the new Voiceflow Dialog Manager API, the call design platform is the best choice for designing, developing, and integrating a Telegram chatbot.

prerequisites

Here are the things you need to do to create a Telegram robot using Voiceflow:

1. Telegram account

2. Voiceflow account

3. Visual Studio code

 

Architecture

In this example, we are going to use the Telegraf library for NodeJS projects to interact with our Telegram robot. As mentioned above, any user interaction in the Telegram robot will be sent to Voiceflow using the Dialog Manager API.

telegram bot

Create your robot with BotFather

First, we have to use Botfather to create our own robot inside Telegram. BotFather lets you create new robot accounts and manage existing accounts with a few simple clicks. To start the process of creating a robot, you just need to talk to BotFather and follow the steps below.

Click the “start” button to open a chat with BotFather.

Click on the new bot command to create a new robot. In the next step, you can name your robot. In this example, I named it “bot Voiceflow”.

The launch of Telegram was completed easily! Remember to add your Telegram token to your .env file in the TELEGRAM_TOKEN.‍ attribute.

launch Project

Install and run the project:

1. Copy the repository:

git clone

2. Install the accessories:

yarn install

3. Launch the project:

yarn start

 

Write robot code

Launching Telegraf

We can create a robot with the following code:

botcode

Launching Voiceflow

Note: It is important to note that you must create a General Project in Voiceflow to implement the robot.

Now let’s implement the Voiceflow client to work with the Voiceflow cloud using the Dialog Manager API.

bot

The getclient () function calls DialogManagerApi.getInstance as the REST API client to interact directly with the Dialog Manager API.

As you can see, there are values that are added to the .env file. Let’s explain how to get those variables.

 

1. VersionID

To get your VersionID you need to go to the Voiceflow Project:

tbot

Then copy VOICEFLOW_VERSION_ID from the URL in your address bar. When you are in the Voiceflow project, your address bar should have the form URL:

https://creator.voiceflow.com/project/ {VOICEFLOW_VERSION_ID}/…

2. APIKEY

To get the Key API you have to go to the workspace where you created your General Project. After that, go to the workspace settings and click on the developer tab.

telegram

Then you have to click the Create New API Key button to create a new key:

tlgram

There you have to choose a name for the new Key API, for example, telegram-bot. After selecting the name, click the Confirm button:

bot

Finally, we need to add these variables to our final .env file. As shown below:

telegram

everything is ready. Let’s continue with the Telegram robot code. Replace start with the following code and get the answer from Voiceflow:

bot

Then replace hi for regex with (+.). This means that the robot hears everything. All incoming text is transmitted directly to Voiceflow and we manage the status of the conversation: If it’s finished or not finished yet:

bot

The response method is responsible for sending the user input in Telegram to Voiceflow using the runtime SDK client. This method allows you to process the answer:

bottlgram

In the example above you will see different types of answers including SPEAK, VISUAL and AUDIO.

 

Run Telegram Robot

bot

Conclusion

As you can see, with just 60 lines of code, you can quickly bring your chat experiences to life. We hope this gives you a better understanding of how to use Voiceflow to bring conversational experiences to your interfaces and products.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *