0

我正在使用 Jovo Node.js 框架为 Amazon Alexa 和 Google Assistant 平台编写语音优先应用程序。我向外部 API 发出嵌套的 http 请求(第一个调用是获取作为第二个 API 调用的参数所需的资源 ID)。数据返回后,我想向应用程序的用户发送响应。但是,我在测试期间根本没有得到任何回应。

我尝试从同一个 .then() 内部发送响应,我从 API 获取数据并制定响应,我还尝试简单地在一个对象中返回该响应并将另一个 .then() 链接到在我尝试发送响应的地方处理该承诺。这些选项都不起作用。

我在请求处理程序中 console.logged “this”,然后在 .then() 处理第一个 API 调用,在 .then() 处理第二个 API 调用(只是为了确保上下文相同)和它是同一个“这个”。

console.logging 从 API 接收的数据也有效,所以我知道我收到了 API 的响应。我只是无法向用户发送回复。

下面是我的代码:

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.');
});
4

0 回答 0