【发布时间】:2017-08-07 18:02:22
【问题描述】:
我正在使用 Facebook Messenger API 创建一个非常基本的聊天机器人。我希望能够在单个气泡中发送一系列消息。但是,当我在同一个函数中多次调用 API 时。我不能确定哪条消息会先显示。如何使用 async/await 功能正确排序消息?
最初的函数调用:
const getStartedProcess = async(formattedText,senderID) => {
const firstMessage = await sendTextMessage(senderID,"First message");
const secondMessage = await sendTextMessage(senderID,"Second message");
const thirdMessage = await sendTextMessage(senderID,"Third message");
}
助手:
const sendTextMessage = async(recipientId, messageText) => {
//format message correctly
const sent = await callSendAPI(messageData);
return 0;
}
const callSendAPI = async(messageData) =>{
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: { access_token: PAGE_ACCESS_TOKEN },
method: 'POST',
json: messageData
}, function (error, response, body) {
//Proccess
return 0;
});
}
【问题讨论】:
标签: javascript node.js facebook async-await messenger