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