Search code examples
c#botframeworkazure-qna-maker

Cannot implicitly convert string to Microsoft.Bot.Schema.Activity


I am working on Bot Framework, and want some help.

I want to show a new login card. For that I am creating a new activity because I want Bot to show that login card when the chat loads.

I have this code with me: enter image description here

As you can see in the above code, when I am writing:

Activity activity = turnContext.Activity.ToString()

It gives me error stating:

Cannot implicitly convert from string to Microsoft.Bot.Schema.Activity.

To check if this works, I wrote:

Activity activity = (Activity)turnContext.Activity.ToString()

but still no luck.

What am I missing here? And what is the correct method to create an activity??


Solution

  • Check the property you are using: https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.turncontext.activity?view=botbuilder-dotnet-stable#Microsoft_Bot_Builder_TurnContext_Activity

    Gets the activity associated with this turn; or null when processing a proactive message.

    So your code would build like this:

    Activity activity = turnContext.Activity;