Connect() public method

public Connect ( ) : void
return void
Esempio n. 1
4
        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 = "316******3"; // Mobile number with country code (but without + or 00)
            string password = "******";//v2 password
            string target = "316********6";// 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.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);

            ProcessChat(wa, target);
            Console.ReadKey();
        }
 private void btnReceive_Click(object sender, EventArgs e)
 {
     txtStatus.Clear();
     var thread = new Thread(t =>
     {
         UpdateTextBox textbox = UpdateDataTextBox;
         WhatsApp wa = new WhatsApp(txtPhoneNumber.Text, txtPassword.Text, txtUserName.Text, true);
         wa.OnConnectSuccess += () =>
         {
             if (txtStatus.InvokeRequired)
             {
                 Invoke(textbox, txtStatus, "Connected...");
             }
             wa.OnLoginSuccess += (phone, data) =>
             {
                 if (txtStatus.InvokeRequired)
                 {
                     Invoke(textbox, txtStatus, "\r\nConnection Success !");
                     wa.pollMessage();
                 }
             };
             wa.OnGetMessage += (node, from, id, name, message, receipt_sent) =>
             {
                 if (txtStatus.InvokeRequired)
                 {
                     Invoke(textbox, txtStatus, string.Format("\r\nName = {0}, Message = {1}", name, message));
                 }
             };
             wa.OnLoginFailed += (data) =>
             {
                 if (txtStatus.InvokeRequired)
                 {
                     Invoke(textbox, txtStatus, string.Format("\r\nLogin Failed {0}", data));
                 }
             };
             wa.Login();
         };
         wa.OnConnectFailed += (ex) =>
         {
             if (txtStatus.InvokeRequired)
             {
                 Invoke(textbox, txtStatus, string.Format("\r\nConnect Failed {0}", ex.StackTrace));
             }
         };
         wa.Connect();
     }) { IsBackground = true };
     thread.Start();
 }
Esempio n. 3
1
        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 = "316******3"; // Mobile number with country code (but without + or 00)
            string password = "******";//v2 password
            string target = "316********6";// 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.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.Connect();
            wa.Login();

            ProcessChat(wa, target);
            Console.ReadKey();
        }
Esempio n. 4
1
        private static void Main(string[] args)
        {
            var tmpEncoding = Encoding.UTF8;
            System.Console.OutputEncoding = Encoding.Default;
            System.Console.InputEncoding = Encoding.Default;
            string nickname = "WhatsAPI Test";
            string sender = "3526********"; // Mobile number with country code (but without + or 00)
            string password = "******";//v2 password
            string target = "316********";// Mobile number to send the message to

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

            wa.Connect();
            wa.Login();
            wa.sendNickname(nickname);
            wa.Disconnect();

            wa.PresenceSubscription(target);
            wa.GetStatus(target);

            ProcessChat(wa, "");

            Console.ReadKey();
        }
        public void EnviarMensagem(String NumeroDestino, String Mensagem, String Senha)
        {
            string from = this.NumeroOrigem;

            string to = NumeroDestino;
            string msg = Mensagem;

            if (String.IsNullOrEmpty(this.Nome))
            {
                this.Nome = NOME_PADRAO;
            }

            WhatsApp wtsp = new WhatsApp(from, Senha, this.Nome, true, false);

            wtsp.OnConnectSuccess += () =>
            {
                wtsp.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wtsp.SendMessage(to, msg);
                    wtsp.SendClose();

                    //TODO: gravar log
                };

                wtsp.OnLoginFailed += (data) =>
                {
                    //TODO: gravar log
                };

                wtsp.Login();
            };

            wtsp.OnConnectFailed += Wtsp_OnConnectFailed;

            wtsp.Connect();
        }
Esempio n. 6
1
        //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();
        }
        private void init()
        {
            var tmpEncoding = Encoding.UTF8;




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

            wa.OnGetMessage += wa_OnGetMessage;
            //wa.OnGetPhoto += wa_OnGetPhoto;
            wa.OnGetMessageImage += wa_OnGetMessageImage;
            wa.OnConnectFailed += new WhatsEventBase.ExceptionDelegate(Instance_OnConnectFailed);
            WhatsAppApi.Helper.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);
            try
            {
                wa.Login();
            }
            catch (Exception e)
            {
                MessageBox.Show(this, "Login failed resone: " + e, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;

            }



            if (wa.ConnectionStatus != WhatsAppApi.WhatsApp.CONNECTION_STATUS.LOGGEDIN)
            {
                MessageBox.Show(this, "Login failed resone: " + wa.ConnectionStatus, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            ProcessChat(wa, target);

        }
Esempio n. 8
1
        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 = "";
            string password = "";
            string target = "";

            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.SendGetServerProperties();
            //ISessionStore AxolotlStore
            wa.OnstoreSession += wa_OnstoreSession;
            wa.OnloadSession += wa_OnloadSession;
            wa.OngetSubDeviceSessions += wa_OngetSubDeviceSessions;
            wa.OncontainsSession += wa_OncontainsSession;
            wa.OndeleteSession += wa_OndeleteSession;
            // IPreKeyStore AxolotlStore
            wa.OnstorePreKey += wa_OnstorePreKey;
            wa.OnloadPreKey += wa_OnloadPreKey;
            wa.OnloadPreKeys += wa_OnloadPreKeys;
            wa.OncontainsPreKey += wa_OncontainsPreKey;
            wa.OnremovePreKey += wa_OnremovePreKey;
            // ISignedPreKeyStore AxolotlStore
            wa.OnstoreSignedPreKey += wa_OnstoreSignedPreKey;
            wa.OnloadSignedPreKey += wa_OnloadSignedPreKey;
            wa.OnloadSignedPreKeys += wa_OnloadSignedPreKeys;
            wa.OncontainsSignedPreKey += wa_OncontainsSignedPreKey;
            wa.OnremoveSignedPreKey += wa_OnremoveSignedPreKey;
            // IIdentityKeyStore AxolotlStore
            wa.OngetIdentityKeyPair += wa_OngetIdentityKeyPair;
            wa.OngetLocalRegistrationId += wa_OngetLocalRegistrationId;
            wa.OnisTrustedIdentity += wa_OnisTrustedIdentity;
            wa.OnsaveIdentity += wa_OnsaveIdentity;
            wa.OnstoreLocalData += wa_OnstoreLocalData;
            // Error Notification ErrorAxolotl
            wa.OnErrorAxolotl += wa_OnErrorAxolotl;

            wa.OnProcessMessageException += wa_On_ProcessMessageException;

            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.SendGetPrivacyList();
            wa.SendGetClientConfig();
            //wa.SendSetPrivacySetting(ApiBase.VisibilityCategory.Status, ApiBase.VisibilitySetting.Everyone);
            //wa.SendStatusUpdate("Hi"); // Hey there! I am using WhatsApp

            if (wa.LoadPreKeys() == null)
                wa.SendSetPreKeys(true);

            ProcessChat(wa, target);
            Console.ReadKey();
        }
Esempio n. 9
1
        public FWhatsAppAPI connect(string sender, string password, string nickname, string nextChalange)
        {
            clearError();
            
            try
            {
                
                log.DebugFormat("sender >{0}<",sender);
                log.DebugFormat("password >{0}<", password);
                log.DebugFormat("nickname >{0}<", nickname);
                log.DebugFormat("nextChalange >{0}<", nextChalange);
               
                WhatsApp wa;
                FWhatsAppAPI waapi = null;

                wa = new WhatsApp(sender.Trim(), password.Trim(), nickname, debug);

                waapi = new FWhatsAppAPI(wa);
                cache[sender] = waapi;

                wa.Connect();
                byte[] datanc = null;
                if (!String.IsNullOrEmpty(nextChalange)) {
                    datanc = Convert.FromBase64String(nextChalange);
                }
                wa.Login(datanc);
                return waapi;
            }
            catch (Exception e)
            {
                setError(3, e);
                log.Debug("error connect", e);
            }
            return new FWhatsAppAPI();
        }
Esempio n. 10
0
        private void btn_send_Click(object sender, EventArgs e)
        {
            string from = textBox_from.Text;
            string to = textBox_to.Text;
            string msg = textBox_msg.Text;

            WhatsApp wa = new WhatsApp(from, "ZVY6Y07Fgepusk2tGcUiCc0v39A=", ".NET Sender", false, false);

            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected", "Status");
                wa.OnLoginSuccess += (phoneNumber, data) =>
                {
                    wa.SendMessage(to, msg);
                    MessageBox.Show("Message Sent", "Status");
                };
                wa.OnLoginFailed += (data) =>
                {
                    MessageBox.Show("could not login to whatsapp", data);
                };
                wa.Login();

            };
            wa.OnConnectFailed += (ex) =>
            {
                MessageBox.Show("failed to connect","Status");
            };
            wa.Connect();
        }
        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();
        }
Esempio n. 12
0
        public void Execute(params object[] list)
        {
            try {
                var tmpEncoding = Encoding.UTF8;
                System.Console.OutputEncoding = Encoding.Default;
                System.Console.InputEncoding  = Encoding.Default;

                wa = new WhatsAppApi.WhatsApp(WAConfig["Sender"], WAConfig["Password"], WAConfig["NickName"], false);
                wa.OnLoginSuccess   += wa_OnLoginSuccess;
                wa.OnConnectSuccess += wa_OnConnectSuccess;
                wa.OnError          += wa_OnError;
                wa.OnConnectFailed  += wa_ConnectFailed;
                wa.OnLoginFailed    += wa_LoginFailed;
                wa.Connect();
                wa.Login();
                string MType = ((string)list [0]);
                switch (MType)
                {
                case "location":
                    wa.SendMessageLocation(WAConfig["Target"], double.Parse((string)list [1], System.Globalization.CultureInfo.InvariantCulture.NumberFormat), double.Parse((string)list [2], System.Globalization.CultureInfo.InvariantCulture.NumberFormat), (string)(list [3]), "");
                    break;

                case "text":
                    wa.SendMessage(WAConfig["Target"], ((string)list [1]));
                    break;

                case "picture":
                    wa.SendMessageImage(WAConfig["Target"], System.IO.File.ReadAllBytes(((string)list [1])), WhatsAppApi.ApiBase.ImageType.PNG);
                    break;

                case "audio":
                    wa.SendMessageAudio(WAConfig["Target"], System.IO.File.ReadAllBytes(((string)list [1])), ApiBase.AudioType.MP3);
                    break;

                case "video":
                    wa.SendMessageVideo(WAConfig["Target"], System.IO.File.ReadAllBytes(((string)list [1])), ApiBase.VideoType.MP4);
                    break;
                }
                de.SYStemiya.Helper.Logger.WriteLine("|  > [WhatsApp] *** Message(" + ((string)(list [0])).ToUpper() + ") sent: " + list[1]);
                PluginEvent messageSent = Event;
                if (messageSent != null)
                {
                    messageSent(this, 2, 2, 2, 2, 2, 2);
                }
            } catch (Exception ex) {
                de.SYStemiya.Helper.Logger.WriteLine(ex.Message);
                de.SYStemiya.Helper.Logger.WriteLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    de.SYStemiya.Helper.Logger.WriteLine(ex.InnerException.Message);
                    de.SYStemiya.Helper.Logger.WriteLine(ex.InnerException.StackTrace);
                }
            }
        }
Esempio n. 13
0
        public ActionResult MandarWhats(string cadena)
        {
            string Ocadena     = cadena;
            char   delimitador = ';';

            string[] parametros = Ocadena.Split(delimitador);

            string from      = "";
            string to        = parametros[1];
            string message   = "";
            string pitchName = parametros[0];

            try
            {
                WhatsAppApi.WhatsApp whats = new WhatsAppApi.WhatsApp(from, "imeistring", "nick", false, false);

                whats.OnConnectSuccess += () =>
                {
                    whats.SendMessage(to, message);
                    Session["EnvioExitoso"] = "El mensaje fue enviado con éxito";

                    whats.OnLoginFailed += (data) =>
                    {
                        Session["LogeoFallido"] = "Login failed : {0}";
                    };
                    whats.Login();
                };

                whats.OnConnectFailed += (ex) =>
                {
                    Session["EnvioFallido"] = "Conexión fallida";
                };

                whats.Connect();
            }
            catch (Exception ex)
            {
            }

            return(View());
        }
Esempio n. 14
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     WhatsApp wa = new WhatsApp(txtPhone.Text, txtPassword.Text, txtName.Text, true);
     wa.OnConnectSuccess += () =>
     {
         txtStatus.Text = "Connected...";
         wa.OnLoginSuccess += (phone, data) =>
         {
             txtStatus.Text += "\r\nConnection Success !";
             wa.SendMessage(txtTo.Text, txtMessage.Text);
             txtStatus.Text += "\r\nMessage Sent !";
         };
         wa.OnLoginFailed += (data) =>
         {
             txtStatus.Text += string.Format("\r\nLoginFailed {0}", data);
         };
         wa.Login();
     };
     wa.OnConnectFailed += (ex) =>
     {
         txtStatus.Text += string.Format("\r\nConnect Failed {0}", ex.StackTrace);
     };
     wa.Connect();
 }
		private void initWhatsAppConnect()
		{
			WhatsApp wa = new WhatsApp(Sender, Password, Nickname, true);
			
			wa.OnGetMessage += wa_OnGetMessage;
			//wa.OnGetPhoto += wa_OnGetPhoto;
			wa.OnGetMessageImage += new WhatsEventBase.OnGetMediaDelegate(wa_OnGetMessageImage);
			wa.OnConnectFailed += new WhatsEventBase.ExceptionDelegate(Instance_OnConnectFailed);
			wa.OnDisconnect += new WhatsEventBase.ExceptionDelegate(wa_OnDisconnect);
			WhatsAppApi.Helper.DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;
			wa.OnConnectFailed += new WhatsEventBase.ExceptionDelegate(wa_OnDisconnect);
			wa.OnError += new WhatsEventBase.OnErrorDelegate(wa_OnError);
			wa.OnGetPaused += new WhatsEventBase.OnGetChatStateDelegate(wa_OnGetPaused);
			wa.OnLoginFailed += new WhatsEventBase.StringDelegate(wa_OnLoginFailed);
			wa.Connect();
			
			

			try
			{
				wa.Login();
			}
			catch (Exception e)
			{
				MessageBox.Show(this, "Login failed resone: " + e, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
				return;
			}
			if (wa.ConnectionStatus != WhatsAppApi.WhatsApp.CONNECTION_STATUS.LOGGEDIN)
			{
				MessageBox.Show(this, "Login failed resone: " + wa.ConnectionStatus, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
				return;
			}
			ProcessChat(wa, target);
		}
Esempio n. 16
-1
        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 = "316******3"; // Mobile number with country code (but without + or 00)
            string password = "******";//v2 password
            string target = "316********6";// Mobile number to send the message to

            string tempStr = "<message to=\"316********[email protected]\" type=\"text\" id=\"1404983842-0\"><x xmlns=\"jabber:x:event\"><server></server></x><body>ddddd</body><offline></offline></message>";
            byte[] byteArray = WhatsApp.SYSEncoding.GetBytes(tempStr);

            WhatsApp wa = new WhatsApp(sender, password, nickname, true);
            wa.SendMessage(target, "ddddd");

            //event bindings
            wa.OnLoginSuccess += wa_OnLoginSuccess;
            wa.OnLoginFailed += wa_OnLoginFailed;
            wa.OnGetMessage += wa_OnGetMessage;
            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;
            WhatsAppApi.Helper.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);

            ProcessChat(wa, target);
            Console.ReadKey();
        }
Esempio n. 17
-1
        private static void Main(string[] args)
        {
            var tmpEncoding = Encoding.UTF8;
            System.Console.OutputEncoding = Encoding.Default;
            System.Console.InputEncoding = Encoding.Default;
            string nickname = "WhatsAPI Test";
            string sender = "3526********"; // Mobile number with country code (but without + or 00)
            string password = "******";//v2 password
            string target = "316********";// Mobile number to send the message to

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

            wa.Connect();
            wa.Login();
            wa.PollMessages();

            wa.Message(target, "Hi this is sent using WhatsApiNet");
            wa.PollMessages();

            ProcessChat(wa, "");

            Console.ReadKey();
        }