microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User response from button selection on Adaptive card not working on Facebook Messenger

nouman937 opened this issue · comments

We are using Azure bot framework that is connected to Omnichannel solution. Customer connects to Facebook messenger it gets routed to Omnichannel and then omnichannel routes the conversation to Azure bot as an agent.
Bot is asking customer to select an option using adaptive card which is being used as CardActivity and sent to customer using ChoicePrompt as can be seen in the code below. Based on the option select, We are performing further action like initiating a chat with actual agent in omnichannel.
The issue is that when customer select an option from adaptive card on Facebook, the "OnMessageActivityAsync" is not getting triggered in our DialogBot class and hence we are not able to find out what the customer has selected. This functionality is working fine on bot emulator but not on Facebook as can be seen in snapshots

To Reproduce

  1. Create adaptive card with one user input
  2. Integrate it with Facebook
  3. Based on user input, parse the response within chatbot code

Expected behavior

When user selects an option, the OnMessageActivityAsync should be triggered with user input response

##Code for Adaptive Card
List stepList_AR = new List();
stepList_AR.Add(LanguageModel.Talk_to_agent_AR);////Adding only one step in List

      // Create card
            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                // Use LINQ to turn the choices into submit actions
                Actions = stepList.Select(choice => new AdaptiveSubmitAction
                {
                    Title = choice,
                    Data = choice,// This will be a string

                }).ToList<AdaptiveAction>(),
            };

//Card Activity
Cardactivity = MessageFactory.Attachment(new Attachment
{
ContentType = AdaptiveCard.ContentType,
// Convert the AdaptiveCard to a JObject
Content = JObject.FromObject(card),
});

return await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
{
Prompt = (Activity)Cardactivity,
Choices = ChoiceFactory.ToChoices(stepList),
// Don't render the choices outside the card
Style = ListStyle.None,
},
cancellationToken);
Emulator
Facebook

Screenshots

Attached

Hi @nouman937,

Let's try to isolate this issue to find the root cause of this problem.

Is this issue reproducible without omnichannel?

Hi @nouman937, I can look into this.

Hi @nouman937,

I isolated this issue from omnichannel and was not able to repro. The OnMessageActivityAsync handler successfully gets triggered when a user selects an option from adaptive card in Facebook.

I modified the 02.echo-bot sample to send the adaptive card like this:

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
    var receivedText = turnContext.Activity.Text?.ToLower();

    if (receivedText == "card")
    {
        await SendAdaptiveCardAsync(turnContext, cancellationToken);
    }
    else
    {
        var replyText = $"Echo: {turnContext.Activity.Text}";
        await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken);
    }
}

private async Task SendAdaptiveCardAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
    var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
    {
        Actions = new List<AdaptiveAction>
        {
            new AdaptiveSubmitAction
            {
                Title = "Option 1",
                Data = "option1"
            },
            new AdaptiveSubmitAction
            {
                Title = "Option 2",
                Data = "option2"
            }
        }
    };

    var attachment = new Attachment
    {
        ContentType = AdaptiveCard.ContentType,
        Content = JObject.FromObject(card)
    };

    var response = MessageFactory.Attachment(attachment);
    await turnContext.SendActivityAsync(response, cancellationToken);
}

Demo:

Screen.Recording.2024-02-09.at.3.38.27.PM.mov

Documentation followed:
https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-facebook?view=azure-bot-service-4.0&tabs=messenger

Attached is the tested bot sample:
02.echo-bot.zip