Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telegram] Get user location #1595

Closed
GhostAtom opened this issue Nov 7, 2016 · 11 comments
Closed

[Telegram] Get user location #1595

GhostAtom opened this issue Nov 7, 2016 · 11 comments
Assignees
Labels
customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete.

Comments

@GhostAtom
Copy link

How can I get the location from Telegram in c# ?

How can I test the location handling with the bot connector emulator?

Do you have some exemple of that use case? I'm scratching my head for too long. Thanks for the help.

@palmerabollo
Copy link
Contributor

palmerabollo commented Nov 7, 2016

If I'm not wrong, when you send your location from Telegram, you receive it in an array of entities in your message (something similar to an attachment). The entities allow the exchange of common contextual metadata between the channel and bot.

At least it is how it works in node.js. Take a look at the "Entities Property" section here https://docs.botframework.com/en-us/csharp/builder/sdkreference/activities.html

I don't think you can test it with the emulator. I used ngrok and with a real Telegram client. It's easy to log the messages you receive to see the entities. I hope it helps.

@GhostAtom
Copy link
Author

@palmerabollo I cannot log the http requests with ngrok each time I get a 400 bad request error. Maybe my setup is wrong.

When I check the log stream in Azure, it seems to happen when awaiting the activity result or in the framework.

Microsoft.Rest.HttpOperationException: Object reference not set to an instance of an object.
at Microsoft.Bot.Connector.ErrorHandling.d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Connector.ConversationsExtensions.<ReplyToActivityAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser.<Microsoft-Bot-Builder-Dialogs-Internals-IBotToUser-PostAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.MapToChannelData_BotToUser.<PostAsync>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.LogBotToUser.<Microsoft-Bot-Builder-Dialogs-Internals-IBotToUser-PostAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.<Microsoft-Bot-Builder-Dialogs-Internals-IBotToUser-PostAsync>d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Extensions.<PostAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at bienbon.Bot.Dialogs.LocationDialog.<MessageReceivedAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop-PollAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter.GetResult()
at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.<ResumeAsync>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop-PollAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IDialogStack-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__211.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ScoringDialogTask1.d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.SerializingDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.d__51.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at bienbon.Bot.Controllers.MessagesController.<Post>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()

@eanders-ms eanders-ms assigned eanders-ms and unassigned eanders-ms Nov 19, 2016
@eanders-ms
Copy link
Contributor

eanders-ms commented Nov 19, 2016

Hi @GhostAtom palmerabollo is correct this isn't something you can catch in the emulator - it is Telegram-specific. But you should be able to run your bot locally with ngrok and debug it that way. You might double-check that your locally running bot is getting initialized with the correct Microsoft appId and password. Also ensure that your bot registration page in the Dev Portal has the right ngrok endpoint (it changes each time you launch ngrok). It should look something like this:

https://XXXXXX.ngrok.io/api/messages

@GhostAtom
Copy link
Author

GhostAtom commented Nov 25, 2016

Hi @eanders-ms I tried another time but still have 400 error code.
When I log the activity messages, I get something like below. But I cannot retrieve the location object.

"messageType": "message",
    "serviceUrl": "https://telegram.botframework.com/",
    "@timestamp": "2016-11-25T12:05:34.5818702+00:00",
    "channelId": "telegram",
    "from": {
      "id": "10700706",
      "name": "Ghostatom"
    },
    "conversation": {
      "isGroup": false,
      "id": "10700706"
    },
    "recipient": {
      "id": "foodeezy_bot",
      "name": "foodeezy"
    },
    "channelData": {
      "update_id": 10700706,
      "message": {
        "message_id": 2612,
        "from": {
          "id": 10700706,
          "first_name": "Ghostatom",
          "last_name": "Ghostatom",
          "username": "Ghostatom"
        },
        "chat": {
          "id": 10700706,
          "first_name": "Ghostatom",
          "last_name": "Ghostatom",
          "username": "Ghostatom",
          "type": "private"
        },
        "date": 1480075532,
        "location": {
          "latitude": 48.893854,
          "longitude": 2.238028
        }
      }
    }

@chrimc62
Copy link
Contributor

@eanders-ms any other ideas?

@eanders-ms
Copy link
Contributor

@GhostAtom Is your bot registered with the Bot Framework? What is its MSA AppID?

@GhostAtom
Copy link
Author

@eanders-ms yes
AppId=0614d470-23cc-4ab2-adba-48494f44041d

@eanders-ms
Copy link
Contributor

@GhostAtom Are you still seeing this error?

It occurs to me that it would be useful if the emulator could send a location to the bot.

@Sid245439
Copy link

Is it possible to get current location of user through node.js chat bot using botbuilder with webchat as a channel??? Till now I found "botbuilder-location" npm used to track the location.. But with webchat how would I be able to get the current location...
FB messenger uses "useNativeControl: true," to track the current address as a location picker... Is it possible to do the same thing with webchat as channel or not???? If possible please provide reference....
Please rpl soon..
Thanx in Advanse

@LorenzCK
Copy link

(Might be a bit late now, but for future reference.)

When the bot receives a location through Telegram, the session.message object looks as follows:

{
	"type": "message",
	"timestamp": "2017-02-22T17:19:08.3506448Z",
	"entities": [{
			"geo": {
				"elevation": 0,
				"latitude": 43.728994,
				"longitude": 12.640851,
				"type": "GeoCoordinates"
			},
			"type": "Place"
		}
	],
	"sourceEvent": {
		"update_id": 108692011,
		"message": {
			"message_id": 119,
			"from": {
				... Telegram user ID ...
			},
			"chat": {
				... Telegram conversation ID ...
			},
			"date": 1487783948,
			"location": {
				"latitude": 43.728994,
				"longitude": 12.640851
			}
		}
	},
	"text": "", etc.

As you can see, while the sourceEvent contains the raw update from Telegram (which of course also contains the location data), the location is indeed nicely parsed and added as a "geo" entity under session.message.entities.

@FernandoPrado-ms
Copy link

Barring confirmation from original poster, it looks like this issue (question) can be closed since an apparently proper answer has been given. For now, I am labeling as "question" and "answered".

@FernandoPrado-ms FernandoPrado-ms added customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. question labels Mar 27, 2017
@nwhitmont nwhitmont added the C# label Apr 10, 2017
@nwhitmont nwhitmont changed the title Get user location [Telegram] Get user location Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete.
Projects
None yet
Development

No branches or pull requests

8 participants