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

Node.js app reading chached json value

I have recently started making a node.js app and have gotten to a point at which I need to read a value of a JSON that has just been updated, but not successfully, I have tried using the ‘sleep’ module to stop threads for a small delay but still no luck.

I haven’t been using node.js for very long either, for only about 5 months.

-Thank you in advance


Source: stackoverflow-javascript

request to Random Word SetGetGo API

I’m trying to get words from this website: http://setgetgo.com/randomword/get.php
How do I create a request to this API? Is there something that i’m missing?

var bot = new Discord.Client(); //new instance of discord client

bot.on("ready", () => {
    console.log("online");
});


var prefix = "!~"
bot.on("message", message => { //when we recieve a message, we'll run this
    if(message.author === bot.user) return;
    if(message.content.startsWith(prefix + "start")){
        message.channel.sendMessage(RandomWord());
    }
});

function RandomWord() {
var requestStr = "http://randomword.setgetgo.com/get.php";

$.ajax({
    type: "GET",
    url: requestStr,
    dataType: "jsonp",
    jsonpCallback: 'RandomWordComplete'
});
}

function RandomWordComplete(data) {
     alert(data.Word);
}


Source: stackoverflow-javascript

Write json file to Firebase with Node.js?

I have a third party API that I need to call every 5 seconds. I get JSON as response, and I’d like to write the JSON content to a Firebase node using Node.js. Based on Firebase examples I could import data with this code:

var usersRef = ref.child("users");
usersRef.set({
  alanisawesome: {
    date_of_birth: "June 23, 1912",
    full_name: "Alan Turing"
  },
  gracehop: {
    date_of_birth: "December 9, 1906",
    full_name: "Grace Hopper"
  }
});

Curl examples worked too. But what I really wanted to do is to import a third party API response directly to my Firebase database using the API endpoint. How can i do it with Node.js?


Source: stackoverflow-javascript

Protractor: Print off first five <li> entries contained inside <ul> element

I have a <ul> div that contains various <li> entries. I would like, to print off just the first five <li> elements and also would like to print them off individually if possible.

This is the css

<ul class="legend-numbers">
<li>-</li>
<li>-</li>
<li>-</li>
<li>58,983.58</li>
<li>127,4563.09</li>
<li>450,918.28</li>
<li>246,833.09</li>
<li>550,953.58</li>
<li>277,733.09</li>i>
<!--anchor-->
			</ul>

And this how I’m trying to tackle this in my page object file

checkFigures (figures) {
	browser.sleep(8000);
   	var balance = element.all(by.css('ul.legend-numbers> li'));
	var cellTexts = balance.map(function (elm) {
    	return elm.getText().then(function (text) {
      	console.log(text);
		});
	    });
	}
 }

I’m not really sure how I only get the first five entries or how I can choose to print off the second <li> element or third <li> element etc. I’ve tried to use indexOf() or .getFirst() but I get errors when I try to do so.
Thanks


Source: stackoverflow-javascript

Expressjs, Handlebars(hbs), express-messages, flash-connect. Not able to render flash messages

I’m doing an express app and I’d like to show flash messages when a user registers using a form.

The technologies that I’m using are Node.js, Express.js, Handlebars(hbs), connect-flash and express-messages.

In order to be easier to find the error, I’ve created a new app in the simplest way that I could.

The error is:
Error: /Applications/MAMP/htdocs/hbs-simple/views/index.hbs: Parse error on line 7:
...</head><body> {{{messages()}}} {{{b
---------------------^
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'

Project structure:

├── app.js
├── package.json
└── _views
    ├── index.hbs
    ├── layout.hbs
    └── test.hbs

app.js:

const express = require('express');
const app = express();
const path = require('path');
const session = require('express-session');
const flash = require('connect-flash');
const hbs = require('hbs');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

app.use(require('connect-flash')());
app.use((req, res, next) => {
  res.locals.messages = require('express-messages')(req, res);
  next();
});

// Handle Sessions
app.use(session({
  secret: 'secret',
  saveUninitialized: true,
  resave: true
}));

app.get('/', (req, res, next) => {
  req.flash('success', 'Rendering index...');
  res.render('index');
});

app.get('/test', (req, res, next) => {
  req.flash('success', 'Rendering test...');
  res.render('test');
});

app.listen(3000, function () {
  console.log('Listening on port 3000!');
});

layout.hbs

<!DOCTYPE html>
<html>
<head>
  <title>{{title}}</title>
</head>
<body>
  {{{messages()}}}
  {{{body}}}
  <a href="/">index</a>
  <a href="/test">test</a>
</body>
</html>

index.hbs

<h3>This is the index</h3>

test.hbs

<h3>This is the index</h3>

package.json

{
  "name": "hbs-simple",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "author": "Rafa",
  "license": "ISC",
  "dependencies": {
    "connect-flash": "^0.1.1",
    "express": "^4.15.3",
    "express-messages": "^1.0.1",
    "express-session": "^1.15.3",
    "hbs": "^4.0.1",
    "path": "^0.12.7"
  }
}

This is from the express-messages documentation that you can find on [https://github.com/expressjs/express-messages][1]

Rendering Messages

Call the messages() function as specified by your rendering engine:

EJS:

<%- messages() %>
Jade:

!= messages()

Which using hbs should be {{{messages}}} , but this doesnt work as I expected.

Any ideas or any solution for this situation.

Thanks a lot!


Source: stackoverflow-javascript

Using promises with streams in node.js

I’ve refactored a simple utility to use promises. It fetches a pdf from the web and saves it to disk. It should then open the file in a pdf viewer once saved to disk. The file appears on disk and is valid, the shell command opens the OSX Preview application, but a dialog pops up complaining that the file is empty.

What’s the best way to execute the shell function once the filestream has been written to disk?

// download a pdf and save to disk
// open pdf in osx preview for example
download_pdf()
  .then(function(path) {
    shell.exec('open ' + path).code !== 0);
  });

function download_pdf() {
  const path = '/local/some.pdf';
  const url = 'http://somewebsite/some.pdf';
  const stream = request(url);
  const write = stream.pipe(fs.createWriteStream(path))
  return streamToPromise(stream);
}

function streamToPromise(stream) {
  return new Promise(function(resolve, reject) {
    // resolve with location of saved file
    stream.on("end", resolve(stream.dests[0].path));
    stream.on("error", reject);
  })
}


Source: stackoverflow-javascript