Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nouman937 opened this issue Jan 20, 2024 · 4 comments
Labels
bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team.

Comments

@nouman937
Copy link

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

@nouman937 nouman937 added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Jan 20, 2024
@breakingram
Copy link
Contributor

Hi @nouman937,

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

Is this issue reproducible without omnichannel?

@nouman937
Copy link
Author

nouman937 commented Jan 21, 2024 via email

@breakingram
Copy link
Contributor

Hi @nouman937, I can look into this.

@breakingram
Copy link
Contributor

breakingram commented Feb 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team.
Projects
None yet
Development

No branches or pull requests

2 participants