Я работаю с API-интерфейсом Facebook Messenger Bot, и я тестирую свой игровой сервер Node.js с Heroku с моей учетной записью Facebook (admin) и фиктивной учетной записью Facebook, которая добавлена как тестер. Каждый раз, когда я отправляю сообщение в ChatBot, Chatbot может ответить мне. Но когда я проверяю журнал Heroku, я узнал, что бот отправляет два сообщения за одно сообщение, которое он получил. Я получил только один ответ от бота, но почему есть второе сообщение, отправленное ботом?Facebook Messenger Bot API отправляет несколько сообщений и показывает ошибку
Это код как пост веб-крюком и функции SendMessage
app.post('/webhook', function (req, res) {
var events = req.body.entry[0].messaging;
for (i = 0; i < events.length; i++) {
var event = events[i];
var sender = event.sender.id
if (event.message && event.message.text) {
sendMessage(sender, {text: "Hey, did you just say: " + event.message.text});
console.log("sent message to: " + sender);
}
}
res.sendStatus(200);
});
function sendMessage(recipientId, message) {
request({
url: 'https://graph.facebook.com/v2.6/me/messages',
qs: {access_token: process.env.PAGE_ACCESS_TOKEN},
method: 'POST',
json: {
recipient: {id: recipientId},
message: message,
}
}, function(error, response, body) {
if (error) {
console.log('Error sending message: ', error);
} else if (response.body.error) {
console.log('Error: ', response.body.error);
}
});
};
Это журнал, когда я построил свой Chatbot приложение в Heroku и я послал сообщение от моего аккаунта администратора
2016-08-25T21:16:02.303705+00:00 heroku[web.1]: Restarting
2016-08-25T21:16:02.304448+00:00 heroku[web.1]: State changed from up to starting
2016-08-25T21:16:03.588649+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-08-25T21:16:05.731964+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-08-25T21:16:06.609304+00:00 heroku[web.1]: Process exited with status 143
2016-08-25T21:16:07.266798+00:00 heroku[web.1]: State changed from starting to up
2016-08-25T21:16:39.746253+00:00 app[web.1]: sent message to: 1160285130676682
2016-08-25T21:16:40.082592+00:00 app[web.1]: sent message to: 284635001929051
2016-08-25T21:16:40.206265+00:00 app[web.1]: Error: { message: '(#100) No matching user found',
2016-08-25T21:16:40.206267+00:00 app[web.1]: type: 'OAuthException',
2016-08-25T21:16:40.206268+00:00 app[web.1]: code: 100,
2016-08-25T21:16:40.206268+00:00 app[web.1]: fbtrace_id: 'BSxdusFbWB6' }
2016-08-25T21:16:39.756640+00:00 heroku[router]: at=info method=POST path="/webhook" host=warm-depths-81393.herokuapp.com request_id=7035f788-f103-49d7-99ec-21cf58d30674 fwd="69.63.188.113" dyno=web.1 connect=1ms service=66ms status=200 bytes=196
2016-08-25T21:16:40.265285+00:00 heroku[router]: at=info method=POST path="/webhook" host=warm-depths-81393.herokuapp.com request_id=71deb2ab-f1db-40cc-a5d1-af926a35b6de fwd="173.252.120.112" dyno=web.1 connect=0ms service=8ms status=200 bytes=196
2016-08-25T21:16:40.084913+00:00 heroku[router]: at=info method=POST path="/webhook" host=warm-depths-81393.herokuapp.com request_id=61be8207-456c-4337-8c2b-ced6ff742f52 fwd="66.220.158.102" dyno=web.1 connect=0ms service=7ms status=200 bytes=196
Это вторая часть журнала, который показывает, что я послал еще одно сообщение от моего фиктивного счета (тестер)
2016-08-25T21:16:44.788335+00:00 app[web.1]: sent message to: 1107394752663896
2016-08-25T21:16:45.195498+00:00 app[web.1]: sent message to: 284635001929051
2016-08-25T21:16:45.307382+00:00 app[web.1]: Error: { message: '(#100) No matching user found',
2016-08-25T21:16:45.307384+00:00 app[web.1]: type: 'OAuthException',
2016-08-25T21:16:45.307385+00:00 app[web.1]: code: 100,
2016-08-25T21:16:45.307385+00:00 app[web.1]: fbtrace_id: 'GKqZtMZawEv' }
2016-08-25T21:16:45.194037+00:00 heroku[router]: at=info method=POST path="/webhook" host=warm-depths-81393.herokuapp.com request_id=fce94f53-bd7e-4020-a0b0-ff05638e0b25 fwd="173.252.120.121" dyno=web.1 connect=0ms service=12ms status=200 bytes=196
2016-08-25T21:16:44.786566+00:00 heroku[router]: at=info method=POST path="/webhook" host=warm-depths-81393.herokuapp.com request_id=3d650955-c9db-47c2-8b69-b919e70bb94e fwd="173.252.120.100" dyno=web.1 connect=2ms service=4ms status=200 bytes=196
2016-08-25T21:16:45.515394+00:00 heroku[router]: at=info method=POST path="/webhook" host=warm-depths-81393.herokuapp.com request_id=f497c7b2-a9ee-4f9c-83b9-c23a2e358cc1 fwd="66.220.158.111" dyno=web.1 connect=0ms service=2ms status=200 bytes=196
Редактирование: я только что обнаружил, что второй пользователь, который бот неоднократно посылает сообщение, на самом деле является самой страницей Facebook chatbot. Есть ли причина, по которой чатбот тоже отправляет сообщение?