Parse event activity JSON to get bot context
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.
The Omnichannel for Customer Service context messages are sent as event activity to bots. Context information such as customer info, live work item, or conversation ID, is sent to the bot as part of an activity JSON. The JSON can be of type startConversation for most channels and ConversationUpdate for voice conversations.
Fetch and use context for bots in your bot code
To process these context messages, use activity handlers and override them in your bot code. For information on how to use activity handlers, see Event-driven conversations using an activity handler.
In the following example, when the event activity is received, the OnEventActivityAsync
method is called to fetch and use the context.
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);
}
}
Next steps
Code samples for parsing activity JSON
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for