Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Facebook bots cannot handle location data #337

Closed
SheaBelsky opened this issue Jul 24, 2016 · 13 comments
Closed

Facebook bots cannot handle location data #337

SheaBelsky opened this issue Jul 24, 2016 · 13 comments

Comments

@SheaBelsky
Copy link

When trying to use a Facebook bot and sending location data through Messenger (iOS/Android), 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 instead, nor do I know if there is a simpler way of trying to extract the location data through Botkit at all.

I'm definitely getting a POST request to my server and there aren't any discernible errors or bugs that I can identify. By temporarily overriding the POST request and logging the output, the location is definitely there, but then I would need to manually trigger the message_received event. I'd like to retain usage of the createWebhookEndpoints function and have Botkit construct the routes for me, versus needing to manually construct the routes and event listeners.

@shirilad
Copy link

Which botkit version are you using?
When sending location data via messenger (at least on iOS), I'm getting a 'message_received' event, and then the location itself is in attachments. no need to override createWebhookEndpoints or anything of the sort...
I'm currently on 0.2.2 if it helps.

@SheaBelsky
Copy link
Author

I'm running Botkit 0.2.2 as well. I'm still not getting a message_received event on my server, although I'm definitely getting a POST request. I tested this on both iOS and Android, same result. Is there maybe a way to see what event, if any, is being trigged and try to manually construct an event listener for that?

@shirilad
Copy link

Are you getting any other facebook_events or is just the location the problem?
Would suggest adding the debug flag to bot and see if the hook is caught:
botkit.facebookbot({ ... debug: true})
if it isn't, something is wrong with your webook and/or registration to the message events.
if it does it's even weirder - would put a break point in Facebook.js where the message hook is received and see what's up (under createWebhookEndpoints method)

@SheaBelsky
Copy link
Author

SheaBelsky commented Jul 25, 2016

The webhook isn't getting caught. On normal text messages I get this:

2016-07-25T12:05:21.627-0400[App/0]OUTdebug: WEBHOOK SUCCESS {"recipient_id":"1061130400603167","message_id":"mid.1469462721449:3720bb2ff7dd6e5d45"}
2016-07-25T12:05:22.043-0400[App/0]OUTdebug: No handler for message_delivered
2016-07-25T12:05:22.043-0400[App/0]OUTdebug: GOT A MESSAGE HOOK
2016-07-25T12:05:22.043-0400[RTR/0]OUT[MyURL] - [25/07/2016:16:05:22.030 +0000] "POST /facebook/receive HTTP/1.1" 200 273 2 "-" "-" [MyIP] x_forwarded_for:"[MyIP]" x_forwarded_proto:"https" vcap_request_id:826d4d2b-c5b1-4401-6b0e-5bbd7a147ad6 response_time:0.011819942 app_id:990451e2-bca6-49ad-89b1-f554866e0baf x_global_transaction_id:"2051127521"

But for a location message, I only get this:

2016-07-25T12:38:34.695-0400[App/0]OUTdebug: CUSTOM FIND CONVO 1061130400603167 1061130400603167
2016-07-25T12:38:34.695-0400[App/0]OUTdebug: GOT A MESSAGE HOOK
2016-07-25T12:38:34.695-0400[App/0]OUTdebug: RECEIVED MESSAGE

I also get debug: No handler for tick in the console. I'm sure it's related, but I don't know how to mitigate it. Also, the No handler for message_delivered in the normal message text is weird, because I get the appropriate response back from my bot.

@shirilad
Copy link

I actually meant the "GOT A MESSAGE HOOK" message :)
If that's the case, would put a break point in Facebook.js where the message hook is received and see what's up (under createWebhookEndpoints method)
Cause what it does these is just build the message and send it, so you can see where exactly is the problem...

(Maybe I'm missing something simpler... if that's the case, sorry in advance... or in retrospect... or something :) )

@ahsanazim
Copy link

@SHBelsky has there been any movement on your end with reference to this bug? I'm experiencing a similar problem and am considering taking @shirilad's advice and debugging my way through the facebook.js file. Just wanted to first know if you'd found a workaround or not

@SheaBelsky
Copy link
Author

I wasn't able to quite debug the problem. It doesn't seem like anything should be stopping the attachments from coming in, but that still seems to happen. Using the routes provided in createWebhookEndpoints, while not actually calling that function but using the function body, appears to have worked for me.

@RobinJayaswal
Copy link

@SHBelsky Are you using some kind of middleware? I was using howdyai's botkit-middleware-witai, and it turned out this was where the problem was. I submitted a pull request for it here howdyai/botkit-middleware-witai#13

@maxhartshorn
Copy link

In my case the message hook is being triggered. However, since there is no message.text none of my listeners fire. Even the pattern /^.*$/ doesn't yield any results. My hack solution was to detect a location response and set the message.text to 'LOCATION_QUERY'.

Is there any other way to listen for FB attachments?

I am on 0.2.2 and I'm not using the witai middleware.

@peterswimm
Copy link
Contributor

Changing this to a feature request.

@PierreMarieRiviere
Copy link

Just in case this is useful to someone, here is how I handled the location:

whereAreYou = function(response, convo) {
convo.ask({
            text: 'Where are you honey?',
            quick_replies: [
            {
                "content_type":"location",
            }]
        }, function(response, convo) {
            if(response.attachments[0].type == "location"){
                coordinates = response.attachments[0].payload.coordinates;
                responseStore.toDatabase('Location', coordinates, response);
                convo.say('got it, latitude' + response.attachments[0].payload.coordinates.lat + 'and longitude' + response.attachments[0].payload.coordinates.lat);
                aTopic(response, convo);
        }
        else {
            convo.say('no no no');
            anotherTopic(response, convo);
        }
    convo.next();
    });
};

Also sending a location quick reply requires to desactivate the quick_replies titleLimit function. Should be fixed in master?

@jay-jlm
Copy link

jay-jlm commented Feb 26, 2017

Time to close this?
Looks like it's been already merged into master and has been working fine for us.

@peterswimm
Copy link
Contributor

Will close for now!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants