iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 14
0

https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-dialog-actions

Actions

去年還沒這個東西, 主要用意,就是如下圖所示,當使用者在原本的對話邏緝佳,可以再呼叫,而不影響原本的流程。

Action types

triggerAction

Global Binds an action to the dialog that will clear the dialog stack and push itself onto the bottom of stack. Use onSelectAction option to override this default behavior.

// Order dinner.
bot.dialog('orderDinner', [
//...waterfall steps...
])
// Once triggered, will clear the dialog stack and pushes
// the 'orderDinner' dialog onto the bottom of stack.
.triggerAction({
matches: /^order dinner$/i
});

customAction

Global Binds a custom action to the bot that can process information or take action without affecting the dialog stack. Use onSelectAction option to customize the functionality of this action.

bot.customAction({
matches: /remind|reminder/gi,
onSelectAction: (session, args, next) => {
// Set reminder...
session.send("Reminder is set.");
}
})

beginDialogAction

Contextual Binds an action to the dialog that starts another dialog when it is triggered. The starting dialog will be pushed onto the stack and popped off once it ends.
// Order dinner.
bot.dialog('orderDinner', [
//...waterfall steps...
])
// Once triggered, will start the 'showDinnerCart' dialog.
// Then, the waterfall will resumed from the step that was interrupted.
.beginDialogAction('showCartAction', 'showDinnerCart', {
matches: /^show cart$/i
});

// Show dinner items in cart
bot.dialog('showDinnerCart', function(session){
for(var i = 1; i < session.conversationData.orders.length; i++){
session.send(You ordered: ${session.conversationData.orders[i].Description} for a total of $${session.conversationData.orders[i].Price}.);
}

// End this dialog
session.endDialog(`Your total is: $${session.conversationData.orders[0].Price}`);

});
//可以在原本的dailog裡push 進新的dialog 不影響原本的進行

reloadAction

Contextual Binds an action to the dialog that causes the dialog to reload when it is triggered. You can use reloadAction to handle user utterances like "start over."

// Order dinner.
bot.dialog('orderDinner', [
//...waterfall steps...
])
// Once triggered, will restart the dialog.
.reloadAction('startOver', 'Ok, starting over.', {
matches: /^start over$/i
});
//可以清空原本的dialog data 重新開始

cancelAction

Contextual Binds an action to the dialog that cancels the dialog when it is triggered. You can use cancelAction to handle user utterances like "cancel" or "nevermind."
// Order dinner.
bot.dialog('orderDinner', [
//...waterfall steps...
])
//Once triggered, will end the dialog.
.cancelAction('cancelAction', 'Ok, cancel order.', {
matches: /^nevermind$|^cancel$|^cancel.*order/i
});
整個取消

endConversationAction

Contextual Binds an action to the dialog that ends the conversation with the user when triggered. You can use endConversationAction to handle user utterances like "goodbye."

// Order dinner.
bot.dialog('orderDinner', [
//...waterfall steps...
])
// Once triggered, will end the conversation.
.endConversationAction('endConversationAction', 'Ok, goodbye!', {
matches: /^goodbye$/i
});

第二個參數,可以塞想講的話,也可以塞dialog


上一篇
Replace dialogs
下一篇
Send proactive messages
系列文
Microsoft Bot Framework 30天上手 + 自幹 Line Builder 串接 + Line Bot Demo30

尚未有邦友留言

立即登入留言