2 minute read

This article describes how to build a first bot with the Bot Framework SDK for Python. Additionally, I will test the bot using the Bot Emulator. In this example, I will only use a local machine and no Azure resources will be required.

Prepare the environment

First we navigate to the folder where the bot will be installed. We create our environment

python3 -m venv venv
source venv/bin/activate

and install the necessary packages:

pip install botbuilder-core
pip install asyncio
pip install aiohttp
pip install cookiecutter==1.7.0

Create the Bot

From the working directory, run

cookiecutter https://github.com/microsoft/BotBuilder-Samples/releases/download/Templates/echo.zip

to install the echo bot template and its dependencies. You will be asked to give the bot’s name and a brief description.

(venv) (base) bartcus@mbp-de-bartcus-1 oc_10 % cookiecutter https: //github.com/microsoft/BotBuilder-Samples/releases/down load/Templates/echo.zip
You've downloaded /Users/bartcus/.cookiecutters/echo.zip before. Is it okay to delete and re-download it? [yes]: yes 
bot_name [my_chat_bot]: echo-bot
bot description [Demonstrate the core capabilities of the Microsoft Bot Framework]: This bot is created to test the Bot Framework SDK in python. In particular I am ma kina a echo bot template here.

Navigate to the folder you just created. That folder should have the same name as the echo bot. And install the requirements.

cd echo-bot
pip install -r requirements.txt

Finally run the python echo bot application.

python app.py

(venv) (base) bartcus@mbp-de-bartcus-1 echo-bot % python app.py
/Users/bartcus/Documents/GitHub/0C-projects/oc_10/venv/lib/python3.9/site-packages/botbuilder/schema/__init_py:80:Userwarning:TheBotFrameworkPythonSDKisbeingretiredwithfinallong-termsupportendi ng in November 2023, after which this repository will be archived. There will be no further feature development, with only critical security and bug fixes within this repository being undertaken. Existing bots built with this SDK Follow link (cmd + click) ion. For all new bot development we recommend that you adopt Power Virtual Agents.
essass== Running on http://localhost: 3978
(Press CTRL+C to quit)

To understand how the bot works, I invite you to refer to the source code of the bot that was downloaded. I recommend you take a look at the app.py file.

Testing the ChatBot with the BotEmulator

To run the Bot Framework Emulator, follow these steps:

1) Download and install the Bot Framework Emulator from the following link

2) Open the emulator on your computer.

3) In the emulator, click on the “File” menu and select “New Bot Configuration”.

4) Fill in the fields for the Bot URL and App ID (if you have one) and click on “Connect”. Observe that we used the link that was given when running the application http://localhost:3978 and we added the /api/messages/. Therefore we have the follwing link: http://localhost:3978/api/messages/.

Creating bot
Connection to the Echo Bot with Bot Emulator.

5) Your bot should now be running in the emulator and you can start testing your interactions with it. Let us test it.

Echo bot
Testing Echo Bot with Bot Emulator.