Jovo Node.js フレームワークを使用して、Amazon Alexa および Google Assistant プラットフォーム用の音声優先アプリケーションを作成しています。外部 API に対してネストされた http 要求を作成します (最初の呼び出しは、2 番目の API 呼び出しのパラメーターとして必要なリソース ID を取得するためのものです)。データが返ってきたら、アプリのユーザーに応答を送信したいと考えています。ただし、テスト中にまったく応答がありません。
APIからデータを取得して応答を作成している同じ.then()内から応答を送信しようとしました。また、単にその応答をオブジェクトで返し、別の.then()を連鎖させてみましたその約束を処理してから、応答を送信しようとします。これらのオプションはどちらも機能しません。
リクエストハンドラーで「これ」をconsole.loggedし、次に最初のAPI呼び出しを処理する.then()内で、2番目のAPI呼び出しを処理する.then()で(コンテキストが同じであることを確認するため)、それを「これ」と同じでした。
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.');
});