How to disable too many logs of actions-on-google – api.ai

this code is giving me un expected logs, my question is how can i remove these logs then it will be easy for me to point out my own developer log

here is my code:

process.env.DEBUG = 'actions-on-google:*';
import * as admin from 'firebase-admin';
const Assistant = require('actions-on-google').ApiAiAssistant;
import * as functions from 'firebase-functions';
import data from './../../db/index';
import { Request, Response } from "express";
import * as functionRequest from 'request';

// API.AI Action names
const SUBMIT_REPORT = 'submitReport';
const NEXT_QUESTION = 'next_question';

export const webhook = functions.https.onRequest(async (request: Request, response: Response) => {
    const assistant = new Assistant({ request: request, response: response });

    let actionMap = new Map();

    actionMap.set(SUBMIT_REPORT, submitReport);
    actionMap.set(NEXT_QUESTION, next_question);

    assistant.handleRequest(actionMap);

    function submitReport(assistant: any) {

        console.info("user ask for submit report, request body: ", request.body);

        let dataRef = request.body.originalRequest.data.user;
        let userData = {
            groupId: dataRef.groupId,
            subgroupId: dataRef.subgroupId,
            userId: dataRef.userId
        }
        //console.log("userdata: ", userData)
        let botRef = data.db.ref('subgroup-bot-chat-mode/' + userData.groupId + '/' + userData.subgroupId + '/' + userData.userId)
        botRef
            .once('value', function (snapshot) {
                let data = snapshot.val()
                //console.log("here is recieved data: ", data)
                if (data == null) {
                    let entry = {
                        'userAgreed': true,
                        'askedForReport': true,
                        'timestamp': admin.database.ServerValue.TIMESTAMP,
                        'reportIndex': 0,

                    }
                    botRef
                        .set(entry, function (error) {
                            if (!error) {
                                //console.log("Data save successfully at subgroup-bot-chat-mode/")

                                // start asking questions
                                const fullfillment = {
                                    "speech": "qedfqwedf",
                                    "followupEvent": {
                                        "name": "ESOX_WRITE_STANDUP_REPORT_NOW"
                                    },
                                    "contextOut": [
                                        {
                                            "name": "quiz",
                                            "lifespan": 5,
                                            "parameters": {
                                                "index": "0"
                                            }
                                        },
                                        {
                                            "name": "sendReportNow-followup",
                                            "lifespan": 5,
                                        },
                                    ]
                                }
                                response.send(fullfillment);
                                return;
                            }
                        }).catch((e) => {
                            console.error("1. an error occured when getting data from db");
                            response.send({
                                speech: "error on db"
                            })
                            return;
                        })

                } else {
                    response.send({
                        speech: "already"
                    })
                    return;
                }
            }).catch((e) => {
                console.error("2. an error occured when getting data from db");
                response.send({
                    speech: "error on db"
                })
                return;

            })

    }
    function next_question(assistant: any) {

        let dataRef = request.body.originalRequest.data.user;
        let userData = {
            groupId: dataRef.groupId,
            subgroupId: dataRef.subgroupId,
            userId: dataRef.userId
        }

        let questionIndex = request.body.result.contexts[0].parameters.index;
        console.log("index: ", questionIndex);

        // if question index == 0 it means it is first time, we will send first question to user
        // if question index > 0 it means it means user is answered th index
        if (questionIndex == 0) {
            console.log("going to send first question");
        } else if (questionIndex > 0) {
            //todo: process answer here
            console.log("answer: ", request.body.result.parameters.answer);
            let answer = request.body.result.parameters.answer;


            // data.db.ref('subgroup-progress-reports/' + userData.groupId + '/' + userData.subgroupId + '/' + userData.userId + '/' + reportId + '/answers/' + reportIndex)
            //     .set(answer)


        }


        // start asking questions
        functionRequest({
            url: 'https://us-central1-luminous-torch-4640.cloudfunctions.net/getReportQuestions',
            method: 'POST',
            json: {
                'groupId': userData.groupId,
                'subgroupId': userData.subgroupId,
                'userId': userData.userId
            }
        }, function (error, res, body) {
            if (!error && response.statusCode == 200) {
                //console.log("hello: ", res.body)
                switch (res.body.status) {

                    case 'EOF':
                        response.send({
                            "speech": "EOF",
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 0
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 0,
                                }
                            ]
                        })
                        break;

                    case 'OK':
                        //sending question back
                        let botRef = data.db.ref('subgroup-bot-chat-mode/' + userData.groupId + '/' + userData.subgroupId + '/' + userData.userId)
                            .update({
                                reportIndex: res.body.reportIndex,
                                reportId: res.body.reportId
                            })

                        response.send({
                            "speech": res.body.question,
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 5,
                                    "parameters": {
                                        "index": res.body.reportIndex,
                                        "reportId": res.body.reportId
                                    }
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 5,
                                }
                            ]
                        })

                        break;
                    case 'ALREADY_ASKED_FOR_TODAY':
                        response.send({
                            "speech": "you are already submited the report for today",
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 0
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 0,
                                }
                            ]
                        })
                        break;
                    default:
                        console.error("Unknown case");
                        //http request failed
                        response.send({
                            "speech": "Something went wront on question server",
                            "contextOut": [
                                {
                                    "name": "quiz",
                                    "lifespan": 0
                                },
                                {
                                    "name": "sendReportNow-followup",
                                    "lifespan": 0,
                                }
                            ]
                        })
                        return;
                }
            } else {
                //http request failed
                response.send({
                    "speech": "Something went wront on question server",
                    "contextOut": [
                        {
                            "name": "quiz",
                            "lifespan": 0
                        },
                        {
                            "name": "sendReportNow-followup",
                            "lifespan": 0,
                        }
                    ]
                })
            }
        })
    }

})//end of webhook http trigger

logs of firebase functions are here:

2:10:34.707 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug map of intents
2:10:34.707 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug name=next_question 2:10:34.707 PM info
webhook Sat, 05 Aug 2017 09:10:34 GMT actions-on-google:debug key is
id 2:10:34.706 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug name=submitReport 2:10:34.706 PM info webhook
Sat, 05 Aug 2017 09:10:34 GMT actions-on-google:debug key is id
2:10:34.706 PM info webhook Sat, 05 Aug 2017 09:10:34 GMT
actions-on-google:debug invokeIntentHandler_: handler=[object Map],
intent=next_question


Source: stackoverflow-javascript

Leave a Reply

Your email address will not be published. Required fields are marked *