public async Task GetProfile_UserIdIsEmpty_ThrowsException()
 {
     ILineBot bot = TestConfiguration.CreateBot();
     await ExceptionAssert.ThrowsArgumentEmptyExceptionAsync("userId", async() =>
     {
         IUserProfile profile = await bot.GetProfile(string.Empty);
     });
 }
 public async Task GetProfile_UserIsNulll_ThrowsException()
 {
     ILineBot bot = TestConfiguration.CreateBot();
     await ExceptionAssert.ThrowsArgumentNullExceptionAsync("user", async() =>
     {
         IUserProfile profile = await bot.GetProfile((IUser)null);
     });
 }
        public async Task GetProfile_WithUser_ReturnsUserProfile()
        {
            TestHttpClient httpClient = TestHttpClient.Create(JsonDocuments.UserProfile);

            ILineBot     bot     = TestConfiguration.CreateBot(httpClient);
            IUserProfile profile = await bot.GetProfile(new TestUser());

            Assert.AreEqual("/profile/testUser", httpClient.RequestPath);
            Assert.IsNotNull(profile);
        }
        public async Task GetProfile_ErrorResponse_ThrowsException()
        {
            TestHttpClient httpClient = TestHttpClient.ThatReturnsAnError();

            ILineBot bot = TestConfiguration.CreateBot(httpClient);

            await ExceptionAssert.ThrowsUnknownError(async() =>
            {
                await bot.GetProfile("test");
            });
        }
        public async Task GetProfile_CorrectResponse_ReturnsUserProfile()
        {
            TestHttpClient httpClient = TestHttpClient.Create(JsonDocuments.UserProfile);

            ILineBot     bot     = TestConfiguration.CreateBot(httpClient);
            IUserProfile profile = await bot.GetProfile("test");

            Assert.AreEqual(HttpMethod.Get, httpClient.RequestMethod);
            Assert.AreEqual("/profile/test", httpClient.RequestPath);

            Assert.IsNotNull(profile);
            Assert.AreEqual("LINE taro", profile.DisplayName);
            Assert.AreEqual(new Uri("http://obs.line-apps.com/..."), profile.PictureUrl);
            Assert.AreEqual("Hello, LINE!", profile.StatusMessage);
            Assert.AreEqual("Uxxxxxxxxxxxxxx...", profile.UserId);
        }
        public async Task Handle(ILineBot lineBot, ILineEvent evt)
        {
            if (string.IsNullOrEmpty(evt.Message.Text))
            {
                return;
            }

            // The Webhook URL verification uses these invalid token.
            if (evt.ReplyToken == "00000000000000000000000000000000" || evt.ReplyToken == "ffffffffffffffffffffffffffffffff")
            {
                return;
            }

            if (evt.Message.Text.ToLowerInvariant().Contains("ping"))
            {
                var response = new TextMessage($"pong");

                await lineBot.Reply(evt.ReplyToken, response);
            }
            else if (evt.Message.Text.ToLowerInvariant().Contains("user"))
            {
                var userName = evt.Source.User.Id;
                try
                {
                    var user = await lineBot.GetProfile(evt.Source.User);

                    userName = $"{user.DisplayName} ({user.UserId})";
                }
                catch (LineBotException)
                {
                }

                var response = new TextMessage($"You are: {userName}");

                await lineBot.Reply(evt.ReplyToken, response);
            }
            else if (evt.Message.Text.ToLowerInvariant().Contains("logo"))
            {
                var logoUrl = this.configuration.ResourcesUrl + "/Images/Line.Bot.SDK.png";

                Console.WriteLine(logoUrl);
                var response = new ImageMessage(logoUrl, logoUrl);

                await lineBot.Reply(evt.ReplyToken, response);
            }
        }
Example #7
0
        public async Task Handle(ILineBot lineBot, ILineEvent evt)
        {
            string userName = "******";

            try
            {
                var user = await lineBot.GetProfile(evt.Source.User);

                userName = $"{user.DisplayName} ({user.UserId})";
            }
            catch (LineBotException)
            {
            }

            var response = new TextMessage($"Welcome, {userName} !");

            await lineBot.Reply(evt.ReplyToken, response);
        }