Botkit: Can't handle user location ( facebook Bot)

Created on 20 Sep 2017  路  4Comments  路  Source: howdyai/botkit

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

Facebook-related help wanted

Most helpful comment

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 ?

All 4 comments

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 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dfischer picture dfischer  路  4Comments

abinashmohanty picture abinashmohanty  路  4Comments

liornaar picture liornaar  路  3Comments

koubenecn picture koubenecn  路  3Comments

seriousssam picture seriousssam  路  3Comments