How to create a Telegram Bot using Microsoft Bot Framework and Node.JS


azure bot framework microsoft telegram Tutorials

In this post, we will create the simplest Node.js bot using Microsoft Bot Framework and connect it to Telegram. All actions we will do on the Azure platform without any code and installations. This tutorial will be easy to follow.

Prerequisites

  • active Azure subscribtion
  • token for Telegram Bot

Creating Bot Service

  1. Go to Azure Portal under your subscription. Press “All Services” and search by “bot” keyword:

    Bot Service

  2. Select “Web App Bot”:

    Select Web App Bot

  3. In default Bot Services directory press on “Create bot service” button:

    Create Bot Service

We created a bot service and then we need to create web app bot.

Create Web App Bot

  1. Press “Create”:

    Create Web App Bot

  2. Fill in the appropriate fields and choose “Bot template”:

    Choose Node.Js Template

  3. Choose “Node.Js” and “Echo Bot” template. Then press “OK”. It will be a good start point:

  4. You will be returned to the previous form. The last step will be choosing a service plan. Select the closest location to you and press “OK”:

  5. Check all fields again and if you like it press “Create”:

    Final Step of Bot Creation

  6. The deployment process starts:

    Deployment in progress

  7. When the deployment process is over you will see a notification:

    Deployment succeeded

    Sometimes you can don’t see this notification. In this case, just go to resource and periodically refresh the page.

Testing bot in the web chat

  1. Congratulations! You created your first bot. You can open it in your resource folder:

    Web App Bot Dashboard

  2. To test our bot we need to press “Test in Web Chat” under “Bot management” section:

    Testing bot in Web Chat

    Send any text message and the bot will send you a copy. To restart bot just press “Start over”.

Connect to Telegram Channel

  1. The process of connection is very primitive. Open “Channels” under “Bot management” section and click on Telegram icon:

    Connect Telegram Channel

  2. You will be redirected to the page where you need to enter Telegram Bot Token:

    Telegram Bot Token Page

    You can find this token BotFather Bot.

  3. Enter token and press “Save”:

    Telegram Bot Token Page (Saving)

  4. After successful saving you can see the newly created channel in the list:

    Telegram channel added successfully

  5. Now you can open your Telegram Bot and send any text message:

    Telegram Echo Bot

    Why I’m saying “text message”? Because the default Echo Bot supports only text messages from the box.

  6. You can make sure that our bot handles all message and open an Analytics:

    Bot Analytics

    Editing code online

    If you want to make quick changes in the bot you can use “App Service” Editor”.

  7. You will be redirected to the Online Editor where you can change the logic in bot.js file:

    Edit your bot online!

  8. Open “Build” under “Bot management” and press “Open online code editor”:

    Open online editor

    Conclusion

    In this tutorial, we’ve created a chatbot using the default Microsoft’s Bot Framework template; we connected it to Telegram and learned how to edit code online.

    P.s. Don’t forget to delete all resources, if don’t need them.

comments powered by Disqus