Muhammad Naufil
Muhammad Naufil

Reputation: 2637

How to play an audio file on dialogflow using firebase function

I have my own server where audio file is uploaded. www.theislam360.me:8080/hbd.mp3 I want to play this audio on google home using firebase functions.

const functions = require('firebase-functions');
var request1 = require('request')
exports.webhook = functions.https.onRequest((request, response) => {

        console.log("request.body.result.parameters: ", request.body.result.parameters);

        let params = request.body.result.parameters;

        var options = {
            url: `https://theislam360.me/${params.any}`+".mp3",
            json:true
        }
        request1(options, function(error, res, body){
            if(error) response.send({speech: "error in API call"});
            else response.send({speech: "<speak>This is the audio <audio>www.theislam360.me:8080/hbd.mp3</audio></speak>"});
        });
    });

I am getting Internal server error on dialogflow fulfillment. Here is the firebase logs. enter image description here

Upvotes: 3

Views: 349

Answers (2)

Muhammad Naufil
Muhammad Naufil

Reputation: 2637

It was as simple as this

const functions = require('firebase-functions');

exports.webhook = functions.https.onRequest((request, response) => {
    response.send({speech:`<speak>Welcome to my action! <audio src="https://theislam360.me:8080/hbd.mp3"></audio> How can I help you?</speak>`})
});

Note that the server should be https, the audio file is stored in.

Upvotes: 2

Anton Eriksson
Anton Eriksson

Reputation: 169

The error

Cannot read property "parameters" of undefined

is telling you that request.body.result is undefined which means that there is no property named "result" on the request.body object. Try double checking that the parameters you are looking for is indeed in the request.body.result object.

Upvotes: 2

Related Questions