protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
if(turnContext!=null)
{
var options = new QnAMakerOptions();
// The actual call to the QnA Maker service.
var replyActivity = await Services.QnAMakerService.GetAnswersAsync(turnContext, options);
if (turnContext.Activity.Type == ActivityTypes.Message)
{
if (replyActivity != null)
{
await turnContext.SendActivityAsync(MessageFactory.Text(replyActivity[0].Answer), cancellationToken);
}
else
{
await turnContext.SendActivityAsync(MessageFactory.Text("No answers were found."), cancellationToken);
}
}
// Run the Dialog with the new message Activity.
await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
// Replace with your own condition for bot escalation
if (turnContext.Activity.Text.Equals("escalate", StringComparison.InvariantCultureIgnoreCase))
{
Dictionary<string, object> contextVars = new Dictionary<string, object>() { { "BotHandoffTopic", "escalate" } };
OmnichannelBotClient.AddEscalationContext(replyActivity[0].Activity, contextVars);
}
// Replace with your own condition for bot end conversation
else if (turnContext.Activity.Text.Equals("endconversation", StringComparison.InvariantCultureIgnoreCase))
{
Dictionary<string, object> contextVars = new Dictionary<string, object>() { { "BotHandoffTopic", "endconversation" } };
OmnichannelBotClient.AddEndConversationContext(replyActivity[0].Answer);
}
// Call method BridgeBotMessage for every response that needs to be delivered to the customer.
else
{
OmnichannelBotClient.BridgeBotMessage(replyActivity[0].Answer);
}
await turnContext.SendActivityAsync(MessageFactory.Text(replyActivity[0].Answer), cancellationToken);
}
}