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?