public IActionResult Index()
        {
            string from = "5511988801976";
            string to   = "5511988801976";

            string message = "mensagem do mats";

            var whatsApp = new WhatsApp(from, "", "", false, false);

            whatsApp.OnConnectSuccess += () =>
            {
                ViewBag.IsConnected = " IsConnected: sim ";

                whatsApp.OnLoginSuccess += (phoneNumber, data) =>
                {
                    whatsApp.SendMessage(to, message);
                    ViewBag.IsMessageSent = " IsMessageSent: sim ";
                };

                whatsApp.OnLoginFailed += (data) =>
                {
                    whatsApp.SendMessage(to, message);
                    ViewBag.IsLoginFailed = " IsLoginFailed: sim ";
                };

                whatsApp.Login();
            };

            whatsApp.OnConnectFailed += (ex) =>
            {
                ViewBag.IsConnectFailed = ex.Message;
            };

            return(View());
        }
Ejemplo n.º 2
0
        private void mmmm()
        {
            string   from = "+261349147482"; //(Enter Your Mobile Number)
            string   to   = "+261336126166";
            string   msg  = "";
            WhatsApp wa   = new WhatsApp(from, "WhatsAppPassword", "NickName", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected to WhatsApp...");
                wa.OnLoginSuccess += (phonenumber, data) =>
                {
                    wa.SendMessage(to, msg);
                    MessageBox.Show("Message Sent...");
                };
                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("Login Failed : {0} : ", data);
                };

                wa.Login();
            };
            wa.OnConnectFailed += (Exception) =>
            {
                MessageBox.Show("Connection Failed...");
            };
        }
Ejemplo n.º 3
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            MESSAGE     = txtMensaje.Text;
            TARGET_CELL = txtPais.Text + txtNoDestinatario.Text;
            wa.SendMessage(TARGET_CELL, MESSAGE);


            /*wa.OnConnectSuccess += () =>
             * {
             *  lblMsg.Text = "Conectado...";
             *  wa.OnLoginSuccess += (phone, data) =>
             *  {
             *      wa.SendMessage(TARGET_CELL, MESSAGE);
             *      lblMsg.Text = "Mensaje enviado...";
             *  };
             *  wa.OnLoginFailed += (data) =>
             *  {
             *      lblMsg.Text = "ERROR: No se pudo realizar la Autentificación";
             *  };
             *  wa.Login();
             * };
             * wa.OnConnectFailed += (ex) =>
             * {
             *  lblMsg.Text = "ERROR: sin conección";
             * };*/
        }
Ejemplo n.º 4
0
        private void btnGonder_Click(object sender, EventArgs e)
        {
            WhatsApp wa = new WhatsApp(txtTelefon.Text, txtPassword.Text, txtIsım.Text, true);

            wa.OnConnectSuccess += () =>
            {
                txtDurum.Text      = "Bağlandıı..";
                wa.OnLoginSuccess += (phone, data) =>
                {
                    txtDurum.Text += "\r\n Bağlantı başarılı!";
                    wa.SendMessage(txtKime.Text, txtMesaj.Text);
                    txtDurum.Text += "\r\n Mesaj gönderildi";
                };
                wa.OnLoginFailed += (data) =>
                {
                    txtDurum.Text += string.Format("\r\n Giriş başarısız {0}", data);
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
            {
                txtDurum.Text += string.Format("\r\n Bağlantı başarısız {0}", ex.StackTrace);
            };
            wa.Connect();
        }
Ejemplo n.º 5
0
        public void SendWhatsAppMessage(WhatsAppConfig whatsAppConfig)
        {
            WhatsApp whatsApp = new WhatsApp(whatsAppConfig.Phone, whatsAppConfig.Password,
                                             whatsAppConfig.Nickname, false, false);

            whatsApp.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected to whatsapp...");
                whatsApp.OnLoginSuccess += (phoneNumber, data) =>
                {
                    whatsApp.SendMessage(whatsAppConfig.Phone, whatsAppConfig.Message);
                    MessageBox.Show("Message Sent...");
                };

                whatsApp.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("Login failed: {0}", data);
                };

                whatsApp.Login();
            };
            whatsApp.OnConnectFailed += (ex) =>
            {
                MessageBox.Show("Connected Failed...");
            };

            whatsApp.Connect();
        }
Ejemplo n.º 6
0
 public Result SendByWhatsApp(string To, string Message)
 {
     result = new Result();
     if (SMSService == "True")
     {
         WhatsApp wa = new WhatsApp(WhatsappFrom, WhatsappPassword, WhatsappNickName, true, true);
         wa.OnConnectSuccess += () =>
         {
             wa.OnLoginSuccess += (phoneNumber, data) =>
             {
                 wa.SendMessage(To, Message);
                 result.Message = "Message sent successfully!";
             };
             wa.OnLoginFailed += (data) =>
             {
                 result.Message = "Login Failed : {0}," + data + "";
             };
             wa.Login();
         };
         wa.OnConnectFailed += (ex) =>
         {
             result.Message = "Connection Failed!";
         };
         wa.Connect();
     }
     return(result);
 }
Ejemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            var from = "85988559171";
            var to   = textBox1.Text;
            var msg  = textBox2.Text;

            var whatsApp = new WhatsApp(from, "%a0%c2%06%29rz%16%3f%f5%0a%cef%81%5dd%20%7dd%cb", "Marcius", false, false);

            whatsApp.OnConnectSuccess += () =>
            {
                MessageBox.Show("Contectado ao Whatsapp!");
            };

            whatsApp.OnLoginSuccess += (number, data) =>
            {
                whatsApp.SendMessage(to, msg);
                MessageBox.Show("Mensagem enviada! " + Encoding.ASCII.GetString(data));
            };

            whatsApp.OnLoginFailed += data =>
            {
                MessageBox.Show("Erro no login: " + data);
            };

            whatsApp.Login();
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            string From = "918824518051";
            string To   = textBox1.Text;
            string msg  = textBox2.Text;
            //Whatsapp Class
            WhatsApp wa = new WhatsApp(From, "", "Vin", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected to WhatsApp..........");

                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    MessageBox.Show("Login SuccessFully!!");
                    wa.SendMessage(To, msg);
                    MessageBox.Show("Message Sent!");
                };
                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("Login Failed :{0}", data);
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
            {
                MessageBox.Show("Connection Failed!");
            };
            wa.Connect();
        }
Ejemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            string from = "923059108705";
            string To   = txtTo.Text;
            string msg  = txtmsg.Text;


            WhatsApp wa = new WhatsApp(from, "604c6a32ffe14e04e999d064342551061a01c778", "Amin", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected to Whatsapp");
                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wa.SendMessage(To, msg);
                    MessageBox.Show("Message send.....");
                };
                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("Login Failed :(0)", data);
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
            {
                MessageBox.Show("Connection Failed......");
            };
            wa.Connect();
        }
Ejemplo n.º 10
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     try
     {
         WhatsApp wa = new WhatsApp(txtPhone.Text, txtPass.Text, txtPass.Text, true);
         wa.OnConnectSuccess += () =>
         {
             txtStatus.Text     = "تم الاتصال .....";
             wa.OnLoginSuccess += (phone, data) =>
             {
                 txtStatus.Text += "\r\n تم الاتصال .....!";
                 wa.SendMessage(txtTo.Text, txtMessage.Text);
                 txtStatus.Text += "\r\n تم ارسال الرسالة !";
             };
             wa.OnLoginFailed += (data) =>
             {
                 txtStatus.Text += string.Format("\r\n Connection Failed {0}", data);
             };
             wa.Login();
         };
         wa.OnConnectFailed += (ex) =>
         {
             txtStatus.Text += string.Format("\r\n Connect Failed {0}", ex.StackTrace);
         };
         wa.Connect();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            string from = "56966411028";
            string to   = txtTo.Text;
            string msg  = txtMessage.Text;

            WhatsApp wa = new WhatsApp(from, "2kVzSn7Mf2CP09+LnqVs+t9EWy8=", "rodrigo", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Conectando a WhatsAppa");

                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wa.SendMessage(to, msg);
                    MessageBox.Show("Mensaje enviado");
                };

                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show(string.Format("Fallo login : {0} ", data));
                };

                wa.Login();
            };

            wa.OnConnectFailed += (ex) =>
            {
                MessageBox.Show("Fallo la conexion");
            };

            wa.Connect();

            //WIhDFaZ/gB4kEv6fk/d9h7rlhJY=
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            string   to   = "7978406411";
            string   msg  = "Hii I am Abhijit Parida";
            string   from = "9437745159";
            WhatsApp wa   = new WhatsApp(from, "", "Abhijit", false, false);

            wa.OnConnectSuccess += () =>
            {
                Console.WriteLine(" Connected with whatsApp Successfully");
                wa.OnLoginSuccess += (phonenumber, data) =>
                {
                    wa.SendMessage(to, msg);
                };
                wa.OnLoginFailed += (data) =>
                {
                    Console.WriteLine("WhatsApp Login failed please check the error through stack trace", data);
                };
                wa.Login();
            };
            wa.OnConnectFailed += (data) =>
            {
                Console.WriteLine("Connection Failled");
            };
            wa.Connect();
        }
Ejemplo n.º 13
0
        private static string SendMessage(String To, String Message)
        {
            string   status = string.Empty;
            WhatsApp wa     = new WhatsApp("917709981177", "xxxxxxxxxxxxxxxxxx", "Amit", false, false);

            wa.OnConnectSuccess += () =>
            {
                wa.OnLoginSuccess += (phonenumber, data) =>
                {
                    status = "Connection Success";
                    wa.SendMessage(To, Message);
                    status = "Message sent Success";
                };

                wa.OnLoginFailed += (data) =>
                {
                    status = "Login Failed" + data;
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
            {
                status = "Connection Failed" + ex.StackTrace;
            };
            wa.Connect();

            return(status);
        }
Ejemplo n.º 14
0
        public void SendMessage(string to, string msg)
        {
            string from = "YOUR_CEL_PHONE";

            WhatsApp wa = new WhatsApp(from, "YOUR_TOKEN_PERMISSION", "PASS", false, false);

            wa.OnConnectSuccess += () =>
            {
                wa.OnLoginSuccess += (phonenumber, data) =>
                {
                    wa.SendMessage(to, msg);
                };

                wa.OnLoginFailed += (data) =>
                {
                    string dataex = data;
                };

                wa.Login();
            };

            wa.OnConnectFailed += (ex) =>
            {
                string s = ex.Message;
            };

            wa.Connect();
        }
Ejemplo n.º 15
0
        private static void Main(string[] args)
        {
            var tmpEncoding = Encoding.UTF8;
            //System.Console.OutputEncoding = Encoding.Default;
            //  System.Console.InputEncoding = Encoding.Default;
            string nickname = "WhatsApiNet";
            string sender   = "972546252491";                // Mobile number with country code (but without + or 00)
            string password = "******"; //v2 password
            string target   = "972543143131";                // Mobile number to send the message to
            string text     = "בדיקה";

            WhatsApp wa = new WhatsApp(sender, password, nickname, true);

            //event bindings

            wa.OnLoginSuccess += (phoneNumber, data) =>
            {
                WhatsUserManager usrMan = new WhatsUserManager();
                var    tmpUser          = usrMan.CreateUser(target, "User");
                string sdata            = Convert.ToBase64String(data);
                wa.SendMessage(tmpUser.GetFullJid(), text);
                //wa.Disconnect();
            };
            byte[] nextChallenge = Convert.FromBase64String(sender);
            wa.Connect();
            wa.Login(nextChallenge);
            Console.ReadKey();
        }
Ejemplo n.º 16
0
        public void SendMessage()
        {
            //WhatsApp wa = new WhatsApp("918971503323", "865980025606754", "Goku", true);
            WhatsApp wa = new WhatsApp("918971503323", "VrF2co5YusQHfEr9KYcRFzHLywg=", "Goku", true);

            //eb+rLdDbcsKrfsodefDuqRSRxhU=
            //Base64Encode("867802024224934")

            wa.OnConnectSuccess += () =>
            {
                //wa.SendMessage("8105446053", "Hello");

                wa.OnLoginSuccess += (phno, data) =>
                {
                    wa.SendMessage("8105446053", "Hello");
                };

                wa.OnLoginFailed += (data) =>
                {
                    System.Diagnostics.Debug.Write("Login failed");
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
            {
                System.Diagnostics.Debug.Write("Login failed" + ex.Message);
            };

            wa.Connect();

            //wa.Disconnect();
        }
Ejemplo n.º 17
0
        private void button3_Click(object sender, EventArgs e)
        {
            string   from = "9199876543210"; //(Enter Your Mobile Number)
            string   to   = destinationIP.Text;
            string   msg  = infoTxt.Text;
            WhatsApp wa   = new WhatsApp(from, "WhatsAppPassword", "NickName", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected to WhatsApp...");
                wa.OnLoginSuccess += (phonenumber, data) =>
                {
                    wa.SendMessage(to, msg);
                    MessageBox.Show("Message Sent...");
                };
                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("Login Failed : {0} : ", data);
                };

                wa.Login();
            };
            wa.OnConnectFailed += (Exception) =>
            {
                MessageBox.Show("Connection Failed...");
            };
        }
Ejemplo n.º 18
0
        private string SendWhats()
        {
            // Moto G dual chip
            // 353334061452427
            // 353334061452435

            string imei = "353334061452435"; //My IMEI

            //string imei = "00c9caf9c2ca86b624d3defcf199d4f1"; //My IMEI

            //WhatsApp me = new WhatsApp(sender, imei, nickname, true);



            WhatsApp me = null;

            using (MD5 md5Hash = MD5.Create())
            {
                String corrected = new string(imei.ToCharArray());

                string hash1 = GetMd5Hash(md5Hash, "353334061452427"); // IMEI SIM CLARO
                string hash2 = GetMd5Hash(md5Hash, "353334061452435"); // IMEI SIM TIM
                string hash3 = GetMd5Hash(md5Hash, "Android9589");     // Senha WART

                me = new WhatsApp("5521995891097", hash1, "API Test", true);
                me.Connect();
                me.Login();

                //Response.Write(me.Login(null) + " | ");

                //Response.Write(me.Login(md5Hash.ComputeHash(Encoding.Unicode.GetBytes(hash3))) + " | ");

                //    byte[] b = {
                //                   getByte("00"), getByte("c9"), getByte("ca"), getByte("f9"),
                //                   getByte("c2"), getByte("ca"), getByte("86"), getByte("b6"),
                //                   getByte("24"), getByte("d3"), getByte("de"), getByte("fc"),
                //                   getByte("f1"), getByte("99"), getByte("d4"), getByte("f1") };

                //    me.Login(b);
            }

            //using (MD5 md5Hash = MD5.Create())
            //{
            //    string hash1 = GetMd5Hash(md5Hash, "353334061452427");
            //    string hash2 = GetMd5Hash(md5Hash, "353334061452435");
            //    //string hashs = "00c9caf9c2ca86b624d3defcf199d4f1";

            //    //me.Login(md5Hash.ComputeHash(Encoding.UTF8.GetBytes(imei)));
            //}

            Response.Write(me.ConnectionStatus + " | ");                      // I get a Connection!

            Response.Write(me.SendMessage("5521969476360", "Amor! Retorna")); // Send Message

            //No Message received :(
            me.Disconnect();

            return("");
        }
Ejemplo n.º 19
0
 public void SendWhatsapp(string to, string message)
 {
     if (wa.ConnectionStatus == ApiBase.CONNECTION_STATUS.LOGGEDIN)
     {
         wa.SendMessage(to, message);
         Clients.All.notifyMessage(string.Format("{0}: {1}", to, message));
     }
 }
Ejemplo n.º 20
0
        bool SendWhatsAppMessage(String receiver, String Message)
        {
            bool result = false;

            try
            {
                //Send ( button_click )

                DataAccess.RedaV1Entities db      = ModuleClass.GetConnection();//= new DataAccess.RedaV1Entities(ModuleClass.Connect());
                DataAccess.Company        company = db.Companies.Take(1).SingleOrDefault();

                string WhatsAppCode   = company.WhatsAppCode;   // UserData.Default.WhatsAppCode;
                string WhatsAppSender = company.WhatsAppSender; // UserData.Default.WhatsAppSender;



                string from = WhatsAppSender;
                string to   = receiver;
                string msg  = Message;

                WhatsApp wa = new WhatsApp(from, WhatsAppCode, "RedaPos", false, true);

                wa.OnConnectSuccess += () =>
                {
                    //   MessageBox.Show("Connected to whatsapp...");

                    wa.OnLoginSuccess += (phoneNumber, data) =>
                    {
                        wa.SendMessage(to, msg);
                        result = true;
                    };

                    wa.OnLoginFailed += (data) =>
                    {
                        MessageBox.Show("Login Failed : {0}", data);
                        result = false;
                    };

                    wa.Login();
                };

                wa.OnConnectFailed += (ex) =>
                {
                    MessageBox.Show("Connection Failed...");
                    result = false;
                };

                wa.Connect();
            }
            catch (Exception ex2)
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 21
0
 private void button1Send_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBox2Message.Text))
     {
         return;
     }
     if (wa != null)
     {
         if (wa.ConnectionStatus == ApiBase.CONNECTION_STATUS.LOGGEDIN)
         {
             wa.SendMessage(textBox1TO.Text, textBox2Message.Text);
             textBox3Status.Text += string.Format("\r\n{0}:{1}", user.Nickname, textBox2Message.Text);
             textBox2Message.Clear();
             textBox2Message.Focus();
         }
     }
 }
Ejemplo n.º 22
0
        public void sendmsg()
        {
            WhatsApp wa = new WhatsApp("989125152528", "your password", "Ali", false, false);

            wa.OnConnectSuccess += () =>
            {
                Response.Write("connect");
                wa.OnLoginSuccess += (phno, data) =>
                {
                    wa.SendMessage("to", "msg");
                };

                wa.OnLoginFailed += (data) =>
                {
                    Response.Write("login failed" + data);
                };
                wa.Login();
            };
        }
Ejemplo n.º 23
0
        private void button1_Click(object sender, EventArgs e)
        {
            string   from = "7503065558";
            string   to   = textBox1.Text;
            string   msg  = textBox2.Text;
            WhatsApp wa   = new WhatsApp(from, "adhajfhsdjhsdjg", "priya", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("connected to whatsup");
                wa.OnLoginSuccess += (phoneNumeber, data) =>
                                     wa.SendMessage(to, msg);
                MessageBox.Show("Message sent......");
            };
            wa.OnLoginFailed += (data) =>
            {
                MessageBox.Show("Login failed...." + data);
            };
            wa.Login();
        }
Ejemplo n.º 24
0
        public override async Task <ResponseMessage> SendMessage(MessageItem messageItem)
        {
            await Task.Run(() =>
            {
                try
                {
                    WhatsUserManager usrMan = new WhatsUserManager();
                    var tmpUser             = usrMan.CreateUser(messageItem.ClientId, "User");
                    _whatsApp.SendMessage(tmpUser.GetFullJid(), messageItem.Message);

                    return(new ResponseMessage(messageItem));
                }
                catch (Exception e)
                {
                    return(new ResponseMessage(messageItem));
                }
            });

            return(new ResponseMessage {
                ClientId = messageItem.ClientId, IsError = true, ErrMessage = "", Message = messageItem.Message
            });
        }
Ejemplo n.º 25
0
        public static void SendWhapp()
        {
            string from     = "40733766829";
            string toMishu  = "4073100090";
            string to       = "40733766829";
            string message  = "Hey";
            string imei     = "354378062812286";
            string password = "******";
            string nick     = "Test";

            //var by = new byte[] { Convert.ToByte(imei) };
            //var base64 = Convert.ToBase64String(by);
            WhatsApp wa = new WhatsApp(from, imei, nick, true, true);

            wa.OnConnectSuccess += () =>
            {
                Console.WriteLine("Connected");
                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wa.SendMessage(to, message);
                    Console.WriteLine("Message send");
                };

                wa.OnLoginFailed += (data) =>
                {
                    Console.WriteLine("Fail to send");
                };

                wa.Login();
            };

            wa.OnConnectFailed += (ex) =>
            {
                Console.WriteLine("Failed to connect");
            };

            wa.Connect();
        }
        public void SendMessage(string message, string toNumber)
        {
            string from = "447885860529";
            string to   = "447474318713";
            string password;
            // var res = WhatsAppApi.Register.WhatsRegisterV2.GetToken(from);

            WhatsApp wa = new WhatsApp(from, "", "BeruwalaMirror", false, false);

            wa.OnConnectSuccess += () =>
            {
                Console.Write("Connected");
                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wa.SendMessage(to, message);
                    Console.Write("Message sent ...");
                };
                wa.OnLoginFailed += (data) => { Console.Write("login failed: {0}", data); };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) => { Console.Write("connection failed.."); };
            wa.Connect();
        }
Ejemplo n.º 27
0
        private void btMessage_Click(object sender, EventArgs e)
        {
            try
            {
                string from = "94991315204";
                string Fone = txFone.Text;
                string msg  = txMessagem.Text;

                WhatsApp wa = new WhatsApp(from, "snowden+snowden=", "sekhar", false, false);

                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wa.SendMessage(Fone, msg);
                    MessageBox.Show("Messagem Enviada");
                };
                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("login errado:{0}", data);
                };
                wa.Login();
                {
                    wa.OnConnectFailed += (ex) =>
                    {
                        MessageBox.Show("conecçao errada");
                    };

                    {
                        wa.Connect();
                    }
                }
            }

            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
Ejemplo n.º 28
0
        //private static void Main(string[] args)
        //{
        //    var tmpEncoding = Encoding.UTF8;
        //    System.Console.OutputEncoding = Encoding.Default;
        //    System.Console.InputEncoding = Encoding.Default;

        //    string sender = "5521966747230";
        //    string meuTim = "5521983486604";
        //    //string eeeeeeeepa = "5524993951862";
        //    //string vinicius = "5521976320158";
        //    //string ricardo = "5521981663664";

        //    string password = "******";
        //    string nickname = "Verision";
        //    //      string sender   = ""; // Mobile number with country code (but without + or 00)
        //    //      string password = "";//v2 password
        //    string target = meuTim;// Mobile number to send the message to

        //    WhatsApp wa = new WhatsApp(sender, password, nickname, true);

        //    //event bindings
        //    wa.OnLoginSuccess += wa_OnLoginSuccess;
        //    wa.OnLoginFailed += wa_OnLoginFailed;
        //    wa.OnGetMessage += wa_OnGetMessage;
        //    wa.OnGetMessageReadedClient += wa_OnGetMessageReadedClient;
        //    wa.OnGetMessageReceivedClient += wa_OnGetMessageReceivedClient;
        //    wa.OnGetMessageReceivedServer += wa_OnGetMessageReceivedServer;
        //    wa.OnNotificationPicture += wa_OnNotificationPicture;
        //    wa.OnGetPresence += wa_OnGetPresence;
        //    wa.OnGetGroupParticipants += wa_OnGetGroupParticipants;
        //    wa.OnGetLastSeen += wa_OnGetLastSeen;
        //    wa.OnGetTyping += wa_OnGetTyping;
        //    wa.OnGetPaused += wa_OnGetPaused;
        //    wa.OnGetMessageImage += wa_OnGetMessageImage;
        //    wa.OnGetMessageAudio += wa_OnGetMessageAudio;
        //    wa.OnGetMessageVideo += wa_OnGetMessageVideo;
        //    wa.OnGetMessageLocation += wa_OnGetMessageLocation;
        //    wa.OnGetMessageVcard += wa_OnGetMessageVcard;
        //    wa.OnGetPhoto += wa_OnGetPhoto;
        //    wa.OnGetPhotoPreview += wa_OnGetPhotoPreview;
        //    wa.OnGetGroups += wa_OnGetGroups;
        //    wa.OnGetSyncResult += wa_OnGetSyncResult;
        //    wa.OnGetStatus += wa_OnGetStatus;
        //    wa.OnGetPrivacySettings += wa_OnGetPrivacySettings;
        //    DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;

        //    wa.Connect();

        //    string datFile = getDatFileName(sender);
        //    byte[] nextChallenge = null;
        //    if (File.Exists(datFile))
        //    {
        //        try
        //        {
        //            string foo = File.ReadAllText(datFile);
        //            nextChallenge = Convert.FromBase64String(foo);
        //        }
        //        catch (Exception) { };
        //    }

        //    wa.Login(nextChallenge);
        //    wa.SendGetServerProperties();

        //    ProcessChat(wa, target);
        //    Console.ReadKey();

        //    wa.SendMessage(sender, "test");
        //    while (true)
        //    {
        //        wa.pollMessage();
        //    }
        //}

        //public static void Main(string[] args)
        //{
        //    var sender = "5521966747230";
        //    var target = ConfigurationManager.AppSettings["destinatario"].ToString();
        //    var nick = "SICADv3";
        //    string imei = ConfigurationManager.AppSettings["base64pwd"].ToString();
        //    string msg = ConfigurationManager.AppSettings["msg"].ToString();

        //    var zapzap = new WhatsApp(sender, imei, nick, false);

        //    zapzap.OnConnectSuccess += () =>
        //    {

        //        Console.WriteLine("Conectado ao zapzap");

        //        zapzap.OnLoginSuccess += (numero, dados) =>
        //        {
        //            zapzap.SendMessage(target, msg);
        //            Console.WriteLine("zap zap enviado...(pressione [ENTER] para finalizar)");
        //            Console.ReadKey();
        //        };


        //        zapzap.OnLoginFailed += (dado) =>
        //        {
        //            Console.WriteLine("Login falhou: {0}", dado);
        //        };

        //        zapzap.Login();
        //    };

        //    zapzap.OnConnectFailed += ex =>
        //    {
        //        Console.WriteLine("deu ruim: {0}", ex.Message);
        //    };
        //    zapzap.Connect();

        //}

        public static void EnviarWhatsapp(string msg, string destinatario)
        {
            var    sender = ConfigurationManager.AppSettings["sender"].ToString();
            string imei   = ConfigurationManager.AppSettings["base64pwd"].ToString();

            if (String.IsNullOrEmpty(sender) || String.IsNullOrEmpty(imei))
            {
                throw new Exception("Algum parâmetro não pode ser lido do arquivo de configuração, ou o mesmo não está presente.");
            }

            var nick   = "JAHU_ZapZap";
            var target = destinatario;
            var zapzap = new WhatsApp(sender, imei, nick, false);

            zapzap.OnConnectSuccess += () =>
            {
                Console.WriteLine("Conectado ao zapzap");

                zapzap.OnLoginSuccess += (numero, dados) =>
                {
                    zapzap.SendMessage(target, msg);
                };

                zapzap.OnLoginFailed += (dado) =>
                {
                    // falha ao logar
                };

                zapzap.Login();
            };

            zapzap.OnConnectFailed += ex =>
            {
                // falha ao conectar.
            };
            zapzap.Connect();
        }
Ejemplo n.º 29
0
        private void btEnviar_Click(object sender, EventArgs e)
        {
            string from = "919885149767";
            string to   = "55" + txtPara.Text;
            string msg  = txtMsg.Text;

            WhatsApp wa = new WhatsApp(from, "S2pRzjF5WnVcHCwGFkjJuFI2oCM=", "Vágner", false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Conectado...");
                wa.OnLoginSuccess += (phonenumber, data) => {
                    wa.SendMessage(to, msg);
                    MessageBox.Show("Mensagem enviada");
                };
            };
            wa.OnLoginFailed += (data) =>
            {
                MessageBox.Show("Falha ao conectar: {0}", data);
            };

            wa.OnLoginFailed += (ex) =>
                                MessageBox.Show("Erro ao conectar");
        }
Ejemplo n.º 30
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;
                }
            }
        }