0

我正在使用此代码从 Node.JS Dialogflow CX webhook 发回文本响应。我想播放音频作为履行,所以我想发回该音频的链接。

如何发回音频文件链接?

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);
});
4

1 回答 1

1

To utilize your audio URI, you must add it to your ‘jsonResponse’. You will need to layer it to your webhookResponse in via the following fields: jsonResponse.fulfillment_response.messages.play_audio

‘play_audio’ will specify the audio clip URI that will be played. This URI must be a public URI.

For example (PlayAudio):

jsonResponse = { 
    fulfillment_response: { 
        messages: [{ 
            play_audio: { 
                audio_uri: `https://URI.EXAMPLE.WAV`
            } 
        }] 
    } 
};

Please note that these audio responses currently only work with Dialogflow’s Telephony integrations such as Avaya or AudioCodes, or with a custom integration you can create yourself using the APIs and Client Libraries. Not all audio files work for Avaya and AudioCodes, so I recommend using .WAV files as they work with both.

If you are using a custom integration, you can create your own implementation to support your preferred audio format.

于 2020-12-18T21:51:25.647 回答