3

我正在做一个机器人项目。我怎样才能实现这样的功能?

在此处输入图像描述

在这里,当我单击 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);
4

1 回答 1

0

最好显示您的代码,但一般的想法是按钮上的文本和该按钮实际发送到聊天的内容必须不同:

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

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

于 2016-09-29T11:08:07.057 回答