2017-10-19 75 views
0

BotFramework中的SuggestedActions和Keyboard類有什麼區別?SuggestedActions vs BotFramework中的鍵盤?

我目前正試圖運行一個瀑布,我提出一個問題,用戶選擇一個選項,然後跳到瀑布的下一步。我已經實現了按鈕的建議操作功能

const msg = new builder.Message(session) 
    .text("Which pair? \nExample: ETH BTC") 
    .suggestedActions(
    builder.SuggestedActions.create(
     session, [ 
      builder.CardAction.postBack(session, "BTC USD", "BTC USD"), 
      builder.CardAction.postBack(session, "ETH USD", "ETH USD"), 
      builder.CardAction.postBack(session, "ETH BTC", "ETH BTC"), 
      builder.CardAction.postBack(session, "XRP BTC", "XRP BTC"), 
      builder.CardAction.postBack(session, "ZEC USD", "ZEC USD") 
     ] 
    )); 
session.send(msg); 

同樣也是可行的與鍵盤類

const msg = new builder.Message(session) 
    .text("Which pair? \nExample: ETH BTC") 
    .addAttachment(new builder.Keyboard(session) 
     .buttons([ 
      builder.CardAction.postBack(session, "BTC USD", "BTC USD"), 
      builder.CardAction.postBack(session, "ETH USD", "ETH USD"), 
      builder.CardAction.postBack(session, "ETH BTC", "ETH BTC"), 
      builder.CardAction.postBack(session, "XRP BTC", "XRP BTC"), 
      builder.CardAction.postBack(session, "ZEC USD", "ZEC USD") 
     ]).toAttachment() 
    ) 
session.send(msg); 

如何捕獲這個按鈕,在接下來的瀑布步反應,或者我應該切換到使用提示來代替。這與鍵盤類有什麼區別

回答

1

SuggestedActionsKeyboard的替代品(例如in C#你會看到他們鍵盤相關的東西標記爲Obsolete)。

要捕獲響應,可以將建議操作作爲提示選擇的一部分發送,如feature-suggestedActions示例中所示。

bot.dialog('/', [ 
    function (session) { 

     var msg = new builder.Message(session) 
      .text("Hi! What is your favorite color?") 
      .suggestedActions(
       builder.SuggestedActions.create(
        session,[ 
         builder.CardAction.imBack(session, "green", "green"), 
         builder.CardAction.imBack(session, "blue", "blue"), 
         builder.CardAction.imBack(session, "red", "red") 
        ] 
       ) 
      ); 
     builder.Prompts.choice(session, msg, ["green", "blue", "red"]); 
    }, 
    function(session, results) { 
     session.send('I like ' + results.response.entity + ' too!'); 
    } 
]);