Example #1
0
        private static void ProcessChat(WhatsApp _WhatsAppApi, string _Dest)
        {
            Thread thRecv = new Thread(t =>
            {
                try
                {
                    while (_WhatsAppApi != null)
                    {
                        _WhatsAppApi.PollMessages();
                        Thread.Sleep(100);
                        continue;
                    }
                }
                catch (ThreadAbortException)
                {
                }
            })
            {
                IsBackground = true
            };

            thRecv.Start();

            WhatsUserManager usrMan  = new WhatsUserManager();
            WhatsUser        tmpUser = usrMan.CreateUser(_Dest, "User");

            while (true)
            {
                String line = Console.ReadLine();
                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }

                string command = line.Trim();
                switch (command)
                {
                case "/query":
                    Console.WriteLine("[] Interactive conversation with {0}:", tmpUser);
                    break;

                case "/accountinfo":
                    Console.WriteLine("[] Account Info: {0}", _WhatsAppApi.GetAccountInfo().ToString());
                    break;

                case "/lastseen":
                    Console.WriteLine("[] Request last seen {0}", tmpUser);
                    _WhatsAppApi.SendQueryLastOnline(tmpUser.GetFullJid());
                    break;

                case "/exit":
                    _WhatsAppApi = null;
                    thRecv.Abort();
                    return;

                case "/start":
                    _WhatsAppApi.SendComposing(tmpUser.GetFullJid());
                    break;

                case "/pause":
                    _WhatsAppApi.SendPaused(tmpUser.GetFullJid());
                    break;

                default:
                    Console.WriteLine("[] Send message to {0}: {1}", tmpUser, line);
                    _WhatsAppApi.SendMessage(tmpUser.GetFullJid(), line);
                    break;
                }
            }
        }
Example #2
0
        private static void ProcessChat(WhatsApp wa, string dst)
        {
            var thRecv = new Thread(t =>
            {
                try
                {
                    while (wa != null)
                    {
                        wa.PollMessages();
                        Thread.Sleep(100);
                        continue;
                    }
                }
                catch (ThreadAbortException)
                {
                }
            })
            {
                IsBackground = true
            };

            thRecv.Start();

            WhatsUserManager usrMan = new WhatsUserManager();
            var tmpUser             = usrMan.CreateUser(dst, "User");

            while (true)
            {
                string line = Console.ReadLine();
                if (line == null && line.Length == 0)
                {
                    continue;
                }

                string command = line.Trim();
                switch (command)
                {
                case "/query":
                    //var dst = dst//trim(strstr($line, ' ', FALSE));
                    Console.WriteLine("[] Interactive conversation with {0}:", tmpUser);
                    break;

                case "/accountinfo":
                    Console.WriteLine("[] Account Info: {0}", wa.GetAccountInfo().ToString());
                    break;

                case "/lastseen":
                    Console.WriteLine("[] Request last seen {0}", tmpUser);
                    wa.SendQueryLastOnline(tmpUser.GetFullJid());
                    break;

                case "/exit":
                    wa = null;
                    thRecv.Abort();
                    return;

                case "/start":
                    wa.SendComposing(tmpUser.GetFullJid());
                    break;

                case "/pause":
                    wa.SendPaused(tmpUser.GetFullJid());
                    break;

                default:
                    Console.WriteLine("[] Send message to {0}: {1}", tmpUser, line);
                    wa.SendMessage(tmpUser.GetFullJid(), line);
                    break;
                }
            }
        }