DEV Community

Cover image for Create a Azure bot in Python
Prabhu Manoharan
Prabhu Manoharan

Posted on

Create a Azure bot in Python

This article shows you how to build a bot by using the Python Echo Bot template, and then how to test it with the Bot Framework Emulator.

Creating a bot with Azure Bot Service and creating a bot locally are independent, parallel ways to create a bot.

Prerequisites

  • Python 3
  • Bot Framework Emulator
  • Knowledge of asynchronous programming in Python

Templates

  1. Install the necessary packages by running the following commands:
pip install botbuilder-core
pip install asyncio
pip install aiohttp
pip install cookiecutter
Enter fullscreen mode Exit fullscreen mode

The last package, cookiecutter, will be used to generate your bot. Verify that cookiecutter was installed correctly by running cookiecutter --help.

  1. To create your bot run:
cookiecutter https://github.com/microsoft/BotBuilder-Samples/releases/download/Templates/echo.zip
Enter fullscreen mode Exit fullscreen mode

This command creates an Echo Bot based on the Python echo template

Create a bot
You will be prompted for the name of the bot and a description. Name your bot echo-bot and set the description to A bot that echoes back user response. as shown below:
image

Start your bot

  1. From a terminal navigate to the echo-bot folder where you saved your bot. Run pip3 install -r requirements.txt to install any required packages to run your bot.

  2. Once the packages are installed run python3 app to start your bot. You will know your bot is ready to test when you see the last line shown in the screenshot below:
    image

Copy the last for digits in the address on the last line (usually 3978) since you will be using them in the next step. You are now ready to start the Emulator.

Start the Emulator and connect your bot

  1. Start the Bot Framework Emulator.

  2. Select Open Bot on the Emulator's Welcome tab.

  3. Enter your bot's URL, which is the URL of the local port, with /api/messages added to the path, typically http://localhost:3978/api/messages.
    image

  4. Then select Connect.
    image

Send a message to your bot, and the bot will respond back.

Discussion (0)