How do I get a users geocoordinates with the Bot Framework? I know I have to use entities but am not sure how to actually get the coordinates and not define them.
答案 0 :(得分:3)
不幸的是,没有自动方式来获取用户的位置,因为会侵犯用户隐私。
但是,您始终可以请求用户的位置。取决于他们正在使用的聊天频道,他们可能会向您发送他们的位置(我在电报上测试过)
作为起点,您可能需要阅读
示例代码:
var reply = activity.CreateReply();
reply.ChannelData = new TelegramCustomMessage
{
Method = "sendLocation",
Parameters = new Parameters
{
ChatId = "your_chat_id",
Latitute = 0,
Longitute = 0
}
};
public class TelegramCustomMessage
{
[JsonProperty(PropertyName = "method")]
public string Method { get; set; }
[JsonProperty(PropertyName = "parameters")]
public Parameters Parameters { get; set; }
}
public class Parameters
{
[JsonProperty(PropertyName = "chat_id")]
public string ChatId { get; set; }
[JsonProperty(PropertyName = "latitute")]
public float Latitute { get; set; }
[JsonProperty(PropertyName = "longitute")]
public float Longitute { get; set; }
}
https://docs.botframework.com/en-us/csharp/builder/sdkreference/channels.html#customtelegrammessages
https://core.telegram.org/bots/api#sendlocation
示例代码:
if (entity.Type == "Place")
{
Place place = entity.GetAs<Place>();
GeoCoordinates geoCoord = place.Geo.ToObject<GeoCoordinates>();
// geoCoord object will contains Longtitude & Latitude
}
https://docs.botframework.com/en-us/csharp/builder/sdkreference/activities.html#places
答案 1 :(得分:0)
该团队刚刚添加了对位置服务框架的支持。超级有用:https://github.com/Microsoft/BotBuilder-Location