Bot Framework v4 Skills with Dialogs sample.
This bot has been created using the Bot Framework; it shows how to use a skill dialog from a root bot.
- Python SDK min version 3.6
- Bot Framework Emulator
The solution uses dialogs, within both a parent bot (dialog-root-bot) and a skill bot (dialog-skill-bot).
It demonstrates how to post activities from the parent bot to the skill bot and return the skill responses to the user.
dialog-root-bot: this project shows how to consume a skill bot using aSkillDialog. It includes:- A Main Dialog that can call different actions on a skill using a
SkillDialog:- To send events activities.
- To send message activities.
- To cancel a
SkillDialogusingCancelAllDialogsAsyncthat automatically sends anEndOfConversationactivity to remotely let a skill know that it needs to end a conversation.
- A sample AdapterWithErrorHandler adapter that shows how to handle errors, terminate skills and send traces back to the emulator to help debugging the bot.
- A sample AllowedSkillsClaimsValidator class that shows how to validate that responses sent to the bot are coming from the configured skills.
- A Logger Middleware that shows how to handle and log activities coming from a skill.
- A SkillConversationIdFactory based on
Storageused to create and maintain conversation IDs to interact with a skill. - A SkillConfiguration class that can load skill definitions from the
DefaultConfigclass. - An app.py class that shows how to register the different root bot components. This file also creates a
SkillHandlerandaiohttp_channel_service_routeswhich are used to handle responses sent from the skills.
- A Main Dialog that can call different actions on a skill using a
dialog_skill_bot: this project shows a modified CoreBot that acts as a skill. It receives event and message activities from the parent bot and executes the requested tasks. This project includes:-
An ActivityRouterDialog that handles Event and Message activities coming from a parent and performs different tasks.
- Event activities are routed to specific dialogs using the parameters provided in the
Valuesproperty of the activity. - Message activities are sent to LUIS if configured and trigger the desired tasks if the intent is recognized.
- Event activities are routed to specific dialogs using the parameters provided in the
-
A sample ActivityHandler that uses the
run_dialogmethod onDialogExtensions.Note: Starting in Bot Framework 4.8, the
DialogExtensionsclass was introduced to provide arun_dialogmethod wich adds support to automatically sendEndOfConversationwith return values when the bot is running as a skill and the current dialog ends. It also handles reprompt messages to resume a skill where it left of. -
A sample SkillAdapterWithErrorHandler adapter that shows how to handle errors, terminate the skills, send traces back to the emulator to help debugging the bot and send
EndOfConversationmessages to the parent bot with details of the error. -
A sample AllowedCallersClaimsValidator that shows how to validate that the skill is only invoked from a list of allowed callers
-
An app.py class that shows how to register the different skill components.
-
A sample skill manifest that describes what the skill can do.
-
-
Clone the repository
git clone https://github.com/microsoft/botbuilder-samples.git
-
(Optionally) Create a bot registration in the azure portal for the
dialog-skill-botand update dialog-skill-bot/config.py with theMicrosoftAppIdandMicrosoftAppPasswordof the new bot registration -
(Optionally) Create a bot registration in the azure portal for the
dialog-root-botand update dialog-root-bot/config.py with theMicrosoftAppIdandMicrosoftAppPasswordof the new bot registration -
(Optionally) Update the
SKILLS.app_idin dialog-root-bot/config.py with theMicrosoftAppIdfor the skill you created in the previous step -
(Optionally) Add the
dialog-root-botMicrosoftAppIdto theAllowedCallerscomma separated list in dialog-skill-bot/config.py
-
In a terminal, navigate to
samples\python\81.skills-skilldialog\dialog-skill-botcd samples\python\81.skills-skilldialog\dialog-skill-bot
-
Activate your desired virtual environment
-
Run
pip install -r requirements.txtto install all dependencies -
Run your bot with
python app.py -
Open a second terminal window and navigate to
samples\python\81.skills-skilldialog\dialog-root-botcd samples\python\81.skills-skilldialog\dialog-root-bot
-
Activate your desired virtual environment
-
Run
pip install -r requirements.txtto install all dependencies -
Run your bot with
python app.py
Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
- Install the Bot Framework Emulator version 4.7.0 or greater from here
- Launch Bot Framework Emulator
- File -> Open Bot
- Enter a Bot URL of
http://localhost:3978/api/messages, theMicrosoftAppIdandMicrosoftAppPasswordfor thedialog-root-bot
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.