0

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.');
});
Milan
  • 1,433
  • 12
  • 15
  • 1
    Just going though jovo SDK online, and first thing I wonder is are you getting anything back on the Alex, i.e. have you tried `this.say(res.speech);`instead of `this.ask(res.speech, res.reprompt);` to see if you are getting anything back on Alexa – Milan Mar 09 '19 at 16:00
  • 1
    Aslo Jovo have you tried running this locally using Jovo Webhook: https://www.jovo.tech/tutorials/alexa-skill-tutorial-nodejs#local-prototyping-with-the-jovo-webhook – Milan Mar 09 '19 at 16:01
  • Yes, I've been testing locally with my Jovo webhook. No response comes back from Alexa. There is just silence until it times out and ends the session. – Kevin Glick Mar 09 '19 at 16:54
  • 1
    Is there a reason you are `then`ing rather than `async/await`ing? – Wiktor Zychla Mar 09 '19 at 21:24
  • @Wiktor Zychla This doesn't seem to be working for me either, but I might be doing it wrong: `await meetup.GetMeetupEventId(city).then(async (details) => { res = await meetup.GetMeetupEventDetails(details.urlname, details.next_event.id).catch((err) => { console.log("Couldn't fetch Event Details"); }); this.ask(res.speech, res.reprompt); }).catch((err) => { console.log("Couldn't Fetch Event ID"); });` – Kevin Glick Mar 09 '19 at 22:25
  • 1
    This looks like a partial refactoring. You still have `then` here. The code would be much cleaner and easier to debug if you refactor all the old style of thens to async/await. In particular, start with `var details = await meetup.GetMeetupEventId(city)` and then continue in the same manner. Debug the result. – Wiktor Zychla Mar 11 '19 at 18:22
  • @WiktorZychla I refactored to use async/await. I've got the code working now. Thanks very much! I'll post the code snippet shortly. – Kevin Glick Mar 14 '19 at 15:06

0 Answers0