How to show a list of applications and asking user to select one to show more details in Microsoft Bot Framework

Rupen A 20 Reputation points
2023-12-26T14:35:31.5533333+00:00

I am working on Chatbot development using Microsoft Bot Framework. The requirement is that when user provides her details like account number and date of birth, the chat bot should show her a list of application under her account. From that list, she should be able to pick one of the application and the chat bot should fetch it's details like date of application, status etc.

My API for the product has been setup and it fetches list like:

[
{
"id":"123",
"applicaitonID":"AA123",
"Status":"InProgress"
},
{
"id":"456",
"applicaitonID":"AA456",
"Status":"Completed"
},
]

From above response, Chatbot should create a table that shows applicationId as hyperlinks.

Upon clicking on that link, chatbot should fetch details of the specific application.

I do understand very basics of MBF (Microsoft Bot Framework). Any example/suggestion will be very helpful.

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
751 questions
0 comments No comments
{count} votes

Accepted answer
  1. Azar 19,400 Reputation points
    2023-12-27T04:48:31.3233333+00:00

    Hi Rupen A

    you'll need to handle user input, call your API to fetch the list of applications, present the list to the user, and then respond to the user's selection by fetching details for the selected application, find the code below change it as per ur need.

    // Import necessary namespaces
    using System.Collections.Generic;
    using Microsoft.Bot.Builder;
    using Microsoft.Bot.Builder.Dialogs;
    using Microsoft.Bot.Schema;
    
    // Define your main dialog class
    public class MainDialog : ComponentDialog
    {
        // Define a constant for the waterfalls steps
        private const string InitialStep = "initialStep";
    
        // Constructor
        public MainDialog() : base(nameof(MainDialog))
        {
            // Define the waterfall steps
            var waterfallSteps = new WaterfallStep[]
            {
                InitialStepAsync,
                DisplayApplicationsAsync,
                DisplayApplicationDetailsAsync,
            };
    
            // Add the waterfall dialog to the main dialog
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
    
            // Set the initial dialog
            InitialDialogId = nameof(WaterfallDialog);
        }
    
        // Initial step - collect account number and date of birth
        private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Your code to collect account number and date of birth from the user
            // ...
    
            // Save the collected information in the dialog state
            return await stepContext.NextAsync(null, cancellationToken);
        }
    
        // Display the list of applications
        private async Task<DialogTurnResult> DisplayApplicationsAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Your code to call the API and get the list of applications
            List<Application> applications = YourApiCallToGetApplications();
    
            // Create a message to display the list of applications
            var reply = MessageFactory.Text("Here is the list of applications:");
            reply.SuggestedActions = new SuggestedActions();
    
            foreach (var application in applications)
            {
                // Add each application as a suggested action
                reply.SuggestedActions.Actions.Add(new CardAction
                {
                    Title = application.ApplicationID,
                    Type = ActionTypes.ImBack,
                    Value = application.ApplicationID,
                });
            }
    
            // Send the message with the list of applications
            await stepContext.Context.SendActivityAsync(reply, cancellationToken);
    
            return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Please select an application.") }, cancellationToken);
        }
    
        // Display the details of the selected application
        private async Task<DialogTurnResult> DisplayApplicationDetailsAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Retrieve the selected application ID
            string selectedApplicationID = stepContext.Result.ToString();
    
            // Your code to call the API and get the details of the selected application
            ApplicationDetails details = YourApiCallToGetApplicationDetails(selectedApplicationID);
    
            // Your code to display the details to the user
            // ...
    
            // End the dialog
            return await stepContext.EndDialogAsync(null, cancellationToken);
        }
    
        // Your methods for API calls to get applications and application details
        private List<Application> YourApiCallToGetApplications()
        {
            // Implement your logic to call the API and get the list of applications
            // ...
    
            // Sample data for illustration
            return new List<Application>
            {
                new Application { Id = "123", ApplicationID = "AA123", Status = "InProgress" },
                new Application { Id = "456", ApplicationID = "AA456", Status = "Completed" },
            };
        }
    
        private ApplicationDetails YourApiCallToGetApplicationDetails(string applicationID)
        {
            // Implement your logic to call the API and get the details of the selected application
            // ...
    
            // Sample data for illustration
            return new ApplicationDetails { /* Populate details */ };
        }
    }
    
    
    

    If this helps kindly accept the answer thanks much.


0 additional answers

Sort by: Most helpful