Enable bot context NuGet package
Omnichannel for Customer Service offers a suite of capabilities that extend the power of Dynamics 365 Customer Service Enterprise to enable organizations to instantly connect and engage with their customers across digital messaging channels. An additional license is required to access Omnichannel for Customer Service. For more information, see the Dynamics 365 Customer Service pricing overview and Dynamics 365 Customer Service pricing plan pages.
As a bot author, you can enable your Azure bot to understand context while authoring a bot flow. Bot context includes context name-value pairs for the current conversation and custom context passed by API programmatically.
When customers initiate a conversation, the relevant context that's related to the customer, the issue they're facing, and recent activities performed by them can be made available for the bot to intelligently provide contextual responses to resolve customer issues in a quick and efficient manner. For example, the bot can use the signed-in user details to look up the recent case information or order history of the customer and provide a response. Similarly, the pre-conversation information, custom context, or recent pages browsed on a website by the customer can be passed on to the bot by configuring context variables for the Azure bot.
For information on configuring context variables, see Configure context variables for a bot.
Install the bot SDK in your project
To open the NuGet Package Manager, right-click your project and then select Manage NuGet Packages.
In the NuGet Package Manager, select the package source as nuget.org and browse for "Microsoft.Xrm.Omnichannel.BotSDK". Select the package and then select Install. More information: Nuget page
Alternatively, you can use the following command in NuGet CLI.
Install-Package Microsoft.Xrm.Omnichannel.BotSDK
The bot SDK is now installed and the Omnichannel middleware is available in your project.
Use the Omnichannel middleware in your bot code
Use this procedure if you've created your bot using Visual Studio Azure Bot template or Azure portal.
Open the AdapterWithErrorHandler.cs file.
Add the import statement and instantiate the Omnichannel middleware.
using Microsoft.Omnichannel.Bot.Middleware; Use(new OmnichannelMiddleware());
Use context for Azure bots in your bot code
The Omnichannel for Customer Service context messages are sent as event activity to bots, and you need to override the OnEventActivityAsync method to process the context messages.
Here's a sample code that you can use to fetch and use the context for Azure bots.
protected override async Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
if (turnContext.Activity.Name == "omnichannelSetContext")
{
// Replace with your logic to fetch the context from Activity.Value
IActivity replyActivity = MessageFactory.Text($"Received context : {turnContext.Activity.Value.ToString()}");
// Replace with your logic to consume the context
await turnContext.SendActivityAsync(replyActivity, cancellationToken);
}
}
More information: Event-driven conversations using an activity handler
See also
Send custom context
setContextProvider
Integrate an Azure bot
Feedback
Submit and view feedback for