Using the Bot Framework from Python with the Direct Line API
Yes, it's possible. The Bot Framework supports the "Direct Line" channel which you can use from any client application to call your bot. If you want to learn more about this channel and how to call it, start here: /en-us/bot-framework/rest-api/bot-framework-rest-overview.
So assuming you've built a bot already using the Bot Builder SDK using Node.js or C#, let's take a quick look at what it's like to call your bot using Python. Here, I will use the Direct Line API v3 referenced here: /en-us/bot-framework/rest-api/bot-framework-rest-direct-line-3-0-concepts
First up, get your development environment Python ready:
- Install Python from here: https://www.python.org/downloads/windows/
- VS Code (obvs): https://code.visualstudio.com/download
- Python VS Code extension: https://marketplace.visualstudio.com/items?itemName=donjayamanne.python
Get the code:
- Grab the source code from my repo here: https://github.com/daltskin/python-botframework-directline
- Add your own DirectLine secret available from the https://dev.botframework.com portal.
Then hit F5, watch your bot framework endpoint get and return a response:
*Disclaimer - I'm new to Python - in fact, this is my first attempt at it, so I'm on pretty much Hello World territory in Python-land.
Update 7th August: After some VS Code updates, I was no longer able to debug the Python code as I was seeing this error: python.python-debug.startSession' not found:
The solution was to uninstall/reinstall the Python VS Code extension and restart VS Code.
Comments
- Anonymous
February 20, 2018
That's neat @Dalton!