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

Admin 1 Reputation point
2022-04-06T06:01:57.217+00:00

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);
        }
    }
Microsoft Q&A
Microsoft Q&A
Use this tag to share suggestions, feature requests, and bugs with the Microsoft Q&A team. The Microsoft Q&A team will evaluate your feedback on a regular basis and provide updates along the way.
825 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,949 questions
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 47,236 Reputation points Microsoft Employee
    2022-04-06T10:49:26.98+00:00

    @Admin 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://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-send-messages?view=azure-bot-service-4.0&tabs=csharp

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.