I'm trying to handle a location sent by user with FB Messenger.
the message_received event isn't being fired, so the controller can't handle the location data at all. I don't know what event I should use.
I'm trying to extract the location data like this :
console.log("lat localisation"+message.attachments[0].payload.coordinates.lat);
console.log("long localisation"+message.attachments[0].payload.coordinates.long);
output:
lat localisationundefined
long localisationundefined
Hello,
Try to handle all incoming messages by attaching the event handler message_received to the FB controller then test if it's a location attachement one, the code snippet below shows how to do that :
controller.on('message_received', (bot, message) => {
if (message.attachments && message.attachments[0].type === 'location') {
let latitude = message.attachments[0].payload.coordinates.lat;
let longitude = message.attachments[0].payload.coordinates.long;
bot.reply(message, `You ate ${latitude} / ${longitude} !`);
}
});
I think it'll be useful to handle a new fb event natively by Botkit when prompt a user for their location instead of catching all messages every time ! maybe handle every other media type (audio, video, file ... ) one by one !! something like this :
````
/* Proposal */
controller.on('attachement_location', (bot, message) => { ... });
controller.on('attachement_audio', (bot, message) => { ... });
controller.on('attachement_video', (bot, message) => { ... });
controller.on('attachement_file', (bot, message) => { ... });
````
Thought ?
+1
+1
@ouadie-lahdioui's solution works great, but with the new messaging pipeline I'd suggest making this a middleware, until Botkit does it natively 馃憤
Most helpful comment
Hello,
Try to handle all incoming messages by attaching the event handler
message_receivedto the FB controller then test if it's a location attachement one, the code snippet below shows how to do that :controller.on('message_received', (bot, message) => { if (message.attachments && message.attachments[0].type === 'location') { let latitude = message.attachments[0].payload.coordinates.lat; let longitude = message.attachments[0].payload.coordinates.long; bot.reply(message, `You ate ${latitude} / ${longitude} !`); } });I think it'll be useful to handle a new fb event natively by Botkit when prompt a user for their location instead of catching all messages every time ! maybe handle every other media type (audio, video, file ... ) one by one !! something like this :
````
/* Proposal */
controller.on('attachement_location', (bot, message) => { ... });
controller.on('attachement_audio', (bot, message) => { ... });
controller.on('attachement_video', (bot, message) => { ... });
controller.on('attachement_file', (bot, message) => { ... });
````
Thought ?