Botframework 自适应卡-日期输入和提交

Botframework 自适应卡-日期输入和提交,botframework,adaptive-cards,Botframework,Adaptive Cards,主要问题 我正在Microsoft Bot框架中使用自适应卡。我遇到了一个问题,在用户选择想要的日期后,我不知道如何从DateInput中获取值。以下是我目前的代码: public async Task StartAsync(IDialogContext context) { string pIdentifier = serviceFactory.ProfileService.GetPatientIdentifier(nric); string respo

主要问题

我正在Microsoft Bot框架中使用自适应卡。我遇到了一个问题,在用户选择想要的日期后,我不知道如何从DateInput中获取值。以下是我目前的代码:

public async Task StartAsync(IDialogContext context)
    {
        string pIdentifier = serviceFactory.ProfileService.GetPatientIdentifier(nric);
        string response = serviceFactory.DentalAppointmentService.GetSlotSearchDates(nric,apptId,caseNumber, institutionCode, pIdentifier);
        string[] split = response.Split(' ');
        DateTime earliestStartDate = DateTime.ParseExact(split[0], "yyyy'-'MM'-'dd'T'HH':'mm':'ss", CultureInfo.InvariantCulture);
        DateTime latestEndDate = DateTime.ParseExact(split[1], "yyyy'-'MM'-'dd'T'HH':'mm':'ss", CultureInfo.InvariantCulture);

        await context.PostAsync("Your appointment can only be rescheduled within this period " + earliestStartDate.ToShortDateString() + " to " + latestEndDate.ToShortDateString());



        AdaptiveCard card = new AdaptiveCard();

        card.Body.Add(new TextBlock()
        {
            Text = "Enter new Date",
            Size = TextSize.Large,
            Weight = TextWeight.Bolder
        });

        DateInput input = new DateInput()
        {
            Id = "Date",
            Placeholder = "New Date"
        };

        card.Body.Add(input);

        card.Actions.Add(new SubmitAction()
        {
            Title = "Submit"
        });

        Attachment cardAttachment = new Attachment()
        {
            ContentType = AdaptiveCard.ContentType,
            Content = card
        };

        var message = context.MakeMessage();
        message.Attachments = new List<Attachment>();
        message.Attachments.Add(cardAttachment);

        await context.PostAsync(message);
        context.Wait(this.MessageReceivedAsync);
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var temp = await result as Activity;
        string date = temp.Text;


        //DateTime newDate = DateTime.ParseExact(value.ToString(), "yyyy'-'MM'-'dd'T'HH':'mm':'ss", CultureInfo.InvariantCulture);

        Debug.WriteLine("Entered Msg received Async:" + date);
        await context.PostAsync(date);
    }
公共异步任务StartAsync(IDialogContext上下文)
{
字符串pIdentifier=serviceFactory.ProfileService.GetPatientIdentifier(nric);
字符串响应=serviceFactory.dentalAppointService.GetSlotSearchDates(nric、apptId、caseNumber、institutionCode、Pidentier);
string[]split=response.split(“”);
DateTime earliestStartDate=DateTime.ParseExact(拆分[0],“yyyy'-'MM'-'dd'T'HH':'MM':'ss”,CultureInfo.InvariantCulture);
DateTime latestEndDate=DateTime.ParseExact(拆分[1],“yyyy'-'MM'-'dd'T'HH':'MM':'ss”,CultureInfo.InvariantCulture);
wait context.PostAsync(“您的约会只能在此期间内重新安排”+earliestStartDate.ToSortDateString()+“到”+latestEndDate.ToSortDateString());
AdaptiveCard卡=新的AdaptiveCard();
card.Body.Add(新文本块()
{
Text=“输入新日期”,
Size=TextSize.Large,
重量=文本重量。加粗
});
DateInput=新的DateInput()
{
Id=“日期”,
占位符=“新日期”
};
卡片.正文.添加(输入);
card.Actions.Add(新提交()
{
Title=“提交”
});
附件卡片附件=新附件()
{
ContentType=AdaptiveCard.ContentType,
内容=卡片
};
var message=context.MakeMessage();
message.Attachments=新列表();
message.Attachments.Add(卡片附件);
等待上下文。PostAsync(消息);
context.Wait(this.MessageReceivedAsync);
}
专用异步任务消息ReceivedAsync(IDialogContext上下文,IAwaitable结果)
{
var temp=等待作为活动的结果;
字符串日期=临时文本;
//DateTime newDate=DateTime.ParseExact(value.ToString(),“yyyy'-'MM'-'dd'T'HH':'MM':'ss”,CultureInfo.InvariantCulture);
Debug.WriteLine(“输入的消息接收异步:+date”);
等待上下文。PostAsync(日期);
}
当前抛出错误

我目前遇到这个问题,无法找到解决方案:

引发异常:mscorlib.dll中的“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”


DatePicker中的日期值将作为activity.value上的作业对象进入bot

以下代码将从.Text属性或.Value中提取日期:

public async Task StartAsync(IDialogContext context)
{
    context.Wait(this.MessageReceivedAsync);
}


public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    var temp = await result as Activity;

    DateTime dateTime;
    var datePresent = DateTime.TryParse(temp.Text, out dateTime);
    if (!datePresent && temp.Value != null)
    {
        var jObjectValue = temp.Value as JObject;

        var dateAsString = jObjectValue.Value<string>("Date");
        if (!string.IsNullOrEmpty(dateAsString))
        {
            dateTime = DateTime.ParseExact(dateAsString, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            datePresent = true;
        }
    }

    if (!datePresent)
    {
        //since the user did not send a date, show the card
        AdaptiveCard card = new AdaptiveCard();

        card.Body.Add(new AdaptiveTextBlock()
        {
            Text = "Enter new Date",
            Size = AdaptiveTextSize.Large,
            Weight = AdaptiveTextWeight.Bolder
        });

        AdaptiveDateInput input = new AdaptiveDateInput()
        {
            Id = "Date",
            Placeholder = "New Date"
        };

        card.Body.Add(input);

        card.Actions.Add(new AdaptiveSubmitAction()
        {
            Title = "Submit"
        });

        Attachment cardAttachment = new Attachment()
        {
            ContentType = AdaptiveCard.ContentType,
            Content = card
        };

        var message = context.MakeMessage();
        message.Attachments = new List<Attachment>();
        message.Attachments.Add(cardAttachment);

        await context.PostAsync(message);
    }
    else
    {
        await context.PostAsync($"Date Entered: {dateTime}");
    }

    context.Wait(this.MessageReceivedAsync);
}
公共异步任务StartAsync(IDialogContext上下文)
{
context.Wait(this.MessageReceivedAsync);
}
公共虚拟异步任务消息ReceivedAsync(IDialogContext上下文,IAwaitable结果)
{
var temp=等待作为活动的结果;
日期时间日期时间;
var datePresent=DateTime.TryParse(temp.Text,out DateTime);
如果(!datePresent&&temp.Value!=null)
{
var jObjectValue=作为JObject的临时值;
var dateAsString=jObjectValue.Value(“日期”);
如果(!string.IsNullOrEmpty(dateAsString))
{
dateTime=dateTime.ParseExact(dateAsString,“yyyy-MM-dd”,CultureInfo.InvariantCulture);
datePresent=true;
}
}
如果(!datePresent)
{
//由于用户未发送日期,请显示卡片
AdaptiveCard卡=新的AdaptiveCard();
card.Body.Add(新的AdaptiveTextBlock()
{
Text=“输入新日期”,
大小=AdaptiveTextSize.Large,
权重=自适应文本权重。加粗
});
AdaptiveDateInput=新的AdaptiveDateInput()
{
Id=“日期”,
占位符=“新日期”
};
卡片.正文.添加(输入);
card.Actions.Add(新的AdaptiveSubmitation()
{
Title=“提交”
});
附件卡片附件=新附件()
{
ContentType=AdaptiveCard.ContentType,
内容=卡片
};
var message=context.MakeMessage();

message.Attachments=new List

我不知道您为什么会看到RuntimeBinderException…我认为您需要在某个地方共享您的项目以获得解决该问题的帮助。我按照您的步骤进行了操作,效果很好!感谢您通过此示例拓宽我的知识面,让我了解如何在Json对象中获取值。非常感谢!@Eric Dahlvang