Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
How to use request callback with node.js in google actions?

Right now I'm using the Google Actions console to create a simple action that fetches the summary of a random Wikipedia article.

Here's the node.js:

const { conversation } = require('@assistant/conversation');
const functions = require('firebase-functions');
const request = require('request');
const app = conversation();
var http = require('http');

function getWiki(callback) {
  request('https://en.wikipedia.org/api/rest_v1/page/random/summary', function (error, response, body) {
    if (!error && response.statusCode == 200) {
      dataObj = JSON.parse(body);
      title = dataObj.title;
      summary = dataObj.extract;
      speech = `${title}. ${summary}`;
      return callback(result, false);
    } else {
      return callback(null, error);
    }
  });
}

app.handle('wiki_random', conv => {
  getWiki();
  conv.add(speech);
});

exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);

Under the app.handle fucntion I'm having trouble getting it to wait for the getWiki function to complete before executing the conv.add(speech). How do I go about implementing my callback into the app.handle function?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!