Exemplo n.º 1
0
 internal FMessage(WhatsAppApi.Account.WhatsUser remote_user, bool from_me)
 {
     this.status = Status.Undefined;
     this.gap_behind = true;
     this.User = remote_user;
     this.key = new Key(remote_user.GetFullJid(), from_me, TicketManager.GenerateId());
 }
Exemplo n.º 2
0
        public async Task <bool> WhatsAppTest([FromBody] WhatsAppSettingsViewModel settings)
        {
            try
            {
                var user = await UserManager.Users.Include(x => x.UserNotificationPreferences).FirstOrDefaultAsync(x => x.UserName == HttpContext.User.Identity.Name);


                var status = await WhatsAppApi.SendMessage(new WhatsAppModel {
                    From    = settings.From,
                    Message = "This is a test from Ombi!",
                    To      = user.UserNotificationPreferences.FirstOrDefault(x => x.Agent == NotificationAgent.WhatsApp).Value
                }, settings.AccountSid, settings.AuthToken);

                if (status.HasValue())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.LogError(LoggingEvents.Api, e, "Could not test Lidarr");
                return(false);
            }
        }
Exemplo n.º 3
0
 public FMessage(WhatsAppApi.Account.WhatsUser remote_user, string data, object image)
     : this(remote_user, true)
 {
     this.data = data;
     this.thumb_image = image;
     this.timestamp = new DateTime?(DateTime.Now);
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            api = new WhatsAppApi();
            string myNumber = System.Configuration.ConfigurationManager.AppSettings["number"];
            string myIMEI = System.Configuration.ConfigurationManager.AppSettings["IMEI"];
            api.MessageReceived += new WhatsAppApi.MessageReceivedEventHandler(api_MessageReceived);
            api.Login(myNumber, myIMEI);

            while (true)
            {
                Console.Write(">");
                string message = Console.ReadLine();
                api.SendMessage("555192192122", message);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            api = new WhatsAppApi();
            string myNumber = System.Configuration.ConfigurationManager.AppSettings["number"];
            string myIMEI = System.Configuration.ConfigurationManager.AppSettings["IMEI"];
            api.Login(myNumber, myIMEI);

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork+=new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerAsync();
            while(true){
                Console.Write(">");
                string message  = Console.ReadLine();
                api.SendMessage("tonumber", message);
            }
        }
Exemplo n.º 6
0
 private void Instance_OnGetGroups(WhatsAppApi.Response.WaGroupInfo[] groups)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 void Instance_OnGetGroups(WhatsAppApi.WhatsApp.GroupInfo[] groups)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
        public void LoginTest()
        {
            // send:
            //    - hello
            //    - feature
            //    - auth
            TcpSocketMock socket = new TcpSocketMock();
            MessageFactory messageFactory = new MessageFactory();
            socket.Connect("bin-short.whatsapp.net", 5222);

            List<byte> helloMessage = messageFactory.CreateHelloMessage();
            socket.Send(helloMessage.ToArray());

            ProtocolNode features = messageFactory.CreateFeaturesNode();
            socket.Send(features.ToBytes());

            ProtocolNode authNode = messageFactory.CreateAuthNode();
            socket.Send(authNode.ToBytes());

            // receive
            //    - start (tream)
            //    - features
            //    - challenge

            byte[] startMessage = new byte[7];
            socket.Receive(startMessage, SocketFlags.None);

            MessageParser parser = new MessageParser();
            ProtocolNode startNode = parser.ParseNode(startMessage);
            Console.WriteLine(startNode.ToString());

            byte[] serverFeaturesMessage = new byte[10];
            socket.Receive(serverFeaturesMessage, SocketFlags.None);

            parser = new MessageParser();
            ProtocolNode serverFeaturesNode = parser.ParseNode(serverFeaturesMessage);
            Console.WriteLine(serverFeaturesNode.ToString());

            byte[] challengeMessage = new byte[97];
            socket.Receive(challengeMessage, SocketFlags.None);

            //send
            // - response

            parser = new MessageParser();
            ProtocolNode challengeNode = parser.ParseNode(challengeMessage);
            Console.WriteLine(challengeNode.ToString());

            Dictionary<string, string> challengeParameters = messageFactory.ProcessChallenge(challengeNode);
            string nonce = challengeParameters["nonce"];
            string qop = challengeParameters["qop"];
            string charset = challengeParameters["charset"];
            string algorithm = challengeParameters["algorithm"];

            WhatsAppApi api = new WhatsAppApi();
            ProtocolNode authResponseNode = messageFactory.CreateAuthResponseNode("s.whatsapp.net", "555198765432", api.EncryptPassword("175422846762539"), nonce, qop, charset);
            socket.Send(authResponseNode.ToBytes());

            byte[] serverMessage = new byte[1024];
            socket.Receive(serverMessage, SocketFlags.None);

            parser = new MessageParser();
            ProtocolNode resultNode = parser.ParseNode(serverMessage);
            Console.WriteLine(resultNode.ToString());
            Assert.AreEqual(resultNode.tag, "success");
        }
Exemplo n.º 9
0
 private static void OnProcessMessageExceptionEvent(Exception ex, byte[] data, WhatsAppApi.Helper.ProtocolTreeNode node)
 {
     System.Windows.Forms.MessageBox.Show(ex.Message);
 }