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(); }
//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(); }
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(); }
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 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); } } }
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(); }
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.SendQueryLastOnline(tmpUser.GetFullJid()); break; case "/exit": wa = null; thRecv.Abort(); return; case "/start": wa.SendComposing(tmpUser.GetFullJid()); break; case "/pause": wa.SendPaused(tmpUser.GetFullJid()); break; default: Console.WriteLine("[] Send message to {0}: {1}", tmpUser, line); wa.SendMessage(tmpUser.GetFullJid(), line); break; } } }
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 (); } }
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(); }