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