Exemple #1
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   = "70178717679";         // Mobile number with country code (but without + or 00)
            string password = "******"; //v2 password
            string target   = "70125223790";         // Mobile number to send the message to

            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.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();

            if (wa.LoadPreKeys() == null)
            {
                wa.sendSetPreKeys(true);
            }

            ProcessChat(wa, target);
            Console.ReadKey();
        }
Exemple #2
0
 private void Wa_OnConnectSuccess()
 {
     lblMsg.Text = "Conectado...";
     wa.Login();
 }
Exemple #3
0
        private static void Main(string[] args)
        {
            var tmpEncoding = Encoding.UTF8;

            System.Console.OutputEncoding = Encoding.Default;
            System.Console.InputEncoding  = Encoding.Default;
            string nickname = "";
            string sender   = ""; // Mobile number with country code (but without + or 00)
            string password = ""; //v2 password
            string target   = ""; // 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);
            wa.SendGetServerProperties();

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

            wa.SendMessage("34696649652", "test");
            while (true)
            {
                wa.pollMessage();
            }
        }
        public void Start()
        {
            // registration if necessary
            string password = WhatsAppApi.Register.WhatsRegisterV2.RequestExist(PHONE);

            if (String.IsNullOrEmpty(password))
            {
                // register process
                string response = string.Empty;
                if (WhatsAppApi.Register.WhatsRegisterV2.RequestCode(PHONE, out password, out response, "sms"))
                {
                    Console.WriteLine("Response: [ " + response + " ]");
                    if (string.IsNullOrEmpty(password))
                    {
                        Console.Write("SMS sent. Enter code: ");
                        string code = Console.ReadLine();
                        password = WhatsAppApi.Register.WhatsRegisterV2.RegisterCode(PHONE, code, out response);
                        Console.WriteLine("Response: [ " + response + " ]");
                    }
                }
                else
                {
                    Console.WriteLine("Response: [ " + response + " ]");

                    Console.WriteLine("Trying to register by voice.");
                    if (WhatsAppApi.Register.WhatsRegisterV2.RequestCode(PHONE, out password, out response, "voice"))
                    {
                        Console.WriteLine("Response: [ " + response + " ]");
                        if (string.IsNullOrEmpty(password))
                        {
                            Console.Write("WhatsApp making a call. Enter code: ");
                            string code = Console.ReadLine();
                            password = WhatsAppApi.Register.WhatsRegisterV2.RegisterCode(PHONE, code, out response);
                            Console.WriteLine("Response: [ " + response + " ]");
                        }
                        else
                        {
                            Console.WriteLine("Cannot initiate register process (banned?)");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Response: [ " + response + " ]");
                    }
                }
            }

            if (string.IsNullOrEmpty(password))
            {
                Console.WriteLine("Cannot complete register process (invalid code / banned)");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                Environment.Exit(-1);
            }

            waClient = new WhatsApp(PHONE, password, "nickname", false);

            bool registered = File.Exists(datFilename);

            //WhatsApp.DEBUG = true;
            //WhatsApp.DEBUGOutBound = true;
            DebugAdapter.Instance.OnPrintDebug += (data) =>
            {
                Console.WriteLine(data);
            };

            waClient.OnError += (id, from, code, text) =>
            {
                Console.WriteLine("ERROR: id={0}, from={1}, code={2}, text={3}", id, from, code, text);
            };

            waClient.OnConnectSuccess += () =>
            {
                Console.WriteLine("Connected success");
            };

            waClient.OnConnectFailed += (ex) =>
            {
                Console.WriteLine("Connected failed: " + ex.Message);
            };

            waClient.OnLoginSuccess += (pn, data) =>
            {
                loggedIn = true;

                string sdata = Convert.ToBase64String(data);
                Console.WriteLine("Login success. Next token: {0}", sdata);
                try
                {
                    File.WriteAllText(datFilename, sdata);
                }
                catch (Exception) { }

                waClient.SendGetPrivacyList();
                waClient.SendGetClientConfig();

                if (waClient.LoadPreKeys() == null)
                {
                    waClient.sendSetPreKeys(true);
                }

                threadReceiver = new Thread(t =>
                {
                    while (waClient != null)
                    {
                        waClient.PollMessages();
                        Thread.Sleep(100);
                    }
                })
                {
                    IsBackground = true
                };

                threadReceiver.Start();
            };

            waClient.OnLoginFailed += (data) => {
                Console.WriteLine("Login failed. Reason: {0}", data);
            };

            waClient.Connect();

            byte[] nextChallenge = null;

            if (registered)
            {
                try
                {
                    string foo = File.ReadAllText(datFilename);
                    nextChallenge = Convert.FromBase64String(foo);
                }
                catch (Exception) { };
            }

            waClient.Login(nextChallenge);
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            //Turkish Encoding
            System.Console.OutputEncoding = Encoding.GetEncoding(857);
            System.Console.InputEncoding  = Encoding.GetEncoding(857);

            //UTF-8 Encoding
            //System.Console.OutputEncoding = Encoding.UTF8;
            //System.Console.InputEncoding = Encoding.UTF8;

            string _Nickname = "";
            string _Sender   = "905073837756"; //Mobile Number with Country Code (but without + or 00)
            string _Password = "";             //v2 password
            string _Target   = "";             // Mobile Number to Send the Message to

            PhoneNumber phoneNumber = new PhoneNumber(_Sender);

            _WhatsAppApi = new WhatsApp(_Sender, _Password, _Nickname, true);

            //Event Bindings
            _WhatsAppApi.OnLoginSuccess             += OnLoginSuccess;
            _WhatsAppApi.OnLoginFailed              += OnLoginFailed;
            _WhatsAppApi.OnGetMessage               += OnGetMessage;
            _WhatsAppApi.OnGetMessageReadedClient   += OnGetMessageReadedClient;
            _WhatsAppApi.OnGetMessageReceivedClient += OnGetMessageReceivedClient;
            _WhatsAppApi.OnGetMessageReceivedServer += OnGetMessageReceivedServer;
            _WhatsAppApi.OnNotificationPicture      += OnNotificationPicture;
            _WhatsAppApi.OnGetPresence              += OnGetPresence;
            _WhatsAppApi.OnGetGroupParticipants     += OnGetGroupParticipants;
            _WhatsAppApi.OnGetLastSeen              += OnGetLastSeen;
            _WhatsAppApi.OnGetTyping          += OnGetTyping;
            _WhatsAppApi.OnGetPaused          += OnGetPaused;
            _WhatsAppApi.OnGetMessageImage    += OnGetMessageImage;
            _WhatsAppApi.OnGetMessageAudio    += OnGetMessageAudio;
            _WhatsAppApi.OnGetMessageVideo    += OnGetMessageVideo;
            _WhatsAppApi.OnGetMessageLocation += OnGetMessageLocation;
            _WhatsAppApi.OnGetMessageVcard    += OnGetMessageVcard;
            _WhatsAppApi.OnGetPhoto           += OnGetPhoto;
            _WhatsAppApi.OnGetPhotoPreview    += OnGetPhotoPreview;
            _WhatsAppApi.OnGetGroups          += OnGetGroups;
            _WhatsAppApi.OnGetSyncResult      += OnGetSyncResult;
            _WhatsAppApi.OnGetStatus          += OnGetStatus;
            _WhatsAppApi.OnGetPrivacySettings += OnGetPrivacySettings;
            _WhatsAppApi.OnGetBroadcastLists  += OnGetBroadcastLists;

            /*Debug Code*/
            DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;

            _WhatsAppApi.SendGetServerProperties();

            // Error Notification ErrorAxolotl
            _WhatsAppApi.OnErrorAxolotl += OnErrorAxolotl;

            _WhatsAppApi.Connect();

            string datFile = GetDatFileName(_Sender);

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

            _WhatsAppApi.Login(nextChallenge);

            ProcessChat(_WhatsAppApi, _Target);
            Console.ReadKey();
        }