我正在为我的Facebook页面设置一个Chatbot,Google Dialogflow处理对话。
对于特定的Intent,我需要发送2个响应。
我理解,对于单个Intent,我无法通过Fulfillment代码发送第一个响应,并通过Dialogflow控制台UI发送第二个响应。因此,我需要编写代码来发送两个响应。
我能够发送第一个响应。但无法发送Rich消息内容。 DialogFlow文档显示了代码片段,但不清楚不同页面的代码片段是如何适合它的。
这是我的代码(只是发布actionHandlers),试图发送一个语句和一个音频(https://dialogflow.com/docs/rich-messages#custom_payload)
const actionHandlers = {
'input.welcome': () => {
const speechText = 'Hi ' + userProfile['first_name'] + ', This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I\'d like to help you with your needs 😃';
const responsePayload = {
'speech': speechText,
'outputContexts': [{
'user-name': userProfile.first_name
}],
"data": {
"facebook": {
"attachment": {
"type": "audio",
"payload": {
"url": "http://incompetech.com/music/royalty-free/mp3-royaltyfree/Funk%20Game%20Loop.mp3"
}
}
}
}
};
sendResponse(responsePayload);
},
// The default fallback intent has been matched, try to recover (https://dialogflow.com/docs/intents#fallback_intents)
'input.unknown': () => {
sendResponse('I\'m having trouble, can you try that again?'); // Send simple response to user
}
};
文本响应正在起作用,但Audio
不是。我做得对吗?任何帮助赞赏。
更新1:更改mp3链接后,音频正在运行。但是文本响应不起作用。
在我的Cloud函数中发送到response.json()
的对象的日志。
{
"speech": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃",
"displayText": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃",
"data": {
"facebook": {
"attachment": {
"type": "audio",
"payload": {
"url": "http://66.90.93.122/ost/death-note-original-soundtrack/bowkqzxs/01%20Death%20note.mp3"
}
}
}
},
"contextOut": [{
"user-name": "Saiyasodharan"
}]
}
在上面的代码中,我期待
displayText
立即显示 - >哪个不起作用audio
响应发生 - >现在正在改变mp3链接我相信我需要通过data
属性给出文本响应和音频响应。让我试试这里更新。
如果对给定的集成使用有效负载,则将忽略响应的文本。您需要将带有text
属性的消息添加到facebook
有效负载中,以便在Facebook Messenger中显示它。例如:
{
"contextOut": [
{
"user-name": "Saiyasodharan"
}
],
"data": {
"facebook": {
"attachment": {
"payload": {
"url": "http://66.90.93.122/ost/death-note-original-soundtrack/bowkqzxs/01%20Death%20note.mp3"
},
"type": "audio"
},
"text": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃"
}
},
"displayText": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃",
"speech": "Hi Saiyasodharan, This is Eva, digital assistant of LMES Academy. Since my people are busy working on the content for the next video, I'd like to help you with your needs 😃"
}