Exemple #1
0
        public void ValidateSignatureTest()
        {
            var e = "{\"events\":[{\"replyToken\":\"00000000000000000000000000000000\",\"type\":\"message\",\"timestamp\":1451617200000,\"source\":{\"type\":\"user\",\"userId\":\"Udeadbeefdeadbeefdeadbeefdeadbeef\"},\"message\":{\"id\":\"100001\",\"type\":\"text\",\"text\":\"Hello,world\"}},{\"replyToken\":\"ffffffffffffffffffffffffffffffff\",\"type\":\"message\",\"timestamp\":1451617210000,\"source\":{\"type\":\"user\",\"userId\":\"Udeadbeefdeadbeefdeadbeefdeadbeef\"},\"message\":{\"id\":\"100002\",\"type\":\"sticker\",\"packageId\":\"1\",\"stickerId\":\"1\"}}]}";
            var c = new LineClient("channel_id", "9a6f07fc8f2d3723fd1ac2ab3411e38e", "channel_access_tokn");

            Assert.IsTrue(c.ValidateSignature(e, "cRUG4B7ACUM0Z1UefRxcXynmPEHmzcw7RkXN6Z/HuGs="));
        }
Exemple #2
0
        static async Task Main(string[] args)
        {
            DotNetEnv.Env.Load();
            string TWITTER     = Environment.GetEnvironmentVariable("TWITTER_TOKEN");
            string TWITTER_URL = Environment.GetEnvironmentVariable("TWITTER_URL");
            string LINE_TOKEN  = Environment.GetEnvironmentVariable("LINE_TOKEN");
            string LINE_URL    = Environment.GetEnvironmentVariable("LINE_URL");

            LineClient            client        = new LineClient(LINE_URL, LINE_TOKEN);
            TwitterClient <Tweet> twitterClient = new TwitterClient <Tweet>(TWITTER, TWITTER_URL, client);

            while (true)
            {
                try
                {
                    await twitterClient.Stream();
                }
                catch (IOException e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Attempting to reconnect waiting 10 second.");
                    System.Threading.Thread.Sleep(10000);
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Attempting to reconnect waiting 10 second.");
                    System.Threading.Thread.Sleep(10000);
                }
            }
        }
Exemple #3
0
        public RPSController()
        {
            var channelId     = Environment.GetEnvironmentVariable("LINE_CHANNEL_ID");
            var channelSecret = Environment.GetEnvironmentVariable("LINE_CHANNEL_SECRET");
            var accessToken   = Environment.GetEnvironmentVariable("LINE_CHANNEL_ACCESS_TOKEN");

            Client = new LineClient(channelId, channelSecret, accessToken);
        }
Exemple #4
0
 public Form1()
 {
     try
     {
         _line = new LineClient("*****@*****.**", "30072528");
     }
     catch { }
     _line = new LineClient(_line.AuthToken);
     InitializeComponent();
     ConnectAsync();
 }
        public RichMenuController()
        {
            var channelId     = Environment.GetEnvironmentVariable("LINE_CHANNEL_ID");
            var channelSecret = Environment.GetEnvironmentVariable("LINE_CHANNEL_SECRET");
            var accessToken   = Environment.GetEnvironmentVariable("LINE_CHANNEL_ACCESS_TOKEN");

            channelId     = "1489026731";
            channelSecret = "b03ae87de61f2d0c94c75adbb5bb33bb";
            accessToken   = "UcaBvvitF/5YLrh97p3vAXVX4qROTtHAEc4aWhwukt3mWFXl0YzGCeUHJrKhdWXdmwgDG3mNMmb7aEPp3u1rIwEK04/lmM83PiZClWnYeM2TwSvhpNyPQ0T/Tn09PG/BBI7GEdpiN7/7LJb+UTqhUgdB04t89/1O/w1cDnyilFU=";

            Client = new LineClient(channelId, channelSecret, accessToken);
        }
Exemple #6
0
        public async Task <IActionResult> GetAllLines(string getStops = "")
        {
            try
            {
                var result = await LineClient.GetAllLines(getStops);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #7
0
        public async Task <IActionResult> GetStopsFromLine(string lineNumber, string direction = "0", string getIncoming = "")
        {
            try
            {
                var result = await LineClient.GetStopsFromLine(lineNumber, direction, getIncoming);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #8
0
        private async Task Notify(List <Message> messages, string mids, int lcid)
        {
            LineClient lineClient = new LineClient(ConfigurationManager.AppSettings["ChannelToken"].ToString());

            foreach (var mid in mids.Split(','))
            {
                PushMessage pushMessage = new PushMessage()
                {
                    Messages = messages,
                    To       = mid
                };
                await lineClient.PushAsync(pushMessage);
            }
        }
Exemple #9
0
        public async Task <IActionResult> LocateBuses(string lineNumber, string direction = "0")
        {
            try
            {
                var line = await LineClient.GetStopsFromLine(lineNumber, direction, "filter");

                var locatedBuses = Locate.LocateBusesFromLine(line);

                return(Ok(locatedBuses));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #10
0
 public async Task <Profile> GetProfile(string mid)
 {
     lineClient = new LineClient(channelToken);
     return(await lineClient.GetProfile(mid));
 }
Exemple #11
0
 protected void Application_Start()
 {
     LineClient.Initialize();
     GlobalConfiguration.Configure(WebApiConfig.Register);
 }
        public void ConnectLine(string user, string password)
        {
            line          = new LineClient();
            line.OnLogin += new LineClient.LoggedInEvent((Result loginResult) =>
            {
                //Everything worked
                if (loginResult == Result.OK)
                {
                    Console.WriteLine("Authed successfully!");
                    List <LineSharp.Common.Contact> contacts = line.GetContacts(line.GetContactIDs());
                    foreach (LineSharp.Common.Contact ct in contacts.FindAll(x => x.Name.ToLower().Contains("wii")))
                    {
                        line.SendMessage(ct.ID, "我登入了系統");
                    }
                }
                //Phone verification needed
                else if (loginResult == Result.REQUIRES_PIN_VERIFICATION)
                {
                    //The user then is required to enter the pin (retrieved from calling
                    string pin = line.Pin;
                    //)

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Verify your account on your mobile device using PIN: " + pin);
                    Console.WriteLine("It times out after about 3 minutes.");
                    Console.ForegroundColor = ConsoleColor.White;

                    //Then call this function, then enter the pin on the mobile device.
                    line.VerifyPin();
                    //WARNING: This function will hang until the pin verifies.
                }
                else
                {
                    Console.WriteLine("Did not auth successfully. Paused.");
                    Console.Read();
                    Environment.Exit(0);
                }
            });

            line.OnPinVerified += new LineClient.PinVerifiedEvent((Result pinVerifiedResult, string verifierToken) =>
            {
                //The pin was verified, or it had timed out???
                if (pinVerifiedResult == Result.OK)
                {
                    //Success. Log in using this. After logging in this way, if there's a certificate, you should
                    //save that somewhere and use it to log in again, because apparently it's nice not to have to
                    //verify your pin every single time. I'll implement logging in and using a cert later though.

                    line.Login("*****@*****.**", "chungyih", verifierToken);
                    // :P
                }
            });

            line.OnReceiveMessage += (o, eventArgs) =>
            {
                Console.WriteLine(eventArgs.Message.Text);
                line.SendMessage(eventArgs.Message.From, @"我收到您的訊息了, 稍候給您回覆" + Environment.NewLine + @"謝謝");
            };

            line.OnNotifiedReceivedCall += (o, eventArgs) =>
            {
                Console.WriteLine("[LineSharp] Got a call from " + line.GetContact(eventArgs.Operation.Param1).Name);
                line.SendMessage(eventArgs.Operation.Param1, @"很抱歉, 我無法接聽電話" + Environment.NewLine + @"請留言");
            };

            //line.Login("*****@*****.**", "chungyih", "qg2tNEsgGGgfTyiuL2IjNxjTAJpW7R0d");
            line.Login(user, password);
            while (true)
            {
                line.Update();
            }
            //Console.Read();
            //Line.Logout();
        }
Exemple #13
0
 public PushClient(LineClient client)
 {
     _client = client;
 }
Exemple #14
0
        public void Notify(string destination, List <EventItem> events)
        {
            try
            {
                LogNotify(destination, events);
                string[] specificChannelKeywords = new[] { "camera", "cam", "c", "picture", "pic", "p", "channel", "ch", "กล้อง" };

                string[]   interestEventTypes = new string[] { "follow", "message" };
                LineClient client             = new LineClient(_accessToken);
                foreach (var ev in events)
                {
                    if (!interestEventTypes.Contains(ev.type))
                    {
                        continue;
                    }
                    if (ev.source != null && ev.source.type == "user")
                    {
                        if (ev.message != null)
                        {
                            if (ev.message.type == "text")
                            {
                                var validCommand = false;
                                var comandBlocks = ev.message.text.Split(new char[] { ' ' });
                                if (comandBlocks.Length == 2)
                                {
                                    var key       = comandBlocks[0].Trim().ToLower();
                                    var channel   = comandBlocks[1].Trim();
                                    int channelId = 0;
                                    if (specificChannelKeywords.Contains(key) && int.TryParse(channel, out channelId))
                                    {
                                        _logger.Debug(string.Format("process-capture-command>> channel: {0}, mId:{1}", channelId, ev.message.id));
                                        var camera = GetCameraInfo(channelId);
                                        if (camera != null)
                                        {
                                            var imageUrl = GetCameraImage(camera.StillImageUrl, camera.UserName, camera.Password);
                                            if (!string.IsNullOrEmpty(imageUrl))
                                            {
                                                client.AddMessageQueue(new SendMessageItem
                                                {
                                                    type = "image",
                                                    originalContentUrl = imageUrl,
                                                    previewImageUrl    = imageUrl,
                                                });
                                                var replyRes = client.ReplyToUser(ev.replyToken);
                                                validCommand = true;
                                                _logger.Debug("reply-image>>" + imageUrl + ", res:" + replyRes.Success.ToString() + ", msg:" + replyRes.Message);
                                            }
                                        }
                                    }
                                }

                                if (!validCommand)
                                {
                                    client.AddMessageQueue(new SendMessageItem
                                    {
                                        type = "text",
                                        text = "คำสังไม่ถูกต้อง หรือไม่พบช่องที่ระบุ กรุณาลองใหม่อีกครั้ง"
                                    });

                                    var replyRes = client.ReplyToUser(ev.replyToken);
                                    _logger.Debug("reply-invalid message>> " + ev.message.text + ", res:" + replyRes.Success.ToString() + ", msg:" + replyRes.Message);
                                }
                            }
                        }
                        else if (ev.type == "follow")
                        {
                            client.AddMessageQueue(new SendMessageItem
                            {
                                type = "text",
                                text = "ยินดีต้อนรับเข้าสู่ระบบดูภาพนิ่งจากกล้องผ่าน LINE\r\nคุณสามารถพิมพ์คำสั่งเพื่อดูกล้องได้ดังนี้\r\n\r\ncam [เลขที่]\r\ncamera [เลขที่]\r\npic [เลขที่]\r\npicture [เลขที่]"
                            });

                            var replyRes = client.ReplyToUser(ev.replyToken);
                            _logger.Debug("reply-greeting message>> res:" + replyRes.Success.ToString() + ", msg:" + replyRes.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Notify-incoming:" + "des:" + destination + ", error:" + ex.Message);
            }
        }
 public PushClient(LineClient client)
 {
     _client = client;
 }
Exemple #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("====Login====");
            Console.Write("Username: "******"Password (NOT MASKED): ");

            string password = Console.ReadLine();

            LineClient line = new LineClient();

            line.OnLogin += new LineClient.LoggedInEvent((Result loginResult) =>
            {
                //Everything worked
                if (loginResult == Result.OK)
                {
                    Console.WriteLine("Authed successfully!");
                    List <Contact> ct = line.GetContacts(line.GetContactIDs());

                    Console.WriteLine("Enter the name of a user you would like to send a 'Hi' to:");
                    string name = Console.ReadLine();

                    for (int i = 0; i < ct.Count; i++)
                    {
                        if (ct[i].Name.Contains(name))
                        {
                            line.SendMessage(ct[i].ID, "Hi!");
                        }
                    }
                }
                //Phone verification needed
                else if (loginResult == Result.REQUIRES_PIN_VERIFICATION)
                {
                    //The user then is required to enter the pin (retrieved from calling
                    string pin = line.Pin;
                    //)

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Verify your account on your mobile device using PIN: " + pin);
                    Console.WriteLine("It times out after about 3 minutes.");
                    Console.ForegroundColor = ConsoleColor.White;

                    //Then call this function, then enter the pin on the mobile device.
                    line.VerifyPin();
                    //WARNING: This function will hang until the pin verifies.
                }
                else
                {
                    Console.WriteLine("Did not auth successfully. Paused.");
                    Console.Read();
                    Environment.Exit(0);
                }
            });

            line.OnPinVerified += new LineClient.PinVerifiedEvent((Result pinVerifiedResult, string verifierToken) =>
            {
                //The pin was verified, or it had timed out???
                if (pinVerifiedResult == Result.OK)
                {
                    //Success. Log in using this. After logging in this way, if there's a certificate, you should
                    //save that somewhere and use it to log in again, because apparently it's nice not to have to
                    //verify your pin every single time. I'll implement logging in and using a cert later though.

                    line.Login(username, password, verifierToken);
                    // :P
                }
            });

            line.OnReceiveMessage += (o, eventArgs) => Console.WriteLine(eventArgs.Message.Text);

            line.Login(username, password);
            while (true)
            {
                line.Update();
            }
            //Console.Read();
            //Line.Logout();
        }
Exemple #17
0
        public void ParseTest()
        {
            var eventStr = ReadResource("events.json");
            var client   = new LineClient("xx", "xx", "xx");
            var events   = client.ParseEvent(eventStr).ToArray();

            Assert.IsInstanceOf <MessageEvent>(events[0]);
            var event0 = (MessageEvent)events[0];

            Assert.IsInstanceOf <UserSoruce>(event0.Source);
            Assert.IsInstanceOf <TextEventMessage>(event0.Message);

            Assert.IsInstanceOf <MessageEvent>(events[1]);
            var event1 = (MessageEvent)events[1];

            Assert.IsInstanceOf <UserSoruce>(event1.Source);
            Assert.IsInstanceOf <ImageEventMessage>(event1.Message);

            Assert.IsInstanceOf <MessageEvent>(events[2]);
            var event2 = (MessageEvent)events[2];

            Assert.IsInstanceOf <UserSoruce>(event2.Source);
            Assert.IsInstanceOf <VideoEventMessage>(event2.Message);

            Assert.IsInstanceOf <MessageEvent>(events[3]);
            var event3 = (MessageEvent)events[3];

            Assert.IsInstanceOf <UserSoruce>(event3.Source);
            Assert.IsInstanceOf <AudioEventMessage>(event3.Message);

            Assert.IsInstanceOf <MessageEvent>(events[4]);
            var event4 = (MessageEvent)events[4];

            Assert.IsInstanceOf <UserSoruce>(event4.Source);
            Assert.IsInstanceOf <LocationEventMessage>(event4.Message);

            Assert.IsInstanceOf <MessageEvent>(events[5]);
            var event5 = (MessageEvent)events[5];

            Assert.IsInstanceOf <UserSoruce>(event5.Source);
            Assert.IsInstanceOf <StickerEventMessage>(event5.Message);

            Assert.IsInstanceOf <FollowEvent>(events[6]);
            var event6 = (FollowEvent)events[6];

            Assert.IsInstanceOf <UserSoruce>(event6.Source);

            Assert.IsInstanceOf <UnfollowEvent>(events[7]);
            var event7 = (UnfollowEvent)events[7];

            Assert.IsInstanceOf <UserSoruce>(event7.Source);

            Assert.IsInstanceOf <JoinEvent>(events[8]);
            var event8 = (JoinEvent)events[8];

            Assert.IsInstanceOf <GroupSoruce>(event8.Source);

            Assert.IsInstanceOf <LeaveEvent>(events[9]);
            var event9 = (LeaveEvent)events[9];

            Assert.IsInstanceOf <GroupSoruce>(event9.Source);

            Assert.IsInstanceOf <PostbackEvent>(events[10]);
            var event10 = (PostbackEvent)events[10];

            Assert.IsInstanceOf <UserSoruce>(event10.Source);
            Assert.AreEqual("action=buyItem&itemId=123123&color=red", event10.Postback.Data);

            Assert.IsInstanceOf <BeaconEvent>(events[11]);
            var event11 = (BeaconEvent)events[11];

            Assert.IsInstanceOf <UserSoruce>(event11.Source);
            Assert.AreEqual("d41d8cd98f", event11.Beacon.Hwid);
        }