Dialogflow es 如何从Dialogflow CX webhook发回音频?
我使用这段代码从Node.JS Dialogflow CX webhook发回文本响应。我想播放一段音频,以便将指向该音频的链接发送回 如何发回音频文件链接Dialogflow es 如何从Dialogflow CX webhook发回音频?,dialogflow-es,dialogflow-es-fulfillment,dialogflow-cx,Dialogflow Es,Dialogflow Es Fulfillment,Dialogflow Cx,我使用这段代码从Node.JS Dialogflow CX webhook发回文本响应。我想播放一段音频,以便将指向该音频的链接发送回 如何发回音频文件链接 const express = require("express"); const app = express(); const bodyParser = require("body-parser"); app.use(bodyParser.json()); app.use(bodyParser.u
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.post("/webhook", (request, response) => {
let tag = request.body.fulfillmentInfo.tag;
let jsonResponse = {};
if (tag == "hello") {
//fulfillment response to be sent to the agent if the request tag is equal to "welcome tag"
jsonResponse = {
fulfillment_response: {
messages: [{
text: {
//fulfillment text response to be sent to the agent
text: ["Hi! This is a webhook response"]
}
}]
}
};
} else {
jsonResponse = {
//fulfillment text response to be sent to the agent if there are no defined responses for the specified tag
fulfillment_response: {
messages: [{
text: {
////fulfillment text response to be sent to the agent
text: [
`There are no fulfillment responses defined for "${tag}"" tag`
]
}
}]
}
};
}
response.json(jsonResponse);
});
const listener = app.listen(3000, () => {
console.log("Your app is listening on port " + listener.address().port);
});
要利用音频URI,必须将其添加到“jsonResponse”中。您需要通过以下字段将其分层到webhookResponse中:jsonResponse.fulfillment\u response.messages “play_audio”将指定要播放的音频剪辑URI。此URI必须是公共URI 例如(播放音频): 请注意,这些音频响应目前仅适用于Dialogflow,如Avaya或AudioCodes,或者您可以使用创建自己的自定义集成。并非所有音频文件都适用于Avaya和AudioCodes,因此我建议使用.WAV文件,因为它们同时适用于两者 如果您使用的是自定义集成,则可以创建自己的实现以支持首选音频格式
jsonResponse = {
fulfillment_response: {
messages: [{
play_audio: {
audio_uri: `https://URI.EXAMPLE.WAV`
}
}]
}
};