question

Admin-4618 avatar image
0 Votes"
Admin-4618 asked romungi-MSFT answered

cannot convert from 'string' to 'Microsoft.Bot.Schema.IActivity' error

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);
         }
     }
qna-feedbackazure-cognitive-servicesazure-qna-maker
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Admin-4618 Did you get a chance to check if the below suggestion helped?

0 Votes 0 ·

1 Answer

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered

@Admin-4618 The formatting on this thread seems to be off and no details are available about the snippet that is added. Based on error mentioned in thread title, I assume this comparison might be causing the error.

 if (turnContext.Activity.Text.Equals("escalate", StringComparison.InvariantCultureIgnoreCase))

Maybe, you could check if this works.

 if (string.Equals(turnContext.Activity.Text, "escalate", System.StringComparison.InvariantCultureIgnoreCase))



Ref: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-send-messages?view=azure-bot-service-4.0&tabs=csharp

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.