[英]How to use Google action conv.ask to get response from user and move to process
我想嘗試使用Google Actions節點js SDK向用戶詢問更多信息,然后再響應用戶,因此我可以繼續進行下一個過程。 我嘗試使用conv.ask
來等待用戶響應,但是,當用戶響應時,它只能返回到actions.intent.TEXT
而不是意圖com.example.test.DO
。 我應該如何實現呢?
app.intent('com.example.test.WHAT', (conv, input, arg) => {
conv.ask('Sure! What do you want me to help with');
})
app.intent('com.example.test.DO', (conv, input, arg) => {
//process the user response here from com.example.test.WHAT
conv.close('I have finished it');
})
app.intent('actions.intent.TEXT', (conv, input) => {
if (input === 'bye' || input === 'goodbye') {
return conv.close('See you later!')
}
conv.ask(`I didn't understand. Can you tell me something else?`)
})
動作包JSON:
{
"name": "DO",
"intent": {
"name": "com.example.test.DO",
"trigger": {
"queryPatterns": [
"stop streaming"
]
}
},
"fulfillment": {
"conversationName": "example-test"
}
},
{
"name": "WHAT",
"intent": {
"name": "com.example.test.WHAT",
"trigger": {
"queryPatterns": [
"help me"
]
}
}
我在模擬器上的問題:
Me: Talk to myTestExample to help me
Google: Sure! What do you want me to help with?
ME: Play with me
Google: I didn't understand. Can you tell me something else?
我希望它去com.example.test.DO
而不是actions.intent.TEXT
。 或在獲得用戶響應后在com.example.test.WHAT
進行處理。
更新:
我試圖制作一個全局類型變量並在action.intent.Text
內切換大小寫。
var type;
app.intent('actions.intent.TEXT', (conv, input) => {
if (input === 'bye' || input === 'goodbye' || input === 'stop') {
return conv.close('See you later!')
}
switch (type){
case 'WHAT':
//use the new input data to process sth here
return conv.close('I will help you to do this');
case 'HOW':
//use the new input data to process sth here
return conv.close('I will use this method to help with you');
}
conv.ask(`I didn't understand. Can you tell me something else?`)
}
app.intent('com.example.test.WHAT', (conv, input, arg) => {
type = 'WHAT';
conv.ask('Sure! What do you want me to help with');
})
app.intent('com.example.test.HOW', (conv, input, arg) => {
type = 'WHAT';
conv.ask('Sure! How do you want me to help with');
})
我認為這不是理想的解決方案,因為當多個設備使用我的履行服務器時,它將引起問題。 是有可能這樣做詢問和目的相同功能使用的用戶響應內,而不是去actions.intent.TEXT
與conv.ask
?
使用actions.json文件中的意圖有兩個原因:
為歡迎意圖和深層鏈接短語設置模式。
在稍后的會話中調整可能的用戶響應。
但是,在情況(2)中,該意圖仍然報告為actions.intent.TEXT
。 您將永遠不會使用Action SDK向您報告已定義的其他意圖。 因此它將永遠不會發送com.example.test.WHAT
或HOW
意圖。
如果您使用自己的自然語言處理(NLP)系統-只是用戶發送的文本,這正是您想要的。
如果您想要為您執行NLP處理並管理狀態的設備,則不妨查看Dialogflow之類的東西。 Dialogflow允許您設置將與意圖匹配的短語,並在您的Webhook實現中將匹配的意圖以及用戶所說的參數發送給您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.