Create a bot with the Bot Framework SDK for Python

APPLIES TO: yesSDK v4 no SDK v3

This quickstart walks you through building a bot using the Python Echo Bot template, and then testing it with the Bot Framework Emulator.

Prerequisites

Create a bot

Note

Some developers may find it useful to create Python bots in a virtual envrionment. The steps below will work regardless if you're developing in a virtual environment or on your local machine.

  1. Open a terminal. Install the necessary packages by running the following commands:
  • pip install botbuilder-core
  • pip install asyncio
  • pip install aiohttp
  • pip install cookiecutter==1.7.0

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-python/releases/download/Templates/echo.zip

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

  1. 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:

set name and description

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 your bot.

Start you bot

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

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

bot running locally

Start the Emulator and connect your bot

  1. Start the Emulator and click the Open Bot button.

  2. After clicking the button a box window will open where you set the necessary values to run the bot. Use the number you saved earlier and set the Bot URL to http://localhost:<saved number>/api/messages as seen below:

open a bot screen

  1. Click the Connect button and your bot should start. Try testing the bot by typing anything and clicking Enter as seen below:

connect and test

Additional resources

See tunneling (ngrok) for how to connect to a bot hosted remotely.

Next steps