我正在使用Jovo Node.js框架为Amazon Alexa和Google Assistant平台编写语音优先应用程序。我向外部API发出了嵌套的http请求(第一个调用是获取所需的资源ID,作为第二个API调用的参数)。数据返回后,我想向应用程序的用户发送响应。但是,在测试过程中我什么也没收到。
我尝试从相同的.then()内部发送响应,从API中获取数据并制定响应,还尝试了简单地在一个对象中返回该响应并链接另一个.then ()处理该诺言,然后尝试发送响应。这些选项都不起作用。
我在请求处理程序中将console.log记录为“ this”,然后在.then()内部处理第一个API调用,然后在.then()内部处理第二个API调用(以确保上下文相同) )和相同的“ this”。
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.');
});