Below is my code where I parsed a json file and used in a loop to "for" loop in order to print it out onto a console
process.env.DEBUG = 'actions-on-google:*';
const apikey = "xxxxxx";
const https = require('https');
const ActionsSdkApp = require("actions-on-google");
const DialogflowApp = require('actions-on-google').DialogflowApp;
const app = new ActionsSdkApp({request, response});
//ActionsSdkApp({request, response} vs DialogflowApp({ request: req, response: res })?????? which one do I use????
function responseHandler(app) {
var topic = app.getArgument('topic');
https.get(`https://example.com/${topic}?apiKey=${apikey}`, (res) => {
let body = "";
res.on('data', data => {
console.log('Reading Data');
body += data.toString();
});
res.on('end', () => {
try {
const profile = JSON.parse(body);
for(let i = 0; i<profile.data.length;i++) {
console.log(" description: " + profile.data[i].description + " title: " + profile.data[i].title + ); // in the json file there are vales called "description" and "title" that I want on my list
}} catch (e) {
app.ask("Sorry, I was unable to load information. Please repeat the search term.");
console.error("error: " + e.message);
}
});
})
}
I'm following the example on actions by google documentation and I'm trying to create a list with all the json objects in my json file but I'm having difficulty. Below is my attempt at it:
function list () {
const app = new ActionsSdkApp({request, response});
app.askWithList('Here are a few things I found. Pick one that looks interesting',
app.buildList('Things to learn about')
// i want add my loop here....but I how would I add it probably?? for(let i = 0; i<profile.data.length;i++)
.addItems
.setTitle(" title: " + profile.data[i].title)
.setDescription(" description: " + profile.data[i].description)
);
};
Can anyone offer any advice to help me build the list? Also, do I import the actionsdk library or the dialogflow library?