【问题标题】:How can I identify the particular attachments when I click on a button in cards?当我单击卡片中的按钮时,如何识别特定的附件?
【发布时间】:2017-02-07 15:12:06
【问题描述】:

我正在开发一个机器人项目。如何实现这样的功能?

在这里,当我单击 Search Flights 的 Show Me 按钮时,它会提供航班相关信息,当我单击 Search Hotel 的 Show Me 按钮时,它会提供酒店相关信息。

在我当前的工作机器人中,当我现在单击保留时(如上图中的“显示我”按钮),我收到的 JSON 响应没有所选附件的信息,如下图所示。

那么,我怎样才能在我的机器人中做同样的事情呢?

为此,我在我的项目中编写以下代码行

enter code here
  place=activity.text(with in the place i am passing the city name)
               MessagesController.hotelsList = await       PropertyService.getHotelsList(place, DateTime.Now);
            var hotellist = MessagesController.hotelsList;
            Activity replyToConversation = message.CreateReply("Welcome to **Hotel Reservation Bot**." + "(Hi)");
            replyToConversation.Recipient = message.From;
            replyToConversation.Type = "message";
            replyToConversation.Attachments = new List<Attachment>();

            foreach (var list in hotellist.SearchResults)
            {

                List<CardAction> cardButtons = new List<CardAction>();
                CardAction plButton = new CardAction()
                {
                    Value ="Reserve Now",
                    Type = "imBack",
                    Title = "Reserve Now"
                };
                cardButtons.Add(plButton);
                ThumbnailCard plCard = new ThumbnailCard()
                {
                    Title = i + "." + "Name:" + list.Property.CallingDisplayName,
                    Subtitle = "Location:" + list.Property.Location.City,
                    Images = cardImages,
                    Buttons = cardButtons
                };
                        Attachment plAttachment = plCard.ToAttachment();
                        replyToConversation.Attachments.Add(plAttachment);
                        i++;

            }
            replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            await context.PostAsync(replyToConversation);

【问题讨论】:

    标签: bots botframework botbuilder


    【解决方案1】:

    最好显示代码,但总体思路是按钮上的文本和该按钮实际发送到聊天的内容必须不同:

    var button = new CardAction() {
        Title = "Show me",
        Value = "Show restaurant #" + restaurantID,
        Type = ActionTypes.imBack
    };
    

    当用户点击它时,他们会在聊天中看到"Show me",但实际上您的应用程序会在Activity.Text 中收到"Show restaurant #35"

    【讨论】:

    • 嗨@k48 我在上面的问题中添加了代码,请通过他们的
    • 所以只需将 Value ="Reserve Now" 更改为您需要传递的实际值?例如。 ID。
    • 实际上,在 C# 中,Value 是发送到聊天的内容。
    • 我们也做了和你上面说的一样的事情,但我认为这不是一个好的程序
    • 我也做了同样的事情,就像在聊天中显示的值分配一样
    猜你喜欢
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2021-05-31
    • 2022-06-30
    • 2020-12-24
    • 1970-01-01
    相关资源
    最近更新 更多