在Bot Framework中以形式方法回复英雄卡c#

时间:2017-03-23 16:13:47

标签: c# bots botframework

我有一个对话框从我开始表格,我希望在用户完成表格后显示英雄卡。我正在使用下面的代码启动表单,并分配后表单方法。

var startFormDialog = Chain.From(() => FormDialog.FromForm(StartForm.BuildForm, FormOptions.PromptInStart));    
context.Call<StartForm>(startFormDialog,AfterMenuForm);

//AfterMenuForm method implementation
private async Task AfterMenuForm(IDialogContext context, IAwaitable<StartForm> result)
{
    message = (Activity)context.MakeMessage();
    Activity replyToConversation = message.CreateReply("Should go to conversation, with a hero card");
     replyToConversation.Recipient = message.From;
     replyToConversation.Type = "message";
     replyToConversation.Attachments = new List<Attachment>();
     //List<CardImage> cardImages = new List<CardImage>();
     replyToConversation.AttachmentLayout = "carousel";
     List<CardAction> cardButtons = new List<CardAction>();
     CardAction plButton = new CardAction()
     {
         Value = "https://en.wikipedia.org/wiki/Pig_Latin",
         Type = "openUrl",
         Title = "WikiPedia Page"
     };
     cardButtons.Add(plButton);
     HeroCard plCard = new HeroCard()
     {
         Title = "I'm a hero card",
         Subtitle = "Pig Latin Wikipedia Page",
         //Images = cardImages,
                    Buttons = cardButtons
      };
      Attachment plAttachment = plCard.ToAttachment();
      replyToConversation.Attachments.Add(plAttachment);
      await context.PostAsync(replyToConversation);
}

问题是,为了能够向用户发送Hero Card答案,我需要活动对象,这在AfterMenuForm方法中不可用。有没有办法在这个方法中表示活动对象?

1 个答案:

答案 0 :(得分:3)

您可以使用IDialogContext创建新的IMessageActivity并发送HeroCard

试试context.MakeMessage();。收到消息后,您只需使用它即可发送信用卡。你不需要对该消息进行CreateReply,这不是必需的。

此外,根据方案,您可能会访问原始活动的内容。这可以在context.Activity上找到。

最后,我不确定你为什么使用Chain.From;你应该只是使用:

var startFormDialog = FormDialog.FromForm(StartForm.BuildForm, FormOptions.PromptInStart));    
context.Call<StartForm>(startFormDialog,AfterMenuForm);