C# 无法在Chatbot V4框架中使用choicePrompt中的值

C# 无法在Chatbot V4框架中使用choicePrompt中的值,c#,botframework,C#,Botframework,我正在使用以下代码: using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using AdaptiveCards; using CoreBot; using CoreBot.Dialogs; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Di

我正在使用以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveCards;
using CoreBot;
using CoreBot.Dialogs;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Microsoft.Bot.Schema;
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
using Newtonsoft.Json.Linq;

namespace Microsoft.BotBuilderSamples.Dialogs
{
    public class SharepointDialog : CancelAndHelpDialog
    {
        private const string DestinationStepMsgText = "Enter the type of document you want to search ";
        private const string OriginStepMsgText = "Enter the name of document you want to search";
        string documentName = null;
        string documentType = null;
        public string CHOICEPROMPT { get; private set; }
        public object AdaptiveCard { get; private set; }

        public SharepointDialog()
            : base(nameof(SharepointDialog))
        {
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
            AddDialog(new DateResolverDialog());
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                DestinationStepAsync,
                OriginStepAsync,
                ConfirmStepAsync,
                FinalStepAsync,
            }));



            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }

        //private static async Task SendIntroCardAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        //{
        //    var card = new HeroCard();
        //    card.Title = "Welcome to Bot Framework!";
        //    card.Text = @"Welcome to Welcome Users bot sample! This Introduction card
        //                 is a great way to introduce your Bot to the user and suggest
        //                 some things to get them started. We use this opportunity to
        //                 recommend a few next steps for learning more creating and deploying bots.";
        //    card.Images = new List<CardImage>() { new CardImage("https://aka.ms/bf-welcome-card-image") };
        //    card.Buttons = new List<CardAction>()
        //    {
        //        new CardAction(ActionTypes.OpenUrl, "HR Contingent", null, "HR Contingency", "Get an overview", "https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0"),
        //        new CardAction(ActionTypes.OpenUrl, "Management Tools", null, "Management Tools", "Ask a question", "https://stackoverflow.com/questions/tagged/botframework"),
        //    };

        //    var response = MessageFactory.Attachment(card.ToAttachment());
        //    await turnContext.SendActivityAsync(response, cancellationToken);
        //}
        private async Task<DialogTurnResult> DestinationStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var docNameDetails = (SharepointDetails)stepContext.Options;
            //docNameDetails.DocType = (string)stepContext.Result;

            if (docNameDetails.DocType == null)
            {
                var promptMessage = MessageFactory.Text(DestinationStepMsgText, DestinationStepMsgText, InputHints.ExpectingInput);

                   var choices = new[] { "One", "Two", "Three" };
            return await stepContext.PromptAsync("ShowChoicePrompt", new PromptOptions
            {
                Style = ListStyle.SuggestedAction,
                Prompt = MessageFactory.Text("Please select from choices"),
                RetryPrompt = MessageFactory.Text("Sorry, Please the valid choice"),
                Choices = ChoiceFactory.ToChoices(choices),
            }, cancellationToken);
                // return await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
            }

            return await stepContext.NextAsync(docNameDetails.DocType, cancellationToken);
        }

        private static async Task SendResCardAsync(ITurnContext turnContext, CancellationToken cancellationToken, List<string> resSpList)

        {
            var card = new HeroCard();
            card.Title = "Sharepoint Result";
            card.Text = @"Click on below result";
            card.Images = new List<CardImage>() { new CardImage("https://aka.ms/bf-welcome-card-image") };

            foreach (var rs in resSpList)
            {

                string[] subLink = rs.Split('/');
                string docTitle = subLink[subLink.Length - 1];
                card.Buttons = new List<CardAction>()
            {
                new CardAction(ActionTypes.OpenUrl, docTitle, null, docTitle, "All",rs),


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

        private async Task<DialogTurnResult> OriginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var docNameDetails = (SharepointDetails)stepContext.Options;

            docNameDetails.DocType = (string)stepContext.Result;

            if (docNameDetails.SharepointSearch == null)
            {
                var promptMessage = MessageFactory.Text(OriginStepMsgText, OriginStepMsgText, InputHints.ExpectingInput);
                return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
            }


            return await stepContext.NextAsync(docNameDetails.SharepointSearch, cancellationToken);
        }



        private async Task<DialogTurnResult> ConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var docNameDetails = (SharepointDetails)stepContext.Options;
            docNameDetails.SharepointSearch= (string)stepContext.Result;

            var messageText = $"Please confirm docName: {docNameDetails.SharepointSearch}  and docType: {docNameDetails.DocType}  Is this correct?";
            var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
            documentName = docNameDetails.SharepointSearch;
            documentType = docNameDetails.DocType;
            return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
        }

        private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            List<string> res = new List<string>();
            SharepointSearchDialog sharepointservice = new SharepointSearchDialog();
            res = await sharepointservice.SharepointSearchEng(documentName, documentType);
            SendResCardAsync(stepContext.Context, cancellationToken, res);
            if ((bool)stepContext.Result)
            {
                var bookingDetails = (BookingDetails)stepContext.Options;

                return await stepContext.EndDialogAsync(bookingDetails, cancellationToken);
            }

            return await stepContext.EndDialogAsync(null, cancellationToken);
        }

        private static bool IsAmbiguous(string timex)
        {
            var timexProperty = new TimexProperty(timex);
            return !timexProperty.Types.Contains(Constants.TimexTypes.Definite);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统线程;
使用System.Threading.Tasks;
使用适配卡;
使用CoreBot;
使用CoreBot.Dialogs;
使用Microsoft.Bot.Builder;
使用Microsoft.Bot.Builder.Dialogs;
使用Microsoft.Bot.Builder.Dialogs.Choices;
使用Microsoft.Bot.Schema;
使用Microsoft.Recognizers.Text.DataTypes.TimexExpression;
使用Newtonsoft.Json.Linq;
命名空间Microsoft.BotBuilderSamples.Dialogs
{
公共类SharepointDialog:CancelAndHelpDialog
{
private const string DestinationStepMsgText=“输入要搜索的文档类型”;
private const string OriginStepMsgText=“输入要搜索的文档名称”;
字符串documentName=null;
字符串documentType=null;
公共字符串CHOICEPROMPT{get;private set;}
公共对象自适应卡{get;private set;}
公共共享点对话框()
:base(名称(SharepointDialog))
{
AddDialog(新建文本提示(名称)(文本提示));
AddDialog(新建ChoicePrompt(名称)(ChoicePrompt));
AddDialog(新建确认提示)(名称(确认提示));
AddDialog(new dateResolvedDialog());
AddDialog(新建WaterWallDialog)(名称(WaterWallDialog),新建WaterWallStep[]
{
DestinationStepAsync,
originstepsync,
ConfirmStepAsync,
最后阶段同步,
}));
//要运行的初始子对话框。
InitialDialogId=nameof(WaterWallDialog);
}
//专用静态异步任务SendIntroCardAsync(ITurnContext turnContext,CancellationToken CancellationToken)
//{
//var卡=新卡();
//card.Title=“欢迎使用Bot框架!”;
//card.Text=@“欢迎欢迎用户bot示例!此介绍卡
//是向用户介绍您的机器人并提出建议的好方法
//一些事情让他们开始。我们利用这个机会
//建议接下来的几个步骤,以了解更多创建和部署机器人程序的信息。“;
//card.Images=new List(){new CardImage('https://aka.ms/bf-welcome-card-image") };
//card.Buttons=新列表()
//    {
//新的CardAction(ActionTypes.OpenUrl,“人力资源应急”,null,“人力资源应急”,“获取概览”https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0“,
//新的CardAction(ActionTypes.OpenUrl,“管理工具”,null,“管理工具”,“提问”https://stackoverflow.com/questions/tagged/botframework"),
//    };
//var response=MessageFactory.Attachment(card.ToAttachment());
//等待turnContext.SendActivityAsync(响应,取消令牌);
//}
专用异步任务DestinationStepAsync(WaterCallStepContext stepContext,CancellationToken CancellationToken)
{
var docNameDetails=(SharepointDetails)stepContext.Options;
//docNameDetails.DocType=(字符串)stepContext.Result;
if(docNameDetails.DocType==null)
{
var promptMessage=MessageFactory.Text(DestinationStepMsgText,DestinationStepMsgText,InputHints.ExpectingInput);
var choices=新[]{“一”、“二”、“三”};
return wait-stepContext.PromptAsync(“ShowChoicePrompt”,新提示
{
Style=ListStyle.SuggestedAction,
Prompt=MessageFactory.Text(“请从选项中选择”),
RetryPrompt=MessageFactory.Text(“对不起,请输入有效选项”),
选项=ChoiceFactory.ToChoices(选项),
},取消令牌);
//return wait-stepContext.PromptAsync(nameof(ChoicePrompt),newprompoptions{Prompt=promptMessage},cancellationToken);
}
返回wait-wait-stepContext.NextAsync(docNameDetails.DocType,cancellationToken);
}
专用静态异步任务SendResCardAsync(ITurnContext turnContext、CancellationToken CancellationToken、List resSpList)
{
var卡=新卡();
card.Title=“Sharepoint结果”;
card.Text=@“点击下面的结果”;
card.Images=new List(){new CardImage('https://aka.ms/bf-welcome-card-image") };
foreach(resSpList中的var rs)
{
字符串[]子链接=rs.Split('/');
字符串docTitle=subLink[subLink.Length-1];
card.Buttons=新列表()
{
新的CardAction(ActionTypes.OpenUrl,docTitle,null,docTitle,“All”,rs),
};
}
var response=MessageFactory.Attachment(card.ToAttachment());
等待turnContext.SendActivityAsync(响应,取消令牌);
}
专用异步任务OriginStepAsync(WaterCallStepContext stepContext,CancellationToken CancellationToken)
{
var docNameDetails=(SharepointDetails)stepContext.Options;
docNameDetails.DocType=(字符串)stepContext.Result;
if(docNameDetails.SharepointSearch==null)
{
var promptMessage=MessageFactory.Text(OriginStepMsgText,OriginStepMsgText,InputHints.ExpectingInput);
返回wait wait stepContext.PromptAsync(nameof(TextPrompt),newpromptoptions{Prompt=promptMessage},cancellationToken);
}
返回wait wait stepContext.NextAsync(docNameDetails.SharepointSearch,cancellationToken);
}
专用异步任务ConfirmStepAsync(WaterWallStepContext stepContext,CancellationToken CancellationToken)
{
var docNameDetails=(SharepointDetails)stepContext.Options;