private void CheckIfUserRegisteredAndCreate(FMessage mess) { if (this.messageHistory.ContainsKey(mess.identifier_key.remote_jid)) { return; } var jidSplit = mess.identifier_key.remote_jid.Split('@'); WhatsUser tmpWhatsUser = new WhatsUser(jidSplit[0], jidSplit[1], mess.identifier_key.serverName); User tmpUser = new User(jidSplit[0], jidSplit[1]); tmpUser.SetUser(tmpWhatsUser); this.messageHistory.Add(mess.identifier_key.remote_jid, new List <FMessage>()); this.messageHistory[mess.identifier_key.remote_jid].Add(mess); }
private static void ProcessChat(WhatsApp _WhatsAppApi, string _Dest) { Thread thRecv = new Thread(t => { try { while (_WhatsAppApi != null) { _WhatsAppApi.PollMessages(); Thread.Sleep(100); continue; } } catch (ThreadAbortException) { } }) { IsBackground = true }; thRecv.Start(); WhatsUserManager usrMan = new WhatsUserManager(); WhatsUser tmpUser = usrMan.CreateUser(_Dest, "User"); while (true) { String line = Console.ReadLine(); if (String.IsNullOrEmpty(line)) { continue; } string command = line.Trim(); switch (command) { case "/query": Console.WriteLine("[] Interactive conversation with {0}:", tmpUser); break; case "/accountinfo": Console.WriteLine("[] Account Info: {0}", _WhatsAppApi.GetAccountInfo().ToString()); break; case "/lastseen": Console.WriteLine("[] Request last seen {0}", tmpUser); _WhatsAppApi.SendQueryLastOnline(tmpUser.GetFullJid()); break; case "/exit": _WhatsAppApi = null; thRecv.Abort(); return; case "/start": _WhatsAppApi.SendComposing(tmpUser.GetFullJid()); break; case "/pause": _WhatsAppApi.SendPaused(tmpUser.GetFullJid()); break; default: Console.WriteLine("[] Send message to {0}: {1}", tmpUser, line); _WhatsAppApi.SendMessage(tmpUser.GetFullJid(), line); break; } } }
private void send() { try { WhatsUserManager manager = new WhatsUserManager(); user = manager.CreateUser(textBox5MyMobile.Text, textBox4Name.Text); var thread = new Thread(t => { UpdateTextBox textbox = UpdateDataTextBox; wa = new WhatsApp(textBox5MyMobile.Text, textBox6Password.Text, textBox4Name.Text, true); wa.OnConnectSuccess += () => { if (textBox3Status.InvokeRequired) { Invoke(textbox, textBox3Status, "Connected..."); } wa.OnLoginSuccess += (phone, data) => { if (textBox3Status.InvokeRequired) { Invoke(textbox, textBox3Status, "\r\nLogin success!"); } while (wa != null) { wa.PollMessages(); Thread.Sleep(200); continue; } }; wa.OnGetMessage += (node, from, id, name, message, receipt_sent) => { if (textBox3Status.InvokeRequired) { Invoke(textbox, textBox3Status, string.Format("\r\n{0}:{1}", name, message)); } }; wa.OnLoginFailed += (data) => { if (textBox3Status.InvokeRequired) { Invoke(textbox, textBox3Status, string.Format("\r\nLogin failed:{0}", data)); } }; wa.Login(); }; wa.OnConnectFailed += (ex) => { if (textBox3Status.InvokeRequired) { Invoke(textbox, textBox3Status, string.Format("\r\nConnect failed: {0}", ex.StackTrace)); } }; wa.Connect(); }) { IsBackground = true }; thread.Start(); } catch (Exception ex) { MessageBox.Show("Connection failed. Check input data, remove polish letters, to telephone number add prefix 48" + ex); } }
protected void Button2_Click(object sender, EventArgs e) { WhatsUserManager Manage = new WhatsUserManager(); USER = Manage.CreateUser(TextBox5.Text, TextBox6.Text); var thread = new Thread(testc => { UpdateTextBox textbox = UpdateDataTextBox; WA = new Whatsapp(TextBox5.Text, TextBox6.Text, TextBox4.Text, true); WA.OnConnectSuccess += () => { if (TextBox3.InvokeRequired) { Invoke(textbox, TextBox3, "Connected...."); } WA.OnLoginSuccess += (phone, data) => { if (TextBox3.InvokeRequired) { invoke(textbox, TextBox3, "\r\nLogin Success...."); } while (WA != null) { WA = PollMessage(); Thread.Sleep(200); continue; } }; WA.OnGetMessage += (node, from, id, name, message, receipt_send) => { if (TextBox3.InvokeRequired) { invoke(textbox, TextBox3, string.Format("\r\n{0}:{1}", name, message)); } }; WA.OnLoginFailed += (data) => { if (TextBox3.InvokeRequired) { invoke(textbox, TextBox3, string.Format("\r\nConnect failed: {0}", data)); } }; WA.Login(); }; WA.OnConnectFailed += (ex) => { if (TextBox3.InvokeRequired) { invoke(textbox, TextBox3, string.Format("\r\nConnection Failed {0}", ex.StactTrace)); } }; WA.Connect(); }) { IsBackground = true }; thread.Start(); }