Send Multiple Message in Bot Framework in Dialog

Brijesh Pankhaniya 21 Reputation points
2021-05-13T06:24:43.293+00:00

i create one Dialog Which have Following Method in Bot Framework:

which return some string data store in local variable, then i send to Emulator with help of stepContext.EndDialogAsync();

 CreateAndSendMessage(stepContext, replyText, attachment, query, suggessionActions);  
 CreateAndSendMessage(stepContext, dataState.allenNlpTitle, attachment, query, suggessionActions);  
  
return await stepContext.EndDialogAsync();  

CreateAndSendMessage method have Following Code:

here i Create Promp Option and use stepContext.PromptAsync() method which return to Dialog

private async void CreateAndSendMessage(WaterfallStepContext stepContext, string text, Attachment attachment, string queryText, List<CardAction> suggesstions)
{
bool isAttachment = false;
List<CardAction> suggessionActions = new List<CardAction>();
if (attachment.Content != null)
{
isAttachment = true;
}
SPHelper spHelper = new SPHelper(_spService);
var dataState = await DataStateAccessor.GetAsync(stepContext.Context);

            try  
            {  
                if (suggesstions.Count == 0)  
                {  
                    suggessionActions = spHelper.SuggessionSearch(dataState.suggestionsData, queryText, dataState);  
                    if (suggessionActions.Count == 0)  
                    {  
                        suggessionActions = spHelper.SuggessionSearch(dataState.suggestionsData, string.Empty, dataState);  
                    }  
                }  
                else  
                {  
                    suggessionActions = suggesstions;  
                }  
            }  
            catch (Exception ex)  
            {  
                //catch exception  
            }  
            var opts = new PromptOptions();  
            if (isAttachment)  
            {  
                opts = new PromptOptions  
                {  
                    Prompt = new Activity  
                    {  
                        Type = ActivityTypes.Message,  
                        Text = string.Empty,  
                        SuggestedActions = new SuggestedActions() { Actions = suggessionActions },  
                        Attachments = new List<Attachment>() { attachment }  
                    }  
                };  
            }  
            else  
            {  
                opts = new PromptOptions  
                {  

                    Prompt = new Activity  
                    {  
                        Type = ActivityTypes.Message,  
                        Text = text,  
                        SuggestedActions = new SuggestedActions() { Actions = suggessionActions }  
                    }  
                };  

            }  
            await stepContext.PromptAsync(NamePrompt, opts);  
    }  

But got three Message in Bot Emulator. though i Call the Method only Twice but i got Three responce in Emulator. screenshot is Given below:96245-teggan.png96246-emulator.png

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

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.