//content

        /// <summary>
        /// 回覆訊息
        /// </summary>
        /// <param name="replyMessageBody">回覆訊息body資料</param>
        public async Task ReplyMessageAsync(ReplyMessageModel replyMessageBody)
        {
            string jsonString = JsonConvert.SerializeObject(replyMessageBody, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None
            });

            await Utility.DoLineHttpPostAsync(MessagingApiUrl.ReplyUrl, jsonString, accessToken);
        }
Example #2
0
        public FeedDetailsViewModel(PostMessageModel postMessage)
        {
            //Pull all ReplyMessageModels from the database where ReplyMessageModel.PostMessageId == postMessage.Id
            PostUserProfileUrl = postMessage.PostUser.PictureUrl;
            PostUserName       = postMessage.PostUser.Name;
            PostUserPostText   = postMessage.PostText;

            if (postMessage.NumberOfReplies == 1)
            {
                NumberOfReplies = $"{postMessage.NumberOfReplies} Reply";
            }
            else
            {
                NumberOfReplies = $"{postMessage.NumberOfReplies} Replies";
            }

            PostButtonCommand = new Command(() =>
            {
                var dummyPostMessage = new ReplyMessageModel
                {
                    Id        = "This was created via Command",
                    ReplyText = "This was created via Command",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "http://www.profightdb.com/img/wrestlers/thumbs-600/6baee11272the-rock.jpg",
                    }
                };

                FeedDetailsListViewItemSource.Add(dummyPostMessage);
            });

            FeedDetailsListViewItemSource = new ObservableCollection <ReplyMessageModel>
            {
                new ReplyMessageModel
                {
                    ReplyText = "And the only way to do great work is to love what you do. ",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "http://www.profightdb.com/img/wrestlers/thumbs-600/6baee11272the-rock.jpg",
                    }
                },
                new ReplyMessageModel
                {
                    ReplyText = "Everything around you that you call life was made up by people that were no smarter than you",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "https://cdn.inquisitr.com/wp-content/uploads/2016/04/kylie-jenner-paper-photoshoot.png"
                    }
                },
                new ReplyMessageModel
                {
                    ReplyText = "What's the best pizza joint around campus? ",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "https://healthyceleb.com/wp-content/uploads/2016/07/Kevin-Hart-headshot.jpg",
                    }
                },
                new ReplyMessageModel
                {
                    ReplyText = "Everything around you that you call life was made up by people that were no smarter than you",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "https://i.ytimg.com/vi/RnSgCv2X0ns/hqdefault.jpg",
                    }
                },
                new ReplyMessageModel
                {
                    ReplyText = "Everything around you that you call life was made up by people that were no smarter than you",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "http://www.profightdb.com/img/wrestlers/thumbs-600/6baee11272the-rock.jpg",
                    }
                },
                new ReplyMessageModel
                {
                    ReplyText = "Everything around you that you call life was made up by people that were no smarter than you",
                    ReplyUser = new UserProfileModel
                    {
                        PictureUrl = "http://www.profightdb.com/img/wrestlers/thumbs-600/6baee11272the-rock.jpg",
                    }
                }
            };
        }
Example #3
0
        public async Task <IActionResult> Webhook()
        {
            HttpContext httpContext = HttpContext;

            LineMessagingClient client = new LineMessagingClient(accessToken);
            ReceiveEventModel   model  = await WebhookRequestMessage.GetWebhookEvent(httpContext, channelSecret);

            if (model == null)
            {
                return(BadRequest());
            }
            if (model.events == null)
            {
                return(BadRequest());
            }

            foreach (EventModel q in model.events)
            {
                string senderId = "";
                switch (q.source.type)
                {
                case SourceType.user:
                    senderId = q.source.userId;
                    break;

                case SourceType.room:
                    senderId = q.source.roomId;
                    break;

                case SourceType.group:
                    senderId = q.source.groupId;
                    break;
                }

                if (q.type == EventType.message)
                {
                    MessageEventTypeUtility messageEventTypeUtility = new MessageEventTypeUtility(accessToken);

                    #region ReplyMessage

                    /*ReplyMessageModel replyMessageBody = new ReplyMessageModel()
                     * {
                     *  replyToken = q.replyToken,
                     *  messages = await messageEventTypeUtility.AutoProcessMessageType(q.message)
                     * };
                     *
                     * await client.ReplyMessageAsync(replyMessageBody);*/
                    #endregion

                    #region ReplyMessageWithJson
                    await client.ReplyMessageWithJsonAsync(q.replyToken, await messageEventTypeUtility.AutoProcessMessageTypeWithJson(q.message));

                    #endregion

                    //await client.ReplyMessageWithJsonAsync(q.replyToken, new ApparelFlexMessage().Create2());

                    #region push message

                    /*PushMessageModel pushMessageBody = new PushMessageModel()
                     * {
                     *  to = "someone's UID",
                     *  messages = messageEventTypeUtility.PushMessageType()
                     * };
                     * await client.PushMessageAsync(pushMessageBody);*/
                    #endregion

                    #region broadcast message

                    /*BroadcastModel broadcast = new BroadcastModel()
                     * {
                     *  messages = messageEventTypeUtility.BroadcastMessageType()
                     * };
                     * await client.BroadcastMessageAsync(broadcast);*/
                    #endregion

                    Console.WriteLine("Sender: " + senderId);
                    Console.WriteLine("Message: " + q.message.text);
                }
                else if (q.type == EventType.follow)
                {
                    MessageEventTypeUtility messageEventTypeUtility  = new MessageEventTypeUtility(accessToken);
                    FollowEventTypeUtility  followEventTypeProcessor = new FollowEventTypeUtility(accessToken);

                    UserProfileResponseModel profileModel = await followEventTypeProcessor.GetProfileAsync(q.source.userId);

                    string text = $"Welcome, {profileModel.displayName}";

                    ReplyMessageModel replyMessageBody = new ReplyMessageModel()
                    {
                        replyToken = q.replyToken,
                        messages   = messageEventTypeUtility.CreateTextMessage(text)
                    };

                    await client.ReplyMessageAsync(replyMessageBody);
                }
            }

            return(Ok());
        }