2016-09-29 54 views
3

我正在處理一個bot項目。我如何實現這樣的功能?當我點擊卡片上的按鈕時,如何識別特定的附件?

enter image description here

在這裏,當我點擊機票的示範按鈕其提供航班相關信息,當我點擊顯示我的搜索按鈕,酒店提供了酒店的相關信息。

在我當前的工作機器人,當我點擊保留現在(如上圖顯示我的按鈕)我得到的JSON響應沒有選定的附件的信息,如下圖所示。

enter image description here

所以,我該怎麼辦我的機器人同樣的事情?

對於我寫的代碼下面的線在我的項目

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); 

回答

0

這將是最好的,如果你想展示你的代碼,但總的想法是,在按鈕上,什麼是文本實際上按鈕發送到聊天必須是不同的:

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

當用戶點擊它,就會看到在聊天"Show me",但實際上你的應用程序將在Activity.Text收到"Show restaurant #35"

+0

hi @ k48我在以上問題中添加了代碼,請通過他們的 – sateesh

+0

因此,將Value =「立即預訂」更改爲您需要傳遞的實際值?例如。 ID。 – K48

+0

實際上,在C#中,值是發送到聊天的內容。 –

相關問題