I'm writing a voice-first application for the Amazon Alexa and Google Assistant platforms using the Jovo Node.js framework. I make nested http requests to an external API (the first call is to get a resource id needed as a parameter for the second API call). Once the data returns, I want to send a response to the user of the app. However, I'm not getting any response at all during tests.
I have tried sending the response from inside the same .then() where I'm getting the data back from the API and formulating a response, I've also tried simply returning that response in an object and chaining another .then() to handle that promise where I then attempt to send the response. Neither of those options works.
I console.logged "this" in the request handler, then inside the .then() handling the first API call, and in the .then() handling the second API call (just to make sure the context was the same) and it was the same "this".
console.logging the data received from the API also works, so I know I'm getting a response from the API. I'm just having trouble sending a response to the user.
Below is my code:
meetup.GetMeetupGroup(city).then((details) => {
const id = details.next_event.id;
console.log(id); // This works
meetup.GetMeetupEvent(city, id).then((event) => {
let response = {};
response.speech = `<speak>The next learn to code meetup is ${event.name}.
It will be held on <say-as interpret-as="date">${event.local_date}</say-as>
at ${event.local_time} at ${event.venue.name}, which is located at
<say-as interpret-as="address">${event.venue.address_1}</say-as>. ${event.plain_text_description}.
Would you like to <say-as interpret-as="characters">RSVP</say-as>?</speak>`;
response.reprompt = `<speak>The next ${city} meetup will be on
<say-as interpret-as="date">${event.local_date}</say-as>
at ${event.local_time} at ${event.venue.name},
<say-as interpret-as="address">${event.venue.address_1}</say-as>.
Do you want to go?</speak>`;
console.log(response); // This works
return response;
}).then((res) => {
console.log(res); // This works
this.ask(res.speech, res.reprompt); // Here is where I'm attempting to send a response
});
}).catch((error) => {
console.log('Meetup API Error');
console.log(error);
this.tell('Sorry, your request could not be completed at this time.');
});