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(); }
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.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 ("34696649652", "test"); while (true) { wa.pollMessage (); } }