public IHttpActionResult Post([FromBody] LineModel.LineMessage data)
        {
            if (data == null)
            {
                return(BadRequest());
            }
            if (data.events == null)
            {
                return(BadRequest());
            }
            // 加入對談清單
            foreach (LineModel.LineMessage.Event e in data.events)
            {
                new ConversationObj().AddLine(e.replyToken, e.source.userId);

                if (e.type == LineModel.LineMessage.EventType.message)
                {
                    LineModel.LineReply rb = new LineModel.LineReply()
                    {
                        replyToken = e.replyToken,
                        messages   = procMessage(e.message)
                    };
                    Reply reply = new Reply(rb);
                    reply.Send();
                }
            }
            return(Ok(data));
        }
Exemplo n.º 2
0
 private void SendLineMessage(ConversationFile data)
 {
     LineModel.LineReply rb = new LineModel.LineReply()
     {
         replyToken = data.ConversationId,
         messages   = new List <LineModel.SendMessage>()
         {
             new LineModel.SendMessage()
             {
                 text = "test", type = "text"
             }
         },
     };
     LineMessagesController.Reply reply = new LineMessagesController.Reply(rb);
     reply.Send();
 }
            public Reply(LineModel.LineReply body)
            {
                //--- set header and body required infos ---
                req             = WebRequest.Create(API_URL);
                req.Method      = "POST";
                req.ContentType = "application/json";
                req.Headers["Authorization"] = "Bearer " + ConfigurationManager.AppSettings["LineMID"].ToString();

                // --- format to json and add to request body ---
                using (var streamWriter = new StreamWriter(req.GetRequestStream()))
                {
                    string data = JsonConvert.SerializeObject(body);
                    streamWriter.Write(data);
                    streamWriter.Flush();
                }
            }