2017-04-25 72 views
1

我想獲得按鈕的標題,當用戶點擊任何按鈕。我可以如何實現這一點。我試圖找到解決方案,但沒有找到適當的解。 我才知道那我怎樣才能得到按鈕的標題點擊機器人框架

IActionActivity 

在使用上按一下按鈕進行操作,但我不知道如何來實現這個接口來獲得按鈕的標題,當用戶點擊

下面

圖片鏈接中給出
[BotAuthentication] 
    public class MessagesController : ApiController 
    { 

    public async Task<HttpResponseMessage> Post([FromBody]Activity activity) 
    { 
     ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 

     if (activity.Type == ActivityTypes.Message) 
     { 
      Options(activity); 
     } 

     var response = Request.CreateResponse(HttpStatusCode.OK); 
     return response; 
    } 




     private void Options(Activity reply) 
     { 
     reply.Attachments = new List<Attachment>(); 
     List<CardAction> cardButtons = new List<CardAction>(); 
     CardAction Button1 = new CardAction() 
     { 
      Value = "Product is an interesting career choice.", 
      Type = "postBack", 
      Title = "Product" 

     }; 

     CardAction Button2 = new CardAction() 
     { 
      Value = "Design is an interesting career choice.", 
      Type = "postBack", 
      Title = "Design" 

     }; 

     CardAction Button3 = new CardAction() 
     { 
      Value = "Development is an interesting career choice.", 
      Type = "postBack", 
      Title = "Development" 
     }; 

     CardAction Button4 = new CardAction() 
     { 
      Value = "Marketing is an interesting career choice.", 
      Type = "postBack", 
      Title = "Marketing" 
     }; 

     CardAction Button5 = new CardAction() 
     { 
      Value = "Sales is an interesting career choice.", 
      Type = "postBack", 
      Title = "Sales" 
     }; 
     CardAction Button6 = new CardAction() 
     { 
      Value = "Administration is an interesting career choice.", 
      Type = "postBack", 
      Title = "Administration" 
     }; 
     cardButtons.Add(Button1); 
     cardButtons.Add(Button2); 
     cardButtons.Add(Button3); 
     cardButtons.Add(Button4); 
     cardButtons.Add(Button5); 
     cardButtons.Add(Button6); 
     HeroCard jobCard = new HeroCard() 
     { 
      Buttons = cardButtons 
     }; 

     Attachment jobAttachment = jobCard.ToAttachment(); 
     reply.Attachments.Add(jobAttachment); 
     reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; 

    } 
} 

conversation image from bot to user in bot emulator

回答

0

點擊後你會得到該按鈕的ValueActivity.Text應該包含該值。

無論如何,我看到你正在做控制器中的所有工作。我會建議使用Dialog

+0

感謝您的幫助兄弟 –

+0

你能告訴我如何在對話框中做到這一點 –

+0

不客氣。請將問題標記爲已回答。看看https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp那裏你會發現很多使用對話框的示例 –

相關問題