public async Task <IHttpActionResult> Post()
        {
            try
            {
                //Get Message
                string postData    = Request.Content.ReadAsStringAsync().Result;
                var    RequestBody = isRock.LineBot.Utility.Parsing(postData);
                string Message     = RequestBody.events[0].message.text;

                //取得LUIS的相關設定值
                NLPInfo LUISInfo = db.GetNLPInfo("LineBotNLP");

                //Send to Analysis
                Microsoft.Cognitive.LUIS.LuisClient lc
                    = new Microsoft.Cognitive.LUIS.LuisClient(LUISInfo.appid, LUISInfo.appKey, true);
                var AnalysisResult = await lc.Predict(Message);

                //Get Reply Message
                string replyMessage = db.GetResult(AnalysisResult);

                //Response Message
                string ChannelAccessToken = db.GetBotToken("Line");
                isRock.LineBot.Utility.ReplyMessage(RequestBody.events[0].replyToken, replyMessage, ChannelAccessToken);
                return(Ok());
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("ErrorMessage:{0},ErrorStack:{1},InnerExcepton:",
                                                    ex.Message,
                                                    ex.StackTrace,
                                                    ex.InnerException);
                db.InsertRequestLog(errorMessage);
                return(Ok(errorMessage));
            }
        }
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                if (LineEvent.type == "message")
                {
                    var repmsg = "";
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc =
                            new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);

                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;
                        if (ret.Intents.Count() <= 0)
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但我看不懂喔!";
                        }
                        else if (ret.TopScoringIntent.Name == "None")
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔!";
                        }
                        else
                        {
                            repmsg = $"OK,你想 '{ret.TopScoringIntent.Name}',";
                            if (ret.Entities.Count > 0)
                            {
                                repmsg += $"想要的是 '{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}' ";
                            }
                        }
                        //回覆
                        this.ReplyMessage(LineEvent.replyToken, repmsg);
                    }
                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
Example #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //建立LuisClient
            Microsoft.Cognitive.LUIS.LuisClient lc =
                new Microsoft.Cognitive.LUIS.LuisClient(
                    this.textBoxAppID.Text.Trim(), this.textBoxKey.Text.Trim(), //請務必置換成你自己的AppID與Key
                    true, "southeastasia");                                     //請留意domain位置
            this.textBoxResult.Text = "分析中...";
            //Call Luis API 查詢
            var ret = lc.Predict(textBoxQuery.Text).Result;

            if (ret.Intents.Count() <= 0)
            {
                return;
            }

            var msg = "<br><br>  ---- Intents :";

            foreach (var item in ret.Intents)           //顯示所有抓取到的intent
            {
                msg += $"<br> intent {item.Name}  score:{item.Score} ";
            }
            msg += "<br><br> ---- Entities :";
            foreach (var item in ret.Entities)          //顯示所有抓取到的Entities
            {
                msg += $"<br> Entities {item.Value[0].Name} score:{ item.Value[0].Score} ";
            }
            //顯示於TextBox
            this.textBoxResult.Text = msg;
        }
        public async Task <IHttpActionResult> Post()
        {
            try
            {
                //Get Message
                string postData = Request.Content.ReadAsStringAsync().Result;
                db.InsertRequestLog(postData);
                var    RequestBody        = isRock.LineBot.Utility.Parsing(postData);
                string Message            = RequestBody.events[0].message.text;
                string ChannelAccessToken = db.GetBotToken("Line");
                //取得LUIS的相關設定值
                NLPInfo LUISInfo = db.GetNLPInfo("LineBotNLP");

                //Send to Analysis
                Microsoft.Cognitive.LUIS.LuisClient lc
                    = new Microsoft.Cognitive.LUIS.LuisClient(LUISInfo.appid, LUISInfo.appKey, true);
                var AnalysisResult = await lc.Predict(Message);

                string replyMessage;
                //Get Reply Message
                bool isGreeting = db.GetResult(AnalysisResult, out replyMessage);

                if (isGreeting)
                {
                    CarouselTemplate ct = LineRepository.GetButtonTemplateMessage("Carousel") as CarouselTemplate;
                    var result          = Utility.PushTemplateMessage(RequestBody.events[0].source.userId
                                                                      , ct
                                                                      , ChannelAccessToken);
                }
                else
                {
                    //Response Message
                    isRock.LineBot.Utility.ReplyMessage(RequestBody.events[0].replyToken, replyMessage, ChannelAccessToken);
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("ErrorMessage:{0},ErrorStack:{1},InnerExcepton:",
                                                    ex.Message,
                                                    ex.StackTrace,
                                                    ex.InnerException);
                db.InsertRequestLog(errorMessage);
                return(Ok(errorMessage));
            }
        }
Example #5
0
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(ChannelAccessToken);
                string Lineid = ReceivedMessage.events.FirstOrDefault().source.userId;
                var Userinfo = bot.GetUserInfo(Lineid);
                //配合Line verify 回傳一個訊息給後台表示webhook成功連接
                if (LineEvent.replyToken == "00000000000000000000000000000000") return Ok();
                //回覆訊息
                //this.PushMessage(LineEvent.source.userId,"6666"); //如果想要私訊某個人(userid)的話
                if (LineEvent.type == "message")
                {
                    //if (LineEvent.message.type == "text") //收到文字
                    //    this.ReplyMessage(LineEvent.replyToken, Userinfo.displayName + "你好,我可以回覆任何問題"); //replyToken傳訊息給整個聊天室
                    if (LineEvent.message.type == "sticker") //收到貼圖
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    if (LineEvent.message.type == "location") //GPS定位
                        this.ReplyMessage(LineEvent.replyToken, $"你的位置在 \n {LineEvent.message.latitude},{LineEvent.message.longitude}");
                    if (LineEvent.message.type == "image") //收到圖片
                    {
                        var bytes = this.GetUserUploadedContent(LineEvent.message.id);
                        var guid = Guid.NewGuid().ToString();
                        var filename = $"{guid}.png";
                        var path = System.Web.Hosting.HostingEnvironment.MapPath("~/temp/");
                        System.IO.File.WriteAllBytes(path + filename, bytes);
                        var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);
                        var url = $"{baseUrl}/temp/{filename}";
                        this.ReplyMessage(LineEvent.replyToken, $"你的圖片位於 \n {url}");
                    }
                    var repmsg = "";
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc =
                          new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);

                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;
                        if (ret.Intents.Count() <= 0)
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但我看不懂喔!";
                        else if (ret.TopScoringIntent.Name == "None")
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔!";
                        else
                        {
                            repmsg = $"OK,你想 '{ret.TopScoringIntent.Name}',";
                            if (ret.Entities.Count > 0)
                            {
                                repmsg += $"想要的是 '{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value }' 和 " +
                                $"'{ret.Entities.ElementAtOrDefault(1).Value.FirstOrDefault().Value}' 和 " +
                                $"'{ret.Entities.LastOrDefault().Value.FirstOrDefault().Value }' ";
                            }
                        }
                        //回覆
                        this.ReplyMessage(LineEvent.replyToken, repmsg);
                    }
                }

                if (LineEvent.type == "postback")
                {
                    var data = LineEvent.postback.data;
                    var datetime = LineEvent.postback.Params.datetime;
                    this.ReplyMessage(LineEvent.replyToken, $"觸發了postback \n 資料為: {data} \n 選擇結果: {datetime}");
                }
                //response OK
                return Ok(); //回傳給line server
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return Ok();
            }
        }
Example #6
0
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;


                //取得Line Event(範例,只取第一個)
                var      LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                DateTime dt        = DateTime.Now.ToLocalTime();


                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                if (LineEvent.type == "message")
                {
                    var repmsg = "";
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc =
                            new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);

                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;

                        if (ret.Intents.Count() <= 0)
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但我看不懂喔!";
                        }
                        else if (ret.TopScoringIntent.Name == "None")
                        {
                            repmsg = $"嗨~你有什麼話想說嗎?";
                        }
                        else
                        {
                            if (ret.TopScoringIntent.Name == "投訴")
                            {
                                repmsg = $"抱歉~造成您的困擾,敬請見諒,已將您的意見記錄下來,我們將在3-5天內由專人回覆您:";
                            }
                            if (ret.TopScoringIntent.Name == "建議")
                            {
                                repmsg = $"感謝您寶貴的意見,讓我們未來能提供更優質的服務:";
                            }
                            if (ret.TopScoringIntent.Name == "讚揚")
                            {
                                repmsg = $"您的肯定是我們最大的動力,希望能有榮幸再次為您服務:";
                            }
                            repmsg += $"\n ";
                            repmsg += $"\n時間:{dt.ToLongDateString().ToString()}";
                            repmsg += $"\n類別:{ret.TopScoringIntent.Name}";
                            if (ret.Entities.Count > 0)
                            {
                                repmsg += $"\n項目:{ret.Entities.FirstOrDefault().Key}";
                            }
                            else
                            {
                                repmsg += $"\n項目:其他";
                            }
                            repmsg += $"\n意見:{LineEvent.message.text}";

                            //ret.Entities => Dict
                            //ret.Entities.FirstOrDefault() => KeyValuePair
                            //ret.Entities.FirstOrDefault().Key => type
                            //repmsg += $",你在說的是{ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}";
                        }
                        //回覆
                        this.ReplyMessage(LineEvent.replyToken, repmsg);
                    }
                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
Example #7
0
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                if (LineEvent.type == "message")
                {
                    var    repmsg         = "";
                    string postData       = Request.Content.ReadAsStringAsync().Result;
                    var    ReceiveMessage = isRock.LineBot.Utility.Parsing(postData);
                    var    actions        = new
                                            List <isRock.LineBot.TemplateActionBase>();
                    var actions2 = new
                                   List <isRock.LineBot.TemplateActionBase>();
                    var actions3 = new
                                   List <isRock.LineBot.TemplateActionBase>();
                    var Medical = new
                                  isRock.LineBot.ButtonsTemplate();
                    var Hospital = new
                                   isRock.LineBot.ButtonsTemplate();
                    var ConfirmTemplateMsg = new
                                             isRock.LineBot.ConfirmTemplate();

                    //var botevent = this.ReceivedMessage.events.FirstOrDefault();
                    //var Postdata = botevent.postback.data;


                    //抓取用戶UserId、UserInfo
                    var UserId = ReceivedMessage.events.FirstOrDefault().source.userId;
                    isRock.LineBot.Bot bot1 = new isRock.LineBot.Bot(channelAccessToken);
                    var UserInfo            = bot1.GetUserInfo(UserId);
                    var Address             = ReceivedMessage.events[0].message.address;
                    var latitude            = ReceivedMessage.events[0].message.latitude;
                    var longitude           = ReceivedMessage.events[0].message.longitude;

                    string Message;
                    Message = "" + ReceivedMessage.events[0].type;
                    if (LineEvent.message.type == "location" || ReceivedMessage.events[0].message.text == "搜尋中...")
                    {
                        actions.Add(new isRock.LineBot.UriAction()
                        {
                            label = "查看官網", uri = new Uri("http://www.wellseen.com.tw/")
                        });
                        actions.Add(new isRock.LineBot.UriAction()
                        {
                            label = "Google Map導航", uri = new Uri("https://www.google.com.tw/maps/place/%E6%83%9F%E6%96%B0%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x4b1a2fedbf9b04ff!8m2!3d25.083483!4d121.5516588?hl=zh-TW")
                        });
                        var Column = new isRock.LineBot.Column
                        {
                            text              = "距離2.3公里,開車前往約7分",
                            title             = "惟新動物醫院",
                            thumbnailImageUrl = new Uri("https://6.share.photo.xuite.net/phibus/169386b/9792593/434439194_m.jpg"),
                            actions           = actions
                        };
                        actions2.Add(new isRock.LineBot.UriAction()
                        {
                            label = "查看官網", uri = new Uri("https://sites.google.com/site/cahvet/")
                        });
                        actions2.Add(new isRock.LineBot.UriAction()
                        {
                            label = "Google Map導航", uri = new Uri("https://www.google.com.tw/maps/place/%E5%8A%A0%E5%B7%9E%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x994d64cddf53704!8m2!3d25.0786487!4d121.5799052?hl=zh-TW")
                        });
                        var Column2 = new isRock.LineBot.Column
                        {
                            text              = "距離2.7公里,開車前往約8分",
                            title             = "加州動物醫院",
                            thumbnailImageUrl = new Uri("https://s3-media3.fl.yelpcdn.com/bphoto/l3Dq4i27euT0gijwXKjvXg/ls.jpg"),
                            actions           = actions2
                        };
                        actions3.Add(new isRock.LineBot.UriAction()
                        {
                            label = "查看官網", uri = new Uri("http://www.petline.com.tw/petline/cgi/index_factory.cgi?t=petfactory_view&ID=11010&R23=1000")
                        });
                        actions3.Add(new isRock.LineBot.UriAction()
                        {
                            label = "Google Map導航", uri = new Uri("https://www.google.com.tw/maps/place/%E8%A5%BF%E6%B9%96%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x8868f530d4bda2ab!8m2!3d25.0822514!4d121.5688866?hl=zh-TW")
                        });
                        var Column3 = new isRock.LineBot.Column
                        {
                            text              = "距離1.5公里,開車前往約5分",
                            title             = "西湖動物醫院",
                            thumbnailImageUrl = new Uri("https://www.3cu.com.tw/UploadFile/UserFiles/images/no_artist_p-b.gif"),
                            actions           = actions3
                        };

                        var CarouseTemplate = new isRock.LineBot.CarouselTemplate();
                        CarouseTemplate.columns.Add(Column);
                        CarouseTemplate.columns.Add(Column2);
                        CarouseTemplate.columns.Add(Column3);
                        repmsg = $"";
                        isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                        bot.PushMessage(UserId, CarouseTemplate);
                        return(Ok());
                    }



                    if (LineEvent.message.type == "text") //收到文字
                    {
                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc =
                            new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);

                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;
                        ///////////////////////////////
                        ///////////////////////////////
                        var      Uri   = "http://netinfo.takming.edu.tw/tip/";
                        var      uri1  = "https://petbird.tw/article2979.html";
                        var      uri2  = "https://kknews.cc/zh-tw/health/39a95vo.html";
                        var      uri3  = "https://read01.com/zh-tw/az4K3x.html#.WyYrqVUzaUk";
                        var      uri4  = "https://petbird.tw/article6910.html";
                        DateTime date1 = DateTime.Now;
                        if (ReceivedMessage.events[0].message.text == "詢問醫療" || ReceivedMessage.events[0].message.text == "醫療")
                        {
                            Medical.thumbnailImageUrl = new Uri("https://cdn-images-1.medium.com/max/2000/1*Vk4qnZdU-VkOlWiayzbIyQ.png");
                            Medical.text  = "其他相關醫療資訊";
                            Medical.title = "動物醫療";
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問疫苗", text = "疫苗"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問疾病", text = "疾病"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問晶片", text = "晶片"
                            });
                            Medical.actions = actions;
                            isRock.LineBot.Bot bot2 = new isRock.LineBot.Bot(channelAccessToken);
                            repmsg = $"";
                            bot2.PushMessage(UserId, Medical);
                            return(Ok());
                        }



                        if (ReceivedMessage.events[0].message.text == "research" || ReceivedMessage.events[0].message.text == "寵物受傷")
                        {
                            ConfirmTemplateMsg.text = "您的寵物是?";
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "狗", text = "dog"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "貓", text = "cat"
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }
                        if (ReceivedMessage.events[0].message.text == "dog")
                        {
                            ConfirmTemplateMsg.text = "您的狗狗怎麼了?";
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "生病", text = "Dsick"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "受傷", text = "Dhurt"
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }
                        else if (ReceivedMessage.events[0].message.text == "cat")
                        {
                            ConfirmTemplateMsg.text = "您的貓咪怎麼了?";
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "生病", text = "Csick"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "受傷", text = "Churt"
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }
                        if (ReceivedMessage.events[0].message.text == "Dsick")
                        {
                            ConfirmTemplateMsg.text = "您的狗狗生病了";
                            actions.Add(new isRock.LineBot.UriAction()
                            {
                                label = "生病症狀", uri = new Uri("https://petbird.tw/article2974.html")
                            });
                            actions.Add(new isRock.LineBot.UriAction()
                            {
                                label = "處理辦法", uri = new Uri("https://petbird.tw/article8971.html")
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }
                        else if (ReceivedMessage.events[0].message.text == "Dhurt")
                        {
                            ConfirmTemplateMsg.text = "您的狗狗受傷了";
                            actions.Add(new isRock.LineBot.UriAction()
                            {
                                label = "緊急處理", uri = new Uri("https://petbird.tw/article11192.html")
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "附近醫院", text = "附近的動物醫院"
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }
                        else if (ReceivedMessage.events[0].message.text == "Csick")
                        {
                            ConfirmTemplateMsg.text = "您的貓咪生病了";
                            actions.Add(new isRock.LineBot.UriAction()
                            {
                                label = "生病症狀", uri = new Uri("https://petbird.tw/article3359.html")
                            });
                            actions.Add(new isRock.LineBot.UriAction()
                            {
                                label = "處理辦法", uri = new Uri("https://petbird.tw/article9058.html")
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }
                        else if (ReceivedMessage.events[0].message.text == "Churt")
                        {
                            ConfirmTemplateMsg.text = "您的貓咪受傷了";
                            actions.Add(new isRock.LineBot.UriAction()
                            {
                                label = "緊急處理", uri = new Uri("https://petbird.tw/article6910.html")
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "附近醫院", text = "附近的動物醫院"
                            });
                            ConfirmTemplateMsg.actions = actions;
                            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                            bot.PushMessage(UserId, ConfirmTemplateMsg);
                            return(Ok());
                        }



                        if (ret.TopScoringIntent.Name == "None")
                        {
                            Medical.thumbnailImageUrl = new Uri("https://cdn-images-1.medium.com/max/2000/1*Vk4qnZdU-VkOlWiayzbIyQ.png");
                            Medical.text  = "您可以透過以下來選擇您想詢問的資訊";
                            Medical.title = "動物醫生";
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問醫療", text = "詢問醫療"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問食品", text = "詢問食品"
                            });
                            actions.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問飼料牌子", text = "推薦的牌子"
                            });
                            Medical.actions = actions;
                            isRock.LineBot.Bot bot2 = new isRock.LineBot.Bot(channelAccessToken);
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔!";
                            bot2.PushMessage(UserId, Medical);
                            return(Ok());
                        }



                        else if (ret.TopScoringIntent.Name == "點餐")
                        {
                            repmsg = $"你想 '{LineEvent.message.text}',要的是 '{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}',這裡是我們的官網" + Uri;
                        }
                        else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "尿尿")
                        {
                            repmsg = $"那可能是因為狗狗沒喝水";
                        }
                        else if (ret.TopScoringIntent.Name == "詢問時間")
                        {
                            repmsg = $"你想 '{LineEvent.message.text}',現在時間" + date1.ToString("yyyy/MM/dd,hh:mm:ss");
                            //ScriptRuntime pyRunTime = Python.CreateRuntime();
                            // dynamic obj = pyRunTime.UseFile("PythonApplication1.py");
                            // obj.movie();
                            // repmsg = $"{obj.movie}";
                        }



                        else if (ret.Intents.Count() >= 0 && ret.TopScoringIntent.Name == "詢問醫療")
                        {
                            if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "動物醫院" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "獸醫院" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "醫院")
                            {
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "查看官網", uri = new Uri("http://www.wellseen.com.tw/")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "Google Map導航", uri = new Uri("https://www.google.com.tw/maps/place/%E6%83%9F%E6%96%B0%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x4b1a2fedbf9b04ff!8m2!3d25.083483!4d121.5516588?hl=zh-TW")
                                });
                                var Column = new isRock.LineBot.Column
                                {
                                    text              = "距離2.3公里,開車前往約7分",
                                    title             = "惟新動物醫院",
                                    thumbnailImageUrl = new Uri("https://6.share.photo.xuite.net/phibus/169386b/9792593/434439194_m.jpg"),
                                    actions           = actions
                                };
                                actions2.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "查看官網", uri = new Uri("https://sites.google.com/site/cahvet/")
                                });
                                actions2.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "Google Map導航", uri = new Uri("https://www.google.com.tw/maps/place/%E5%8A%A0%E5%B7%9E%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x994d64cddf53704!8m2!3d25.0786487!4d121.5799052?hl=zh-TW")
                                });
                                var Column2 = new isRock.LineBot.Column
                                {
                                    text              = "距離2.7公里,開車前往約8分",
                                    title             = "加州動物醫院",
                                    thumbnailImageUrl = new Uri("https://s3-media3.fl.yelpcdn.com/bphoto/l3Dq4i27euT0gijwXKjvXg/ls.jpg"),
                                    actions           = actions2
                                };
                                actions3.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "查看官網", uri = new Uri("http://www.petline.com.tw/petline/cgi/index_factory.cgi?t=petfactory_view&ID=11010&R23=1000")
                                });
                                actions3.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "Google Map導航", uri = new Uri("https://www.google.com.tw/maps/place/%E8%A5%BF%E6%B9%96%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x8868f530d4bda2ab!8m2!3d25.0822514!4d121.5688866?hl=zh-TW")
                                });
                                var Column3 = new isRock.LineBot.Column
                                {
                                    text              = "距離1.5公里,開車前往約5分",
                                    title             = "西湖動物醫院",
                                    thumbnailImageUrl = new Uri("https://www.3cu.com.tw/UploadFile/UserFiles/images/no_artist_p-b.gif"),
                                    actions           = actions3
                                };

                                var CarouseTemplate = new isRock.LineBot.CarouselTemplate();
                                CarouseTemplate.columns.Add(Column);
                                CarouseTemplate.columns.Add(Column2);
                                CarouseTemplate.columns.Add(Column3);
                                repmsg = $"";
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                bot.PushMessage(UserId, CarouseTemplate);
                                return(Ok());
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "疫苗" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "預防針")
                            {
                                Medical.thumbnailImageUrl = new Uri("https://bpic.588ku.com/element_origin_min_pic/17/07/14/7a018b83b03dc478b662d36bd22e671f.jpg");
                                Medical.text  = "相關動物疫苗的資訊";
                                Medical.title = "動物疫苗";
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "認識動物疫苗及種類", uri = new Uri("http://aetasah.pixnet.net/blog/post/321991-%E7%96%AB%E8%8B%97-%E5%9F%BA%E6%9C%AC%E8%AA%8D%E8%AD%98")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "施打疫苗週期", uri = new Uri("http://blog.xuite.net/g5223086/twblog4/188516832-%E5%B9%AB%E7%8B%97%E7%8B%97%E6%B3%A8%E5%B0%84%E7%96%AB%E8%8B%97%E3%80%81%E9%A9%85%E8%9F%B2%E7%9A%84%E6%99%82%E5%88%BB%E8%88%87%E7%A8%AE%E9%A1%9E")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "施打疫苗相關資訊", uri = new Uri("https://petbird.tw/article6685.html")
                                });
                                Medical.actions = actions;
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"您所{ret.TopScoringIntent.Name}而以上是查詢到的{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}資訊";
                                bot.PushMessage(UserId, Medical);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "晶片")
                            {
                                Medical.thumbnailImageUrl = new Uri("https://bpic.588ku.com/element_origin_min_pic/17/07/14/7a018b83b03dc478b662d36bd22e671f.jpg");
                                Medical.text  = "相關動物晶片的資訊";
                                Medical.title = "動物晶片";
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "認識動物晶片與最佳位置", uri = new Uri("http://ckx613.pixnet.net/blog/post/10319749-%E3%80%90%E8%BD%89%E8%BC%89%E3%80%91%E8%AA%8D%E8%AD%98%E5%AF%B5%E7%89%A9%E6%99%B6%E7%89%87%E5%8F%8A%E6%A4%8D%E5%85%A5%E7%9A%84%E6%9C%80%E4%BD%B3%E4%BD%8D%E7%BD%AE")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "動保處寵物登記與植入晶片入口網站", uri = new Uri("https://animal.coa.gov.tw/html/index_02_5.html")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "附近的動物醫院", uri = new Uri("https://www.google.com.tw/maps/place/%E8%A5%BF%E6%B9%96%E5%8B%95%E7%89%A9%E9%86%AB%E9%99%A2/@25.0865262,121.5567785,15z/data=!4m8!1m2!2m1!1z54246Yar6Zmi!3m4!1s0x0:0x8868f530d4bda2ab!8m2!3d25.0822514!4d121.5688866?hl=zh-TW")
                                });
                                Medical.actions = actions;
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"您所{ret.TopScoringIntent.Name}而以上是查詢到的{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}資訊";
                                bot.PushMessage(UserId, Medical);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "疾病")
                            {
                                Medical.thumbnailImageUrl = new Uri("https://cdn-images-1.medium.com/max/2000/1*Vk4qnZdU-VkOlWiayzbIyQ.png");
                                Medical.text  = "有關寵物疾病的資訊";
                                Medical.title = "動物疾病";
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "狗狗十大常見疾病", uri = new Uri("https://kknews.cc/zh-tw/health/qpz3ng.html")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "貓咪六大常見疾病", uri = new Uri("https://pet.talk.tw/article.aspx?Article_ID=20")
                                });
                                actions.Add(new isRock.LineBot.MessageAction()
                                {
                                    label = "查詢更多", text = "research"
                                });
                                Medical.actions = actions;
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"您所{ret.TopScoringIntent.Name}而以上是查詢到的{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}";
                                bot.PushMessage(UserId, Medical);
                            }
                            else
                            {
                                Medical.thumbnailImageUrl = new Uri("https://cdn-images-1.medium.com/max/2000/1*Vk4qnZdU-VkOlWiayzbIyQ.png");
                                Medical.text  = "其他相關醫療資訊";
                                Medical.title = "動物醫療";
                                actions.Add(new isRock.LineBot.MessageAction()
                                {
                                    label = "詢問疫苗", text = "疫苗"
                                });
                                actions.Add(new isRock.LineBot.MessageAction()
                                {
                                    label = "詢問疾病", text = "疾病"
                                });
                                actions.Add(new isRock.LineBot.MessageAction()
                                {
                                    label = "詢問晶片", text = "晶片"
                                });
                                Medical.actions = actions;
                                isRock.LineBot.Bot bot2 = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"以上是有關醫療的資訊";
                                bot2.PushMessage(UserId, Medical);
                            }
                        }



                        else if (ret.Intents.Count() >= 0 && ret.TopScoringIntent.Name == "詢問狗狗")
                        {
                            if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "生病" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "不舒服" ||
                                ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "打噴嚏" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "發燒" ||
                                ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "流鼻水")
                            {
                                ConfirmTemplateMsg.text = "您的狗狗生病了";
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "生病症狀", uri = new Uri("https://petbird.tw/article2974.html")
                                });
                                actions.Add(new isRock.LineBot.UriAction()
                                {
                                    label = "處理辦法", uri = new Uri("https://petbird.tw/article8971.html")
                                });
                                ConfirmTemplateMsg.actions = actions;
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                bot.PushMessage(UserId, ConfirmTemplateMsg);
                                return(Ok());
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "呼吸困難" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "喘氣")
                            {
                                repmsg = $"1、保持安靜,避免患犬亂動以防加重呼吸困難。2、讓犬取坐姿勢,減少耗氧。3、取除異物,保持呼吸道暢通。4、嚴重的患犬立即送醫院進行治療。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "食慾不振")
                            {
                                repmsg = $"1、糧食內放肉沫盡量讓愛犬趁熱吃、趕快吃,因為此時肉中水分含量比較高,當時間一久會把狗糧泡軟了,泡軟的飼料對幼犬或是老犬沒什麼大礙,但對於成犬來說,牠們可是會不接受的。2、糧食內放肉條和「方法一」類似,但區別是狗飼料中不需要放多水分的肉沫,取而代之的是用牛肉乾之類的乾肉食品,其優點是不會弄濕狗糧,頗能大幅改善愛犬的食慾。3、糧食要多變化即使您的愛犬對某樣食物胃口再怎麼好,也要定期更換,不僅可以讓狗狗保持新鮮感,還能避免長期使用同種類同品牌的狗糧,可能造成的某些營養素缺少。貼心提醒:請掌握好少吃多餐的原則,狗狗一頓如果吃得太多、太脹,是難以快速消化的。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "便祕")
                            {
                                repmsg = $"1、 讓狗狗少吃動物內臟,少吃肉食,不要長期不變換的餵食某個牌子的狗糧。2、大量飲水,吃些富含植物纖維的瓜果蔬菜,偶爾可以啃食些青草。3、注意身材變化,稍有肥胖,可加大運動量,增加消耗。4、少啃食家畜的骨頭,否則大便必定乾燥。5、如果是帶狗狗去旅遊,到了新景點,最好先稍加休息。6、在狗排大便時,不要干擾它,周邊環境需保持安靜。7、對於老齡狗,更需要做好以上幾點。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "抓撓皮膚")
                            {
                                repmsg = $"狗狗抓撓皮膚可能是(真菌性皮膚病、蟎蟲性皮膚病、細菌性皮膚病) 解決辦法:1、剪短或者剃光患處毛髮:皮膚病的治療一般需要局部使用噴劑和擦劑,或全身使用藥浴治療,為了幫助藥物滲透,將患處被毛剪短或者剃光是很有必要的2、給狗狗戴上伊莉莎白脖圈或者穿上襪子:狗狗會抓撓或者啃咬患處,但抓撓或者啃咬都會加重皮膚病症狀,因此要對狗狗進行限制3、補充維生素或者卵磷脂:維生素B 和卵磷脂對皮膚有很好的作用,促進皮膚的細胞的新陳代謝,使皮膚病儘快癒合";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "牙床舌頭變色")
                            {
                                repmsg = $"牙床和舌頭的顏色顏色越紅者越健康,白色是貧血,也可能是腸道內寄生蟲或便血(細小病毒病或鉤蟲病)。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "搖頭" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "抓耳")
                            {
                                repmsg = $"搖頭、抓耳這是耳病的特有症狀,如果耳朵內骯髒又臭,可能有寄生蟲,耳尖上有皮屑的可能有疥癬蟲。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "飲水障礙")
                            {
                                repmsg = $"狗見到飲水盆往往主動走近想喝水。但是欲飲不能或進入口腔的水又滴出,這十之八九是咽喉部有病,如咽炎等。患狂犬病的狗,口極渴,由於咽麻痺不能飲水,有時見水可引起狂癲。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "發抖")
                            {
                                repmsg = $"狗狗在感到寒冷的時候會發抖,一些狗狗在洗澡後毛未擦乾也會發抖,這是正常現象。可是,如果狗狗在並不冷的時候發抖不停,就要引起家長的注意了。病態發抖的原因是狗狗的神經系統出了問題,比如腦炎、犬瘟熱等疾病,因為狗狗的神經遭到病毒的侵害,因此導致狗狗發抖。確定狗狗是非正常發抖,家長要將愛犬送往醫院就診。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "腹瀉")
                            {
                                repmsg = $"狗狗大都貪吃,吃得過多消化不了就會引起腹瀉,對於這種狗狗要禁食一天,但由寄生蟲或其它傳染病引起的腹瀉就不那麼簡單了。如果出現便血,家長更要引起足夠重視,謹防病毒性疾病。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "鼻子乾燥" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "鼻子發熱")
                            {
                                repmsg = $"狗鼻子變得乾燥、發熱,狗狗正常的鼻子應該是濕潤潤的,當狗狗發燒生病時,狗狗的鼻子就會發熱,鼻端變的乾燥,有時會出現裂開的現象。";
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "嘔吐")
                            {
                                repmsg = $"狗狗的嘔吐神經很發達,這是狗狗自我保護的一個功能。當狗狗吃了異物時,會主動吐出,一些狗狗不適應坐車,暈車嘔吐,這都是正常現象,家長不必過於擔心。";
                            }

                            Medical.thumbnailImageUrl = new Uri("https://cdn-images-1.medium.com/max/2000/1*Vk4qnZdU-VkOlWiayzbIyQ.png");
                            Medical.text  = "其他狗狗相關資訊";
                            Medical.title = "詢問狗狗";
                            actions2.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問牌子", text = "推薦的牌子"
                            });
                            actions2.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問食品", text = "詢問食品"
                            });
                            actions2.Add(new isRock.LineBot.MessageAction()
                            {
                                label = "詢問醫療", text = "詢問醫療"
                            });
                            Medical.actions = actions2;
                            isRock.LineBot.Bot bot2 = new isRock.LineBot.Bot(channelAccessToken);
                            repmsg = $"以上是有關狗狗相關的資訊";
                            bot2.PushMessage(UserId, Medical);
                        }



                        else if (ret.TopScoringIntent.Name == "詢問食品")
                        {
                            if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "巧克力")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"巧克力對狗來說是致命的毒藥,巧克力中毒的狗,在食用之後二到四小時,會有嘔吐和下痢的現象,狗狗也會顯現不安和活動增加的狀況,由於甲基黃漂吟有利尿作用,所以狗會有頻尿現象,都可作為狗主人研判的指標。 嚴重者,會在食用後的十二到三十六小時內死亡。如果狗狗不是一次食用巧克力過量中毒,而是持續幾天食用,則有可能死於心臟衰竭。";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "洋蔥")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"這些食物中含有二氧化硫,可能導致狗狗體內的紅血球破裂。若吃下太多,狗狗可能出現貧血、呼吸急促、血尿的狀況。小型犬尤其對這類食物更加敏感~飼主一定要小心!"; Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "蒜頭")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"這些食物中含有二氧化硫,可能導致狗狗體內的紅血球破裂。若吃下太多,狗狗可能出現貧血、呼吸急促、血尿的狀況。小型犬尤其對這類食物更加敏感~飼主一定要小心!"; Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "蔥")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"這些食物中含有二氧化硫,可能導致狗狗體內的紅血球破裂。若吃下太多,狗狗可能出現貧血、呼吸急促、血尿的狀況。小型犬尤其對這類食物更加敏感~飼主一定要小心!"; Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "韭蔡")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"這些食物中含有二氧化硫,可能導致狗狗體內的紅血球破裂。若吃下太多,狗狗可能出現貧血、呼吸急促、血尿的狀況。小型犬尤其對這類食物更加敏感~飼主一定要小心!";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "生雞蛋")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"生雞蛋的細菌風險大,近年也有多起雞蛋食安風波。建議飼主準備狗狗鮮食時,將雞蛋確實煮熟才能讓狗狗安心吃。";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "葡萄")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"有研究報告指出,葡萄與葡萄乾可能引起狗狗急性腎衰竭。雖然目前仍有許多爭議,但美國愛護動物協會(ASPCA)仍將葡萄列為危險食物。建議狗狗還是少碰葡萄為妙喔!";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "葡萄乾")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"有研究報告指出,葡萄與葡萄乾可能引起狗狗急性腎衰竭。雖然目前仍有許多爭議,但美國愛護動物協會(ASPCA)仍將葡萄列為危險食物。建議狗狗還是少碰葡萄為妙喔!";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "水果籽核")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"種子通常堅硬不好消化,部分種子具有毒性,更容易阻塞食道與腸胃。所以餵狗狗吃水果時,請確實去籽喔!";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                            else if (ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "吃甚麼" || ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "吃什麼")
                            {
                                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                                repmsg = $"狗狗不能吃疏菜水果類(蘋果、杏仁、桃子、野莓、苦瓜、李子類、梅子類)、香蕉、花椰菜、櫻桃、洋菇、肉荳蔻、洋蔥、葡萄葡、萄乾、梅子、巧克力、肝臟、骨頭、生雞蛋、豬肉、牛奶、菇類、酒,";
                                Uri dogcanteat = new Uri("https://maoup.com.tw/wp-content/uploads/2018/02/180118_1.png");
                                bot.PushMessage(UserId, dogcanteat);
                            }
                        }



                        else if (ret.TopScoringIntent.Name == "詢問牌子")
                        {
                            isRock.LineBot.Bot bot =
                                new isRock.LineBot.Bot(ChannelAccessToken);  //傳入Channel access token
                            var ImageCarouselColumn1 = new isRock.LineBot.ImageCarouselColumn
                            {
                                //設定圖片
                                imageUrl = new Uri("https://img1.momoshop.com.tw/goodsimg/0004/272/609/4272609_B.jpg?t=1507335911"),
                                //設定回覆動作
                                action = new isRock.LineBot.MessageAction()
                                {
                                    label = "愛肯拿", text = "愛肯拿"
                                }
                            };
                            var ImageCarouselColumn2 = new isRock.LineBot.ImageCarouselColumn
                            {
                                //設定圖片
                                imageUrl = new Uri("https://a.ecimg.tw/items/DEBV6RA90078EG9/000001_1478528276.jpg"),
                                //設定回覆動作
                                action = new isRock.LineBot.MessageAction()
                                {
                                    label = "法國皇家", text = "法國皇家"
                                }
                            };
                            var ImageCarouselColumn3 = new isRock.LineBot.ImageCarouselColumn
                            {
                                //設定圖片
                                imageUrl = new Uri("https://a.ecimg.tw/items/DEBV6RA90078EG9/000001_1478528276.jpg"),
                                //設定回覆動作
                                action = new isRock.LineBot.MessageAction()
                                {
                                    label = "希爾思", text = "希爾思"
                                }
                            };
                            var ImageCarouselColumn4 = new isRock.LineBot.ImageCarouselColumn
                            {
                                //設定圖片
                                imageUrl = new Uri("https://a.ecimg.tw/items/DEBV6RA90078EG9/000001_1478528276.jpg"),
                                //設定回覆動作
                                action = new isRock.LineBot.MessageAction()
                                {
                                    label = "海洋之心", text = "海洋之心"
                                }
                            };
                            var ImageCarouselColumn5 = new isRock.LineBot.ImageCarouselColumn
                            {
                                //設定圖片
                                imageUrl = new Uri("https://a.ecimg.tw/items/DEBV6RA90078EG9/000001_1478528276.jpg"),
                                //設定回覆動作
                                action = new isRock.LineBot.MessageAction()
                                {
                                    label = "貝斯比", text = "貝斯比"
                                }
                            };
                            var ImageCarouselColumn6 = new isRock.LineBot.ImageCarouselColumn
                            {
                                //設定圖片
                                imageUrl = new Uri("https://a.ecimg.tw/items/DEBV6RA90078EG9/000001_1478528276.jpg"),
                                //設定回覆動作
                                action = new isRock.LineBot.MessageAction()
                                {
                                    label = "柏萊富", text = "柏萊富"
                                }
                            };
                            var ImageCarouselTemplate = new isRock.LineBot.ImageCarouselTemplate();

                            //這是範例,所以用一組樣板建立三個
                            ImageCarouselTemplate.columns.Add(ImageCarouselColumn1);
                            ImageCarouselTemplate.columns.Add(ImageCarouselColumn2);
                            ImageCarouselTemplate.columns.Add(ImageCarouselColumn3);
                            ImageCarouselTemplate.columns.Add(ImageCarouselColumn4);
                            ImageCarouselTemplate.columns.Add(ImageCarouselColumn5);
                            ImageCarouselTemplate.columns.Add(ImageCarouselColumn6);
                            //發送 CarouselTemplate
                            bot.PushMessage(AdminUserId, ImageCarouselTemplate);
                            repmsg = $"以上是部分狗糧的牌子";
                        }



                        //回覆
                        this.ReplyMessage(LineEvent.replyToken, repmsg);
                    }
                }

                //response OK
                return(Ok());
            }

            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
Example #8
0
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                if (LineEvent.type == "message")
                {
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        string repmsg = "";

                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc = new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);
                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;
                        if (ret.Intents.Count() <= 0)
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但我看不懂喔!";
                        }
                        else if (ret.TopScoringIntent.Name == "None")
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔!";
                        }
                        else
                        {
                            repmsg = $"你想的是 '{ret.TopScoringIntent.Name}'";
                            if (ret.Entities.Count > 0)
                            {
                                foreach (var item in ret.Entities)
                                {
                                    repmsg += $"\n關鍵字 '{ item.Key  }'  ,  '{ item.Value.FirstOrDefault().Value}' ";
                                }
                            }
                            // repmsg += $"想要的是 '{ ret.Entities.FirstOrDefault().Value.FirstOrDefault().Value}' ";
                        }



                        bool flag = true;

                        /*
                         * var repo = new Finance();
                         * var UserInput = LineEvent.message.text;
                         * if(UserInput.Substring(0,4) == "我要記帳")
                         * {
                         *  try
                         *  {
                         *
                         *  var n = UserInput.Split(',');
                         *  var accounting = new Accounting();
                         *
                         *  accounting.MemberID = 1;
                         *  accounting.AccountingName = n[1];
                         *      string format = "yyyy-MM-dd HH:mm:ss";
                         *
                         *      accounting.AccountingTime = DateTime.ParseExact(n[2], "yyyy-MM-dd HH:mm:ss", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces);
                         *      accounting.AccountingCost = Convert.ToDecimal(n[3]);
                         *
                         *
                         *      repo.AccountingToDatabase(accounting);
                         *      repmsg = "你記錄了:" + accounting.AccountingName + " " + accounting.AccountingCost + " 元 , 在 " + accounting.AccountingTime + "購買的";
                         *
                         *  }
                         *  catch
                         *  {
                         *      repmsg = "紀錄時發生錯誤";
                         *  }
                         * }
                         * else if(UserInput.Substring(0, 8) == "我要查詢所有紀錄")
                         * {
                         *  try
                         *  {
                         *      var result = repo.GetAllRecord();
                         *      foreach(var item in result)
                         *      {
                         *          repmsg = "購買了:" + item.AccountingName + " " + item.AccountingCost + " 元 , 在 " + item.AccountingTime + "購買的";
                         *          this.PushMessage(AdminUserId, repmsg);
                         *          flag = false;
                         *      }
                         *  }
                         *  catch
                         *  {
                         *      repmsg = "查詢時發生錯誤 , 可能是您沒有紀錄";
                         *  }
                         * }
                         * else
                         * {
                         *  repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔!";
                         * }
                         */

                        //回覆
                        if (flag)
                        {
                            this.PushMessage(AdminUserId, repmsg);
                        }
                    }

                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                    if (LineEvent.message.type == "location")
                    {
                        this.ReplyMessage(LineEvent.replyToken, $"你的位置在\n{LineEvent.message.latitude} , {LineEvent.message.longitude} , {LineEvent.message.address}");
                    }
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
Example #9
0
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                if (LineEvent.type == "message")
                {
                    var repmsg = "";
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc =
                            new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);

                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;
                        if (ret.Intents.Count() <= 0)
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但我看不懂喔!";
                        }
                        else if (ret.TopScoringIntent.Name == "None")
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔!";
                        }
                        else
                        {
                            var EntityList = new List <string>();

                            foreach (var item in ret.Entities)
                            {
                                EntityList.Add(item.Value[0].Name);
                            }

                            /* foreach (var item in EntityList)
                             * {
                             *   repmsg += item + "-";
                             * }*/

                            if (ret.TopScoringIntent.Name == "訂單查詢")
                            {
                                var Service = new service();
                                var Order   = Service.OrderGetAll();
                                var List    = new List <string>();
                                if (ret.Entities.Count > 1)
                                {
                                    if (EntityList.Any((x) => x == "申請退貨"))
                                    {
                                        foreach (var item in Order)
                                        {
                                            if (item.Status == "申請退貨")
                                            {
                                                repmsg += item.OrderID;
                                            }
                                        }
                                    }
                                    if (EntityList.Any((x) => x == "訂單完成結案"))
                                    {
                                        foreach (var item in Order)
                                        {
                                            if (item.Status == "訂單完成結案")
                                            {
                                                repmsg += item.OrderID;
                                            }
                                        }
                                    }
                                    if (EntityList.Any((x) => x == "處理中"))
                                    {
                                        foreach (var item in Order)
                                        {
                                            if (item.Status == "處理中")
                                            {
                                                repmsg += item.OrderID;
                                            }
                                        }
                                    }
                                    if (EntityList.Any((x) => x == "已到貨"))
                                    {
                                        foreach (var item in Order)
                                        {
                                            if (item.Status == "已到貨")
                                            {
                                                repmsg += item.OrderID;
                                            }
                                        }
                                    }
                                    if (EntityList.Any((x) => x == "已出貨"))
                                    {
                                        foreach (var item in Order)
                                        {
                                            if (item.Status == "已出貨")
                                            {
                                                repmsg += item.OrderID;
                                            }
                                        }
                                    }
                                    if (EntityList.Any((x) => x == "申請取消"))
                                    {
                                        foreach (var item in Order)
                                        {
                                            if (item.Status == "申請取消")
                                            {
                                                repmsg += item.OrderID;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    var Total = Order.Count();
                                    repmsg = $"OK,{ret.TopScoringIntent.Name}: {Total.ToString()} 筆";
                                }
                            }
                            if (ret.TopScoringIntent.Name == "金額查詢")
                            {
                                var     Service       = new service();
                                var     Order_Details = Service.Order_DetailsGetAll();
                                var     Products      = Service.ProductsGetAll();
                                decimal Total         = 0;
                                foreach (var itemO in Order_Details)
                                {
                                    foreach (var itemP in Products)
                                    {
                                        if (itemO.ProductID == itemP.ProductID)
                                        {
                                            Total += itemO.Quantity * itemP.UnitPrice;
                                        }
                                    }
                                }

                                repmsg = $"OK,{ret.TopScoringIntent.Name}: {Decimal.Round(Total).ToString()} 元";
                            }
                            if (ret.TopScoringIntent.Name == "商品查詢")
                            {
                                var Service     = new service();
                                var Products    = Service.ProductsGetAll();
                                var Orderdetail = Service.Order_DetailsGetAll();
                                var Total       = Products.Count();

                                if (ret.Entities.Count > 1)
                                {
                                    var id = 0;
                                    if (EntityList.Any((x) => x == "最好"))
                                    {
                                        var Product   = Orderdetail.GroupBy((x) => x.ProductID).Select((y) => y.Sum((x) => x.Quantity)).Max();
                                        var Productid = Orderdetail.GroupBy((x) => x.ProductID).Where((y) => y.Sum((x) => x.Quantity) == Product).Select((z) => z.Select((x) => x.ProductID));
                                        foreach (var item in Productid)
                                        {
                                            foreach (var item_ in item)
                                            {
                                                id = item_;
                                            }
                                        }
                                        var i = Products.Where((x) => x.ProductID == id).Select((y) => y.ProductName);
                                        foreach (var item in i)
                                        {
                                            repmsg += item;
                                        }
                                    }
                                    if (EntityList.Any((x) => x == "最差"))
                                    {
                                        var Product   = Orderdetail.GroupBy((x) => x.ProductID).Select((y) => y.Sum((x) => x.Quantity)).Min();
                                        var Productid = Orderdetail.GroupBy((x) => x.ProductID).Where((y) => y.Sum((x) => x.Quantity) == Product).Select((z) => z.Select((x) => x.ProductID));
                                        foreach (var item in Productid)
                                        {
                                            foreach (var item_ in item)
                                            {
                                                id = item_;
                                            }
                                        }
                                        var i = Products.Where((x) => x.ProductID == id).Select((y) => y.ProductName);
                                        foreach (var item in i)
                                        {
                                            repmsg += item;
                                        }
                                    }
                                }
                                else
                                {
                                    repmsg = $"OK,{ret.TopScoringIntent.Name}: {Total.ToString()} 筆";
                                }
                            }
                            if (ret.TopScoringIntent.Name == "庫存查詢")
                            {
                                var Service  = new service();
                                var Products = Service.ProductsGetAll();
                                var Total    = 0;
                                foreach (var item in Products)
                                {
                                    Total += item.UnitsInStock;
                                }

                                repmsg = $"OK,{ret.TopScoringIntent.Name}: {Total.ToString()} 個";
                            }
                            if (ret.TopScoringIntent.Name == "客戶查詢")
                            {
                                var Service   = new service();
                                var Customers = Service.CustomerGetAll();
                                var Total     = Customers.Count();

                                repmsg = $"OK,{ret.TopScoringIntent.Name}: {Total.ToString()} 位";
                            }
                        }
                        //回覆
                        this.ReplyMessage(LineEvent.replyToken, repmsg);
                    }
                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                isRock.LineBot.Bot bot    = new isRock.LineBot.Bot(ChannelAccessToken);
                string             Lineid = ReceivedMessage.events.FirstOrDefault().source.userId;
                var Userinfo = bot.GetUserInfo(Lineid);
                if (LineEvent.type == "follow")
                {
                    this.ReplyMessage(LineEvent.replyToken, $"{Userinfo.displayName} 您好,\n謝謝您加我為好友!! 我可以回覆您任何問題!!\n下方'MORE'選單提供您更便利的購物流程!!");
                }
                if (LineEvent.type == "message")
                {
                    var repmsg = "";
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        //建立LuisClient
                        Microsoft.Cognitive.LUIS.LuisClient lc =
                            new Microsoft.Cognitive.LUIS.LuisClient(LuisAppId, LuisAppKey, true, Luisdomain);

                        //Call Luis API 查詢
                        var ret = lc.Predict(LineEvent.message.text).Result;
                        if (ret.Intents.Count() <= 0)
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但我看不懂喔!";
                        }
                        else if (ret.TopScoringIntent.Name == "None")
                        {
                            repmsg = $"你說了 '{LineEvent.message.text}' ,但不在我的服務範圍內喔! 期待您下次提問!!";
                            this.ReplyMessage(LineEvent.replyToken, repmsg);
                        }

                        else
                        {
                            if (ret.TopScoringIntent.Name == "會員問題")
                            {
                                var actions = new List <isRock.LineBot.TemplateActionBase>();

                                actions.Add(new isRock.LineBot.PostbackAction()
                                {
                                    label = "註冊", data = "歡迎您到官網點選右上角的 Sign up,填完資料點選註冊就完成囉。"
                                });
                                actions.Add(new isRock.LineBot.PostbackAction()
                                {
                                    label = "修改資料", data = "麻煩您到官網登入後,點選右上角的頭像標誌即可編輯資料。"
                                });
                                actions.Add(new isRock.LineBot.PostbackAction()
                                {
                                    label = "FB登入", data = "不好意思,目前尚未提供FB登入服務,麻煩您到官網完成註冊手續。"
                                });


                                var actions2 = new List <isRock.LineBot.TemplateActionBase>();
                                actions2.Add(new isRock.LineBot.PostbackAction()
                                {
                                    label = "忘記密碼", data = "非常抱歉我們目前不提供密碼提示,麻煩您再申請一個帳號,謝謝您。"
                                });
                                actions2.Add(new isRock.LineBot.PostbackAction()
                                {
                                    label = "折扣", data = "不好意思,我們目前沒有折扣的活動。"
                                });
                                actions2.Add(new isRock.LineBot.PostbackAction()
                                {
                                    label = "聯絡方式", data = "可以於周一 ~ 周五 09:00 ~ 18:00撥打客服專線03-512-3456或是寄 email 到 [email protected],將有專人為您服務。"
                                });

                                var CarouselTemplateMessage = new isRock.LineBot.CarouselTemplate();

                                var column1 = new isRock.LineBot.Column()
                                {
                                    text  = "這些是常見的會員問題,希望可以解決您的問題:)",
                                    title = "會員問題",
                                    //設定圖片
                                    thumbnailImageUrl = new Uri("https://images.unsplash.com/photo-1511822487717-d127fa0aa63d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a262d451dcc65e94722d66513b70100d&auto=format&fit=crop&w=1189&q=80"),
                                    actions           = actions //設定回覆動作
                                };
                                var column2 = new isRock.LineBot.Column()
                                {
                                    text  = "這些是常見的會員問題,希望可以解決您的問題:)",
                                    title = "會員問題",
                                    //設定圖片
                                    thumbnailImageUrl = new Uri("https://images.unsplash.com/photo-1511822487717-d127fa0aa63d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a262d451dcc65e94722d66513b70100d&auto=format&fit=crop&w=1189&q=80"),
                                    actions           = actions2 //設定回覆動作
                                };

                                CarouselTemplateMessage.columns.Add(column1);
                                CarouselTemplateMessage.columns.Add(column2);

                                //發送
                                this.ReplyMessage(LineEvent.replyToken, CarouselTemplateMessage);
                            }

                            if (ret.TopScoringIntent.Name == "商品問題")
                            {
                                foreach (var item in ret.Entities)
                                {
                                    if (item.Value.FirstOrDefault().Name == "上衣")
                                    {
                                        repmsg = $"這邊是我們上衣的頁面,歡迎參觀選購! http://jujube.azurewebsites.net/Products?CategoryName=TOP&Gender=MEN ,目前都是現貨供應中喲!!! 謝謝您 :)";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "下著")
                                    {
                                        repmsg = $"這邊是我們下著的頁面,歡迎參觀選購! http://jujube.azurewebsites.net/Products?CategoryName=BOTTOM&Gender=MEN ,目前都是現貨供應中喲!!!謝謝您 :)";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "連身")
                                    {
                                        repmsg = $"這邊是我們連身的頁面,歡迎參觀選購! http://jujube.azurewebsites.net/Products?CategoryName=JUMPSUIT&Gender=MEN ,目前都是現貨供應中喲!!!謝謝您 :)";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "內褲")
                                    {
                                        repmsg = $"不好意思,內褲還沒開賣,敬請期待,謝謝您 :)";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "特價")
                                    {
                                        repmsg = $"官網上顯示折扣的都是特價商品喲!!";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "新品")
                                    {
                                        repmsg = $"我們官網顯示在最上面的商品都是新貨唷!!";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "其他商品")
                                    {
                                        repmsg = $"不好意思,我們目前沒有提供此項商品喲!!";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "未知品牌")
                                    {
                                        repmsg = $"您好,我們目前沒有與其他品牌聯名,期待未來可以與他們合作,謝謝您的建議!!";
                                    }
                                }
                                this.ReplyMessage(LineEvent.replyToken, repmsg);
                            }

                            if (ret.TopScoringIntent.Name == "客訴行為")
                            {
                                foreach (var item in ret.Entities)
                                {
                                    if (item.Value.FirstOrDefault().Name == "嫌棄")
                                    {
                                        repmsg = $"不好意思,如果您不滿意的話,在七天鑑賞期之內都有提供退貨服務。謝謝您。";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "貨品延遲")
                                    {
                                        repmsg = $"不好意思,讓您等那麼久才收到商品,我們會向運輸公司反應。";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "純客訴")
                                    {
                                        repmsg = $"不好意思,要麻煩您於周一 ~ 周五 09:00 ~ 18:00 撥打客服專線 03-512-3456,或是寄 email 到 [email protected],將會有專人為您服務,謝謝您。";
                                    }
                                }
                                //發送
                                this.ReplyMessage(LineEvent.replyToken, repmsg);
                            }

                            if (ret.TopScoringIntent.Name == "購買問題")
                            {
                                foreach (var item in ret.Entities)
                                {
                                    if (item.Value.FirstOrDefault().Name == "訂單狀態")
                                    {
                                        repmsg = $"訂單一旦成立將無法更改,如果需要修改訂單,麻煩您先取消原訂單,再重新下單。";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "銷貨退回")
                                    {
                                        repmsg = $"先告知您,若商品以取貨超過七天鑑賞期、已下水清洗過、受損、無吊牌等情形,則無法申請退貨。\n" +
                                                 $"\n麻煩您先寄信到[email protected]或於周一~周五 09:00 ~ 18:00撥打客服專線03-512-3456,將有專人為您申辦退貨核准。\n" +
                                                 $"\n退貨流程:\n" +
                                                 $"登入會員 -> 訂單查詢 -> 點選該筆訂單的退貨按鈕 -> 填寫個人帳戶資料 -> 按下確認退貨按鈕,跳出完成退貨對話框即完成退貨手續。" +
                                                 $"宅配業者將會於3~5天內前往取貨(不需要另外收取費用)。\n" +
                                                 $"\n購物金:本店退貨後的款項將直接匯入您的個人帳戶。\n" +
                                                 $"期待您下次購買,謝謝您:)";
                                    }

                                    if (item.Value.FirstOrDefault().Name == "運送時間")
                                    {
                                        repmsg = $"現貨商品3~5天內會到貨;預購商品需要等7~15天不含假日喲!謝謝您。";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "預定購買")
                                    {
                                        repmsg = $"預購商品需要等7~15天不含假日喲。";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "運送費用")
                                    {
                                        repmsg = $"運費基本上一律以新台幣60元計算。";
                                    }
                                    if (item.Value.FirstOrDefault().Name == "購買證明")
                                    {
                                        repmsg = $"不好意思,本店小本經營尚未提供發票及統編服務。";
                                    }
                                }
                                //發送
                                this.ReplyMessage(LineEvent.replyToken, repmsg);
                            }
                        }
                    }
                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                }
                if (LineEvent.type == "postback")
                {
                    var data = LineEvent.postback.data;
                    this.ReplyMessage(LineEvent.replyToken, data);
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
        public IHttpActionResult POST()
        {
            string ChannelAccessToken = "WJ10DIkt+Y8abCGbAb/OmK/35F3iZ3h4xiB3CE8/B6SzkfTg4mLGonn/9nVI/P33o6+SnGwSBtKYjfa65YJSdfskV7Lf5RtWUAEmZajgARKdJva3ufd3cn7i/H4F/FXA685e75j18IsFjwDgSmugcQdB04t89/1O/w1cDnyilFU=";

            Microsoft.Cognitive.LUIS.LuisClient lc = new Microsoft.Cognitive.LUIS.LuisClient("ac6c1ff9-b031-4eff-bf31-442a202b1038", "61c5bbfb4ac5435b8f839a9528d50a46", true, "westus");

            Bot    LineBot  = new Bot(ChannelAccessToken);
            string postData = Request.Content.ReadAsStringAsync().Result;
            //剖析JSON
            var ReceivedMessage = Utility.Parsing(postData);
            var ReplyToken      = ReceivedMessage.events[0].replyToken;

            //取得用戶名稱
            //var UserName = LineBot.GetUserInfo(ReceivedMessage.events.FirstOrDefault().source.userId);

            //取得用戶ID
            var UserId = ReceivedMessage.events.FirstOrDefault().source.userId;
            //取得聊天室ID
            var RoomId = ReceivedMessage.events.FirstOrDefault().source.roomId;
            //取得群組ID
            var GroupId = ReceivedMessage.events.FirstOrDefault().source.groupId;
            var item    = ReceivedMessage.events[0];

            var weather_api = "https://works.ioa.tw/weather/api/all.json";

            try
            {
                LineUserInfo UserInfo = null;
                if (ReceivedMessage.events[0].type == "message")
                {
                    if (ReceivedMessage.events[0].message.type == "text")
                    {
                        var UserSays   = ReceivedMessage.events[0].message.text;
                        var LuisResult = lc.Predict(UserSays).Result;

                        if (UserSays == "安靜")
                        {
                            Global.quiet = true;
                            LineBot.ReplyMessage(ReplyToken, "找蟹安靜!!!");
                        }
                        else if (UserSays == "說話")
                        {
                            Global.quiet = false;
                        }

                        if (UserSays == "狀態")
                        {
                            if (Global.quiet == true)
                            {
                                LineBot.ReplyMessage(ReplyToken, "目前為安靜狀態");
                            }
                            else
                            {
                                LineBot.ReplyMessage(ReplyToken, "目前為說話狀態");
                            }
                        }
                        if (LuisResult.TopScoringIntent.Name == "詢問天氣" && LuisResult.TopScoringIntent.Score > 0.8)
                        {
                            if (LuisResult.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "淡水")
                            {
                                Global.id   = 50;
                                Global.city = "淡水";
                            }
                            else if (LuisResult.Entities.FirstOrDefault().Value.FirstOrDefault().Value == "北投")
                            {
                                Global.id   = 9;
                                Global.city = "北投";
                            }

                            var town_weather = "https://works.ioa.tw/weather/api/weathers/" + Global.id + ".json";

                            WebClient wc = new WebClient();
                            wc.Encoding = Encoding.UTF8;

                            string  jsonStr = wc.DownloadString(town_weather);
                            JObject obj     = JsonConvert.DeserializeObject <JObject>(jsonStr);

                            var desc          = "";
                            var temperature   = "";
                            var felt_air_temp = "";
                            var humidity      = "";
                            var rainfall      = "";
                            var sunrise       = "";
                            var sunset        = "";
                            var at            = "";

                            desc          = obj["desc"].ToString();
                            temperature   = obj["temperature"].ToString();
                            felt_air_temp = obj["felt_air_temp"].ToString();
                            humidity      = obj["humidity"].ToString();
                            rainfall      = obj["rainfall"].ToString();
                            sunrise       = obj["sunrise"].ToString();
                            sunset        = obj["sunset"].ToString();
                            at            = obj["at"].ToString();
                            LineBot.ReplyMessage(ReplyToken, Global.city + "\n" + "天氣:" + desc + "\n" + "溫度:" + temperature + "度\n" + "體感溫度:" + felt_air_temp + "度\n" + "雨量:" + rainfall + "\n" + "日出時間:" + sunrise + "\n" + "日落時間:" + sunset + "\n" + "最後更新時間:" + at + "\n" + "資料每30分鐘更新");
                        }
                        else if (ReceivedMessage.events[0].message.type == "text")
                        {
                            if (UserSays == "滾")
                            {
                                if (ReceivedMessage.events[0].source.type == "user")
                                {
                                    LineBot.PushMessage(UserId, "滾屁");
                                }
                                else if (ReceivedMessage.events[0].source.type == "room")
                                {
                                    UserInfo = Utility.GetRoomMemberProfile(RoomId, UserId, ChannelAccessToken);
                                    LineBot.PushMessage(RoomId, $"{UserInfo.displayName},我記住你了\n掰掰");
                                    Utility.LeaveRoom(RoomId, ChannelAccessToken);
                                }
                                else if (ReceivedMessage.events[0].source.type == "group")
                                {
                                    UserInfo = Utility.GetGroupMemberProfile(GroupId, UserId, ChannelAccessToken);
                                    LineBot.PushMessage(GroupId, $"{UserInfo.displayName},我記住你了\n掰掰");
                                    Utility.LeaveGroup(GroupId, ChannelAccessToken);
                                }
                            }

                            /*WebClient wc = new WebClient();
                             * wc.Encoding = Encoding.UTF8;
                             *
                             * string jsonStr = wc.DownloadString(weather_api);
                             *
                             * JArray array = JsonConvert.DeserializeObject<JArray>(jsonStr);
                             *
                             * int i=0, j=0;
                             *
                             * JObject obj = (JObject)array[i];
                             *
                             * var name = obj["name"].ToString();
                             * var towns = obj["towns"][j]["name"].ToString();
                             *
                             * LineBot.PushMessage(UserId, name + "\n" + towns);*/
                        }
                        if (Global.quiet == true)
                        {
                        }
                        else if (Global.quiet == false)
                        {
                            if (ReceivedMessage.events[0].message.type == "text")
                            {
                                if (LuisResult.TopScoringIntent.Name == "尋找葛格" && LuisResult.TopScoringIntent.Score > 0.8)
                                {
                                    LineBot.ReplyMessage(ReplyToken, "嘿嘿嘿!怎麼啦?\n需要葛格提供你什麼服務嗎");
                                    if (ReceivedMessage.events[0].source.type == "user")
                                    {
                                        LineBot.PushMessage(UserId, $"這是一個天氣預報機器人\n在群組或聊天室裡說'滾'我就會離開喔\n希望能幫到你");
                                        LineBot.PushMessage(UserId, 1, 2);
                                    }
                                    else if (ReceivedMessage.events[0].source.type == "room")
                                    {
                                        LineBot.PushMessage(RoomId, $"這是一個天氣預報機器人\n在群組或聊天室裡說'滾'我就會離開喔\n希望能幫到你");
                                        LineBot.PushMessage(RoomId, 1, 2);
                                    }
                                    else if (ReceivedMessage.events[0].source.type == "group")
                                    {
                                        LineBot.PushMessage(GroupId, $"這是一個天氣預報機器人\n在群組或聊天室裡說'滾'我就會離開喔\n希望能幫到你");
                                        LineBot.PushMessage(GroupId, 1, 2);
                                    }
                                }
                                else if (LuisResult.TopScoringIntent.Name == "None" || LuisResult.TopScoringIntent.Score < 0.8)
                                {
                                    if (ReceivedMessage.events[0].source.type == "user")
                                    {
                                        LineBot.ReplyMessage(ReplyToken, UserSays);
                                    }
                                    else if (ReceivedMessage.events[0].source.type == "room")
                                    {
                                        LineBot.ReplyMessage(ReplyToken, UserSays);
                                    }
                                    else if (ReceivedMessage.events[0].source.type == "group")
                                    {
                                        LineBot.ReplyMessage(ReplyToken, UserSays);
                                    }
                                }
                            }
                        }
                    }
                    else if (ReceivedMessage.events[0].message.type == "sticker")
                    {
                        if (Global.quiet == true)
                        {
                        }
                        else if (Global.quiet == false)
                        {
                            string botMessage = "機器人看不懂貼圖你還傳";
                            if (ReceivedMessage.events[0].source.type == "user")
                            {
                                LineBot.PushMessage(UserId, botMessage);
                                LineBot.PushMessage(UserId, 3, 185);
                            }
                            else if (ReceivedMessage.events[0].source.type == "room")
                            {
                                LineBot.PushMessage(RoomId, botMessage);
                                LineBot.PushMessage(RoomId, 3, 185);
                            }
                            else if (ReceivedMessage.events[0].source.type == "group")
                            {
                                LineBot.ReplyMessage(ReplyToken, botMessage);
                                LineBot.PushMessage(GroupId, 3, 185);
                            }
                        }
                    }
                }
                else if (ReceivedMessage.events[0].type == "follow")
                {
                    UserInfo = Utility.GetUserInfo(ReceivedMessage.events[0].source.userId, ChannelAccessToken);
                    LineBot.PushMessage(UserId, $"{UserInfo.displayName},我來了!!!");
                }
                else if (ReceivedMessage.events[0].type == "join")
                {
                    if (ReceivedMessage.events[0].source.type == "room")
                    {
                        LineBot.PushMessage(RoomId, $"我來了!!!");
                    }
                    else if (ReceivedMessage.events[0].source.type == "group")
                    {
                        LineBot.PushMessage(GroupId, $"我來了!!!");
                    }
                }
                else
                {
                    string Message = ReceivedMessage.events[0].type;
                    LineBot.ReplyMessage(ReplyToken, postData);
                }
                //回覆API OK
                return(Ok());
            }
            catch (Exception ex)
            {
                string Message = "我錯了,錯在\n" + ex.Message;
                //回覆用戶
                LineBot.ReplyMessage(ReplyToken, Message);
                return(Ok());
            }
        }