Create a chatbot using Bot Framework SDK in Python. Creating your bot locally does not require an Azure subscription. We will work with Windows OS. For C# bots, check out the tutorials here.
The download link for 2nd requirement is available on the Downloads page.
Create and Enable a Virtual Environment
The virtual environment is specific to a project and is maintained in the project folder. Go to the project directory where you want to create your bot.
Run the following commands to activate the virtual environment using any command-line tool.
python -m venv venv venv\Scripts\activate.bat
Install the Templates
Install the packages using the
pip install command.
pip install botbuilder-core pip install asyncio pip install aiohttp pip install cookiecutter==1.7.0
You might get an error for
Building wheel for cryptography (PEP 517) … error while running the first command. Try upgrading the
pip to latest version and rerun the first command.
python -m pip install --upgrade pip
Create the Bot
We will create an Echo bot for this demo. From your project directory, run the below command to download the echo bot template and its dependencies.
When asked about the bot name and the description, give suitable values.
If you see your project directory, a new folder is created with the name of the bot you provided.
Run your Bot
Go to the bot folder that was created in the last step by running the below command in the command line/command prompt.
Install all the dependencies for the echo bot template by running the below command.
pip install -r requirements.txt
To start the bot, run the below command.
If you see the
Running on http://localhost:3978, that means your bot is running. We will use Bot Framework Emulator to test the bot.
Test the Bot in Bot Framework Emulator
Open Bot when the emulator starts.
Enter the Bot URL that was shown in the command line appended with “
http://localhost:3978/api/messages. Click on Connect.
Initially, you will see a welcome message when you join the conversation.
Start typing your messages and see the bot replies to you with the same message or in other words echo it back.