ReferenceError: conv is not defined in actions-on-google

*爱你&永不变心* 提交于 2019-12-12 23:28:34

问题


I want to implement Suggestions chips in my Dialog flow (to be use in Google Assistant)..But I am getting this error

"ReferenceError: conv is not defined"

which i didn't understand.I have go through the official docs but what am i missing? I have also added actions_intent_OPTION in his Event

following is my code

const functions = require('firebase-functions');
const {actionssdk} = require('actions-on-google');
const app = actionssdk({debug: true});
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var firestore = admin.firestore();

exports.webhook = functions.https.onRequest((request, response) => {
    switch (request.body.result.action) {
           case 'countitem':

            firestore.collection('orders').get()
                .then((querySnapshot) => {

                    var orders = [];
                    querySnapshot.forEach((doc) => { orders.push(doc.data()) });
                    // now orders have something like this [ {...}, {...}, {...} ]

                    response.send({
                        speech: `you have ${orders.length} orders11, would you like to see them? (yes/no)`
                    });
                })
                .catch((err) => {
                    console.log('Error getting documents', err);

                    response.send({
                        speech: "something went wrong when reading from database"
                    })
                })
            conv.ask(new Suggestions('Suggestion Chips'));
            conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));         

            break;

        default:
            response.send({
                speech: "no action matched in webhook"
            })
    }
});

回答1:


The issue is that conv isn't defined. Typically, if you're using the actions-on-google library, conv is passed to your fulfillment function and contains methods you can use to set replies and so forth.

It looks like you're handling everything yourself and generating the JSON response manually. If so, you should consult the guide for using JSON as part of your webhook and the repository of JSON examples.



来源:https://stackoverflow.com/questions/51192662/referenceerror-conv-is-not-defined-in-actions-on-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!