Exemple #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();
        }
Exemple #2
2
 static void wa_OnGetGroups(WhatsApp.GroupInfo[] groups)
 {
     Console.WriteLine("Got groups:");
     foreach (WhatsAppApi.WhatsApp.GroupInfo info in groups)
     {
         Console.WriteLine("\t{0} {1}", info.subject, info.id);
     }
 }
Exemple #3
2
        public void Disconnect()
        {
            clearError();
            try
            {
                if (wa != null)
                {
                    wa.Disconnect();
                    wa = null;
                }
                if (thRecv != null)
                {
                    thRecv.Abort();
                }
            }
            catch (Exception e)
            {
                setError(13, e);
            }

        }
Exemple #4
1
 public FWhatsAppAPI(WhatsApp _wa)
 {
     wa = _wa;
     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;
 }
Exemple #5
1
        private static void ProcessChat(WhatsApp wa, string dst)
        {
            var thRecv = new Thread(t =>
                                        {
                                            try
                                            {
                                                while (wa != null)
                                                {
                                                    wa.PollMessages();
                                                    Thread.Sleep(100);
                                                    continue;
                                                }

                                            }
                                            catch (ThreadAbortException)
                                            {
                                            }
                                        }) {IsBackground = true};
            thRecv.Start();

            WhatsUserManager usrMan = new WhatsUserManager();
            var tmpUser = usrMan.CreateUser(dst, "User");

            while (true)
            {
                string line = Console.ReadLine();
                if (line == null && line.Length == 0)
                    continue;

                string command = line.Trim();
                switch (command)
                {
                    case "/query":
                        //var dst = dst//trim(strstr($line, ' ', FALSE));
                        Console.WriteLine("[] Interactive conversation with {0}:", tmpUser);
                        break;
                    case "/accountinfo":
                        Console.WriteLine("[] Account Info: {0}", wa.GetAccountInfo().ToString());
                        break;
                    case "/lastseen":
                        Console.WriteLine("[] Request last seen {0}", tmpUser);
                        wa.RequestLastSeen(tmpUser.GetFullJid());
                        break;
                    case "/exit":
                        wa = null;
                        thRecv.Abort();
                        return;
                    case "/start":
                        wa.WhatsSendHandler.SendComposing(tmpUser.GetFullJid());
                        break;
                    case "/pause":
                        wa.WhatsSendHandler.SendPaused(tmpUser.GetFullJid());
                        break;
                    default:
                        Console.WriteLine("[] Send message to {0}: {1}", tmpUser, line);
                        wa.Message(tmpUser.GetFullJid(), line);
                        break;
                }
               }
        }
Exemple #6
1
 public SendImageParams(string mid, User user, WhatsApp wa, string phoneNum, string sendFileName)
 {
     this.mid = mid;
     this.user = user;
     this.wa = wa;
     this.phoneNum = phoneNum;
     this.sendFileName = sendFileName;
 }
 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();
 }
Exemple #8
1
        public Login(WhatsApp wa)
        {
            InitializeComponent();

            LoadData();

            if (Properties.Settings.Default.auto)
            {
                if (CheckData())
                {
                    SetData();
                    this.auto = true;
                    this.accept = true;
                }
            }
        }
Exemple #9
1
        public frmForm(string num, string pass, string nick)
        {
            this.phoneNum = num;
            this.phonePass = pass;
            this.phoneNick = nick;

            InitializeComponent();
            this.userList = new Dictionary<string, User>();
            this.isRunning = true;
            this.bgWorker = new BackgroundWorker();
            this.bgWorker.DoWork += ProcessMessages;
            this.bgWorker.ProgressChanged += NewMessageArrived;
            this.bgWorker.WorkerSupportsCancellation = true;
            this.bgWorker.WorkerReportsProgress = true;
            this.wa = new WhatsApp(this.phoneNum, this.phonePass, this.phoneNick);
            this.messageHandler = new WhatsMessageHandler();
        }
Exemple #10
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();
        }
Exemple #11
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();
        }
Exemple #13
1
        private void Start()
        {
            this.isRunning = true;
            //this.BackupDB();
            System.IO.Directory.CreateDirectory("multimedia");
            Database.CheckDatabase();
            Database.CleanDatabase();
            this.wa = new WhatsApp(this.phoneNum, this.phonePass, this.phoneNick, false);
            this.wa.Connect();
            this.wa.Login();
            this.wa.WhatsSendHandler.SendActive();
            this.bgWorker.RunWorkerAsync();
            this.dispatcherTimer.Start();

            this.wa.sendNickname(this.phoneNick);
            this.wa.WhatsSendHandler.SendGetPhoto(this.phoneNum + "@" + WhatsAppApi.Settings.WhatsConstants.WhatsAppServer, false);

            this.Visibility = System.Windows.Visibility.Visible;
            this.LoadPrintUsers();
        }
        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);

        }
Exemple #15
1
 public static void Create(string phoneNum, string imei, string nick, bool debug)
 {
     _instance = new WhatsApp(phoneNum, imei, nick, debug);
 }
Exemple #16
1
        private void Window_Unloaded(object sender, RoutedEventArgs e)
        {
            if (this.typingTimer != null && this.typingTimer.IsEnabled)
            {
                this.typingTimer.Stop();
            }

            if (this.wa != null)
            {
                this.wa.WhatsSendHandler.SendPaused(this.user.WhatsUser.GetFullJid());
            }

            WpfsApp.MainWindow.MessageEvent -= MainWindow_MessageEvent;
            this.user = null;
            this.wa = null;
            this.phoneNum = null;
            this.messages = null;
            this.patternEmojis = null;

            Properties.Settings.Default.mwidth = this.Width;
            Properties.Settings.Default.mheight = this.Height;
            Properties.Settings.Default.mleft = this.Left;
            Properties.Settings.Default.mtop = this.Top;
            Properties.Settings.Default.Save();
        }
Exemple #17
1
        private void Stop()
        {
            this.isRunning = false;
            this.lstContacts.Items.Clear();
            this.Visibility = System.Windows.Visibility.Hidden;

            if (this.bgWorker != null)
            {
                this.bgWorker.CancelAsync();
                this.bgWorker = null;
            }

            if (this.dispatcherTimer != null && this.dispatcherTimer.IsEnabled)
            {
                this.dispatcherTimer.Stop();
            }

            if (this.wa != null)
            {
                this.wa.WhatsSendHandler.SendClose();
                this.wa.Disconnect();
                this.wa = null;
            }

            this.phoneNum = "";
            this.phonePass = "";
            this.phoneNick = "";
        }
Exemple #18
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();
        }
Exemple #19
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();
        }
Exemple #20
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();
        }
Exemple #21
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();
        }
Exemple #23
0
        protected void SendChatState(string to, string type)
        {
            var node = new ProtocolTreeNode("chatstate", new[] { new KeyValue("to", WhatsApp.GetJID(to)) }, new[] {
                new ProtocolTreeNode(type, null)
            });

            this.SendNode(node);
        }
Exemple #24
0
        protected void SendChatState(string to, string type)
        {
            var node = new ProtocolTreeNode("chatstate", new[] { new KeyValue("to", WhatsApp.GetJID(to)) }, new [] {
                new ProtocolTreeNode(type, null)
            });

            this.whatsNetwork.SendData(this.BinWriter.Write(node));
        }
Exemple #25
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);
                }
            }
        }
Exemple #26
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());
        }
 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();
 }
Exemple #28
0
        public void SendGetParticipants(string gjid)
        {
            string id    = TicketCounter.MakeId();
            var    child = new ProtocolTreeNode("list", null);
            var    node  = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "get"), new KeyValue("xmlns", "w:g2"), new KeyValue("to", WhatsApp.GetJID(gjid)) }, child);

            this.SendNode(node);
        }
Exemple #29
0
        /// <summary>
        /// Make a request to retrieve all group participents
        /// </summary>
        /// <param name="gjid">The group jabber id</param>
        public void SendGetParticipants(string gjid)
        {
            string id    = TicketCounter.MakeId("get_participants_");
            var    child = new ProtocolTreeNode("list", null);
            var    node  = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "get"), new KeyValue("xmlns", "w:g"), new KeyValue("to", WhatsApp.GetJID(gjid)) }, child);

            this.whatsNetwork.SendData(this.BinWriter.Write(node));
        }
Exemple #30
-1
        public Mensajes(string phoneNum, User user, WhatsApp wa)
        {
            this.user = user;
            this.wa = wa;
            this.phoneNum = phoneNum;
            InitializeComponent();

            WpfsApp.MainWindow.MessageEvent += MainWindow_MessageEvent;

            this.typingTimer = new DispatcherTimer();
            this.typingTimer.Tick += new EventHandler(typingTimer_Tick);
            this.typingTimer.Interval = new TimeSpan(0, 0, 5);

            this.patternEmojis = Utils.GetEmojiCompletePattern();

            // Ocultar
            this.lblUser.Visibility = Visibility.Collapsed;
            this.imgUser.Visibility = Visibility.Collapsed;

            if (user.Img != null)
            {
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.StreamSource = new MemoryStream(user.Img);
                bi.EndInit();
                this.imgUser.Source = bi;
                this.lblUser.Content = user.UserName;

                this.imgUser.Visibility = Visibility.Visible;
                this.lblUser.Visibility = Visibility.Visible;
            }
        }
Exemple #31
-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();
        }
Exemple #32
-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();
        }