Пример #1
0
        public async Task LocationReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var msg      = await argument;
            var reply    = context.MakeMessage();
            var location = msg.Entities?.Where(t => t.Type == "Place").Select(t => t.GetAs <Place>()).FirstOrDefault();

            context.Done(location);

            if (location == null)
            {
                reply.Text = "謝謝您的使用!";
                await context.PostAsync(reply);

                return;
            }

            var geo = (location.Geo as JObject)?.ToObject <GeoCoordinates>();

            reply.Text = "距離您地點最近的輔具中心是...";
            if (geo != null)
            {
                Dictionary <string, string> site = ChatUtil.GetNearestLocation(Convert.ToDouble(geo.Latitude), Convert.ToDouble(geo.Longitude), Sites);
                double siteLat = Convert.ToDouble(site["lat"]);
                double siteLon = Convert.ToDouble(site["lon"]);

                reply.Attachments.Add(new HeroCard
                {
                    Title    = site["name"],
                    Subtitle = site["address"],
                    Text     = Environment.NewLine + site["phone"] + Environment.NewLine + site["email"],
                    Buttons  = new List <CardAction> {
                        new CardAction
                        {
                            Title = "帶我去" + site["name"],
                            Type  = ActionTypes.OpenUrl,
                            Value = "https://www.google.com.tw//maps/place/" + site["name"] + $"/@{siteLat},{siteLon},15z",
                            //Value = $"https://www.bing.com/maps/?v=2&cp={siteLat}~{siteLon}&lvl=16&dir=0&sty=c&sp=point.{siteLat}_{siteLon}_You%20are%20here&ignoreoptin=1"
                        }
                    }
                }.ToAttachment());
            }
            else
            {
                reply.Text = "這是哪裡阿﹍";
            }
            await context.PostAsync(reply);
        }