Botframework-sdk: [FB Messenger] How to read the location coordinates from a FB channel?

Created on 23 Jan 2018  路  4Comments  路  Source: microsoft/botframework-sdk

Bot Info

  • SDK Platform: .NET
  • SDK Version: 3.12.2.4
  • Active Channels: Facebook
  • Deployment Environment: Azure Bot Service

Issue Description

capture

I couldn't manage to read location from facebook channel inside botbuilder

Code Example

var activity = await result as IMessageActivity;
String t = activity.ChannelData.get();

Expected Behavior

Get the longitude and latitude sent by user in the location button in facebook

Most helpful comment

Works like charm, thank you @JasonSowers.

All 4 comments

I found this in another GitHub issue see if it helps you https://github.com/Yudner/Bot-Framework-Code/blob/master/LocationFacebookControl/FacebookLocationControlDialog.cs It looks like you have to read it from Channeldata > quick_reply

var channelData = JObject.FromObject(new
                {
                    quick_replies = new dynamic[]
                    {
                        new
                        {
                            content_type = "location",
                        }
                    }
                });

try this

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            dynamic data = JObject.Parse(activity.ChannelData.ToString());

            string longitude = data.message.attachments[0].payload.coordinates["long"].ToString();
            string latitude = data.message.attachments[0].payload.coordinates["lat"].ToString();

            // return our reply to the user
            await context.PostAsync(longitude + "\n\n" + latitude);

            context.Wait(MessageReceivedAsync);
        }

Works like charm, thank you @JasonSowers.

Thank you. I really needed this and am up and running now. It works perfectly well..

Was this page helpful?
0 / 5 - 0 ratings