Actions Sdk get this error TypeError: Cannot read property 'output' of undefined

I'm trying to connect IBM Watson and Google Assistant, but I keep receiving this error "TypeError: Cannot read property 'output' of undefined" and this "Function execution took 3323 ms, finished with status: 'crash'"

This is my code:

const {actionssdk} = require('actions-on-google');
const functions = require('firebase-functions');

const app = actionssdk({debug: true});

app.intent('actions.intent.MAIN', (conv) => {
    conv.ask('Olá, como posso lhe ajudar?');
});


app.intent('actions.intent.TEXT', (conv, input) => {
    var AssistantV1 = require('watson-developer-cloud/assistant/v1');
    var assistant = new AssistantV1({
        username: '###################################',
        password: '###################################',
        url: '###################################',
        version: '2018-07-10'
    });
    conv.ask("eeeeeeeeeeeeeeeee");
    return new Promise( (resolve, reject) => {
        assistant.message(
        {
          workspace_id: '###################################',
            input: { text: input },
            headers: {'Content-Type':'application/json'}
        },
        function(err, response) {
            conv.ask(response.output.text[0]);
            resolve();
        }
        );
     })
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Answers:

Answer

Rebeca, just to adding information, you are trying to add some outbound access, but you need to configure your account to do that.

"Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions"

If you wanted to call some API (IBM Watson, as verified) you'd need to enable billing.

For the other quotas, take a look here to see prices - as you can see there are limits to the number of invocations using free tier.

Answer

Your responseobject is null. Check it is not equal to null before to use it:

let speech;
if (response !== null) {
    speech = response.output.text[0];
}
else{
    speech = "I'm sorry, there was an error and I'm unable to answer";
}
conv.ask(speech);

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.