Manage routing incoming activities, including handling interruptions.
The Virtual Assistant provides foundational logic for handling incoming user activities. It uses a combination of concepts from the Bot Builder SDK v4 and base classes that enable additional scenarios.
Adapters and Middleware
Incoming activities are initially received through the BotAdapter implementation, processed through the configured Middleware pipeline, then routed onto the Assistant’s dialog stack. The DefaultAdapter in the Virtual Assistant template provides a set of Middleware out of the box including the following:
- Telemetry Middleware - Configures Application Insights telemetry logging.
- Transcript Logger Middleware - Configures conversation transcript logging.
- Show Typing Middleware - Sends typing indicators from the bot.
- Feedback Middleware - Configures the Feedback feature.
- Set Locale Middleware - Configures the CurrentUICulture to enable localization scenarios.
- Event Debugger Middleware - Enables debugging for event activities.
After the activity is processed by the Adapter and Middleware pipeline, it is received by the ActivityHandler implementation. The DefaultActivityHandler in the template implements the TeamsActivityHandler which enables Teams scenarios out of the box. By default, the DefaultActivityHandler passes the incoming message into the MainDialog. However, this logic can be customized as needed.
The DefaultActivityHandler passes incoming activities into the MainDialog. MainDialog implements the ActivityHandlerDialog, which provides its own routing logic for handling activities of different types, as well as enables interruptions. The following diagram shows how the activities flow through the different methods in MainDialog:
Once an activity flows into MainDialog, one of the first methods that will be called is OnInterruptDialogAsync(). The following interruptions are configured out of the box:
- Switching between Skills - Switches between connected skills based on intent.
- Cancellation - Cancels the current dialog.
- Help - Sends a help message, then resumes the waiting dialog.
- Escalation - Shows an escalation message.
- Log out - Logs the user out.
- Repeat - Repeats the last set of activities from the bot. Useful for speech scenarios.
- Start over - Starts the current dialog over.
- Stop - Can be implemented to stop readout in speech scenarios.
Once interruptions are evaluated, the activity is processed according to its activity type:
- OnMessageActivityAsync() - Any incoming message activities that were not handled by a waiting dialog.
- OnMembersAddedAsync() - Any incoming conversation update activity. Used for introduction logic.
- OnEventActivityAsync() - Any incoming event activity
- OnUnhandledActivityTypeAsync() - Any other incoming activity.