예제 #1
0
        public async Task <HttpResponseMessage> Post([FromBody] string request)
        {
            // do some thing
            if (request != null)
            {
                string temp = request.ToString();

                Event   ev = new Event();
                Message m  = new Message();
                m.Id   = "325708";
                m.Type = MessageType.Text;

                ev.Message    = m;
                ev.ReplyToken = @"VC/sPEIz8O7WYo0THlaM5laorgw+GifJmN8cFR5eZ0seYxNsR3ZOVblQgOeI8xNaCOyTsUz2VsajbtAyt8hj7+NdP2/oYB+7eQ/FGnEAN/ICGCPj5nX36E848piCYi16BPkXlDR3N0CDiPnrfbpPcAdB04t89/1O/w1cDnyilFU=";


                LineMessageHandler handler1 = new LineMessageHandler(ev);
                //return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
                await handler1.HandleTextMessage();

                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
            }
            else
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotAcceptable));
            }
        }
예제 #2
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post()
        {
            //HttpRequestMessage request
            //if (!await VaridateSignature(request))
            //	return new HttpResponseMessage(HttpStatusCode.BadRequest);
            Activity activity = new Activity();

            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                activity = JsonConvert.DeserializeObject <Activity> (await reader.ReadToEndAsync());
            }


            // Line may send multiple events in one message, so need to handle them all.
            foreach (Event lineEvent in activity.Events)
            {
                LineMessageHandler handler = new LineMessageHandler(lineEvent);

                Profile profile = await handler.GetProfile(lineEvent.Source.UserId);

                switch (lineEvent.Type)
                {
                case EventType.Beacon:
                    await handler.HandleBeaconEvent();

                    break;

                case EventType.Follow:
                    await handler.HandleFollowEvent();

                    break;

                case EventType.Join:
                    await handler.HandleJoinEvent();

                    break;

                case EventType.Leave:
                    await handler.HandleLeaveEvent();

                    break;

                case EventType.Message:
                    Message message = JsonConvert.DeserializeObject <Message>(lineEvent.Message.ToString());
                    switch (message.Type)
                    {
                    case MessageType.Text:
                        await handler.HandleTextMessage();

                        break;

                    case MessageType.Audio:
                    case MessageType.Image:
                    case MessageType.Video:
                        await handler.HandleMediaMessage();

                        break;

                    case MessageType.Sticker:
                        await handler.HandleStickerMessage();

                        break;

                    case MessageType.Location:
                        await handler.HandleLocationMessage();

                        break;
                    }
                    break;

                case EventType.Postback:
                    await handler.HandlePostbackEvent();

                    break;

                case EventType.Unfollow:
                    await handler.HandleUnfollowEvent();

                    break;
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }