【问题标题】:Microsoft Bot Framework GeolocationMicrosoft Bot 框架地理定位
【发布时间】:2016-08-30 04:15:15
【问题描述】:

如何使用 Bot Framework 获取用户的地理坐标?我知道我必须使用实体,但不确定如何实际获取坐标而不是定义它们。

【问题讨论】:

    标签: c# geolocation botframework chatbot


    【解决方案1】:

    很遗憾,没有自动方式获取用户的位置,因为这会侵犯用户隐私

    但是,您始终可以请求用户的位置。取决于他们使用的聊天频道,他们可能会向您发送他们的位置(我在 telegram 上测试过)

    作为起点,您可能需要阅读有关

    如何发送位置

    示例代码:

    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

    【讨论】:

    • 你可以在 Node.js 中为相同的东西添加一个 sn-p 吗?
    • @PirateApp:对不起,我对 NodeJS 一无所知 :)。
    • Place 实体也可以用于 Facebook 频道。但是,Facebook 不提供请求用户位置的方法。唯一的办法就是通过短信询问。
    • 您确定sendLocation 可用于请求用户的位置,而不是发送位置给用户吗?你有一个可行的例子吗?
    • @EugeneBerdnikov 绝对不是,“sendLocation”不能用于请求用户的位置。但是,您可以使用它来提示用户,例如“这是您当前的位置吗?”“这是您想去的地方吗?”。对于请求用户的位置,您必须使用普通短信询问用户。
    【解决方案2】:

    团队刚刚添加了对定位服务框架的支持。超级有帮助:https://github.com/Microsoft/BotBuilder-Location

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多