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 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));
            }
        }
예제 #3
0
 public IHttpActionResult Post()
 {
     try
     {
         string ChannelAccessToken = db.GetBotToken("Line");
         string postData           = Request.Content.ReadAsStringAsync().Result;
         var    ReceivedMessage    = isRock.LineBot.Utility.Parsing(postData);
         string Message            = "你說了:" + ReceivedMessage.events[0].message.text;
         isRock.LineBot.Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, Message, 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));
     }
 }