private void mmmm() { string from = "+261349147482"; //(Enter Your Mobile Number) string to = "+261336126166"; string msg = ""; WhatsApp wa = new WhatsApp(from, "WhatsAppPassword", "NickName", false, false); wa.OnConnectSuccess += () => { MessageBox.Show("Connected to WhatsApp..."); wa.OnLoginSuccess += (phonenumber, data) => { wa.SendMessage(to, msg); MessageBox.Show("Message Sent..."); }; wa.OnLoginFailed += (data) => { MessageBox.Show("Login Failed : {0} : ", data); }; wa.Login(); }; wa.OnConnectFailed += (Exception) => { MessageBox.Show("Connection Failed..."); }; }
private void button1_Click(object sender, EventArgs e) { string from = "56966411028"; string to = txtTo.Text; string msg = txtMessage.Text; WhatsApp wa = new WhatsApp(from, "2kVzSn7Mf2CP09+LnqVs+t9EWy8=", "rodrigo", false, false); wa.OnConnectSuccess += () => { MessageBox.Show("Conectando a WhatsAppa"); wa.OnLoginSuccess += (phoneNumber, data) => { wa.SendMessage(to, msg); MessageBox.Show("Mensaje enviado"); }; wa.OnLoginFailed += (data) => { MessageBox.Show(string.Format("Fallo login : {0} ", data)); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { MessageBox.Show("Fallo la conexion"); }; wa.Connect(); //WIhDFaZ/gB4kEv6fk/d9h7rlhJY= }
private void btnGonder_Click(object sender, EventArgs e) { WhatsApp wa = new WhatsApp(txtTelefon.Text, txtPassword.Text, txtIsım.Text, true); wa.OnConnectSuccess += () => { txtDurum.Text = "Bağlandıı.."; wa.OnLoginSuccess += (phone, data) => { txtDurum.Text += "\r\n Bağlantı başarılı!"; wa.SendMessage(txtKime.Text, txtMesaj.Text); txtDurum.Text += "\r\n Mesaj gönderildi"; }; wa.OnLoginFailed += (data) => { txtDurum.Text += string.Format("\r\n Giriş başarısız {0}", data); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { txtDurum.Text += string.Format("\r\n Bağlantı başarısız {0}", ex.StackTrace); }; wa.Connect(); }
public void SendMessage() { //WhatsApp wa = new WhatsApp("918971503323", "865980025606754", "Goku", true); WhatsApp wa = new WhatsApp("918971503323", "VrF2co5YusQHfEr9KYcRFzHLywg=", "Goku", true); //eb+rLdDbcsKrfsodefDuqRSRxhU= //Base64Encode("867802024224934") wa.OnConnectSuccess += () => { //wa.SendMessage("8105446053", "Hello"); wa.OnLoginSuccess += (phno, data) => { wa.SendMessage("8105446053", "Hello"); }; wa.OnLoginFailed += (data) => { System.Diagnostics.Debug.Write("Login failed"); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { System.Diagnostics.Debug.Write("Login failed" + ex.Message); }; wa.Connect(); //wa.Disconnect(); }
private void button1_Click(object sender, EventArgs e) { string From = "918824518051"; string To = textBox1.Text; string msg = textBox2.Text; //Whatsapp Class WhatsApp wa = new WhatsApp(From, "", "Vin", false, false); wa.OnConnectSuccess += () => { MessageBox.Show("Connected to WhatsApp.........."); wa.OnLoginSuccess += (phoneNumber, data) => { MessageBox.Show("Login SuccessFully!!"); wa.SendMessage(To, msg); MessageBox.Show("Message Sent!"); }; wa.OnLoginFailed += (data) => { MessageBox.Show("Login Failed :{0}", data); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { MessageBox.Show("Connection Failed!"); }; wa.Connect(); }
public void Start() { dtEmisores_UsuariosEN = SchoolManager.WhatsApp.LogicaNegocios.Emisores_UsuariosLN.DtEmisorActivoPorUsuario(Usuario, _prioridad); if (dtEmisores_UsuariosEN.Rows.Count == 0) { System.Windows.Forms.MessageBox.Show(string.Format("Usuario: {0}.- No hay emisor para enviar mensajes", Usuario)); return; } _listen = true; wa = new WhatsApp(dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString(), dtEmisores_UsuariosEN.Rows[0]["APIKEY"].ToString(), dtEmisores_UsuariosEN.Rows[0]["NOMBREPERFIL"].ToString(), true); dtUltimaConexion = DateTime.Now; wa.Connect(); wa.Login(); if (_types != null && _types.Length > 0) { // Using only the XmlMessageFormatter. You can use other formatters as well _queue.Formatter = new XmlMessageFormatter(_types); } _queue.PeekCompleted += new PeekCompletedEventHandler(OnPeekCompleted); _queue.ReceiveCompleted += new ReceiveCompletedEventHandler(OnReceiveCompleted); StartListening(); }
public Result SendByWhatsApp(string To, string Message) { result = new Result(); if (SMSService == "True") { WhatsApp wa = new WhatsApp(WhatsappFrom, WhatsappPassword, WhatsappNickName, true, true); wa.OnConnectSuccess += () => { wa.OnLoginSuccess += (phoneNumber, data) => { wa.SendMessage(To, Message); result.Message = "Message sent successfully!"; }; wa.OnLoginFailed += (data) => { result.Message = "Login Failed : {0}," + data + ""; }; wa.Login(); }; wa.OnConnectFailed += (ex) => { result.Message = "Connection Failed!"; }; wa.Connect(); } return(result); }
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 = "972546252491"; // Mobile number with country code (but without + or 00) string password = "******"; //v2 password string target = "972543143131"; // Mobile number to send the message to string text = "בדיקה"; WhatsApp wa = new WhatsApp(sender, password, nickname, true); //event bindings wa.OnLoginSuccess += (phoneNumber, data) => { WhatsUserManager usrMan = new WhatsUserManager(); var tmpUser = usrMan.CreateUser(target, "User"); string sdata = Convert.ToBase64String(data); wa.SendMessage(tmpUser.GetFullJid(), text); //wa.Disconnect(); }; byte[] nextChallenge = Convert.FromBase64String(sender); wa.Connect(); wa.Login(nextChallenge); Console.ReadKey(); }
public void LoginWhatsapp(string phoneNumber, string password) { Thread thhread = new Thread(t => { wa = new WhatsApp(phoneNumber, password, phoneNumber, true); wa.OnConnectSuccess += () => { Clients.All.notifyMessage("Connected......"); wa.OnLoginSuccess += (phone, data) => { Clients.All.notifyMessage("Login Success !"); }; wa.OnLoginFailed += (data) => { Clients.All.notifyMessage(string.Format("Login failed: {0}", data)); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { Clients.All.notifyMessage(string.Format("Connected failed: {0}", ex.StackTrace)); }; wa.Connect(); }) { IsBackground = true }; thhread.Start(); }
public WhatsappSender() { string from = "hier mobiel nummer van bus-systeem"; string token = "hier whatsapp token van WART (https://github.com/mgp25/WART)"; WhatsApp wa = new WhatsApp(from, token, "Bus-systeem", false, false); wa.OnConnectSuccess += () => { //MessageBox.Show("Connecten naar whatsapp..."); // Alleen voor testen wa.OnLoginSuccess += (phoneNumber, data) => { // wa.SendMessage(to, msg); //MessageBox.Show("Bericht verstuurd.."); // Alleen voor testen }; wa.OnLoginFailed += (data) => { //MessageBox.Show("Login mislukt : {0}", data); // Alleen voor testen }; wa.Login(); }; wa.OnConnectFailed += (ex) => { //MessageBox.Show("Connection mislukt"); // Alleen voor testen }; wa.Connect(); }
private void button1_Click(object sender, EventArgs e) { var from = "85988559171"; var to = textBox1.Text; var msg = textBox2.Text; var whatsApp = new WhatsApp(from, "%a0%c2%06%29rz%16%3f%f5%0a%cef%81%5dd%20%7dd%cb", "Marcius", false, false); whatsApp.OnConnectSuccess += () => { MessageBox.Show("Contectado ao Whatsapp!"); }; whatsApp.OnLoginSuccess += (number, data) => { whatsApp.SendMessage(to, msg); MessageBox.Show("Mensagem enviada! " + Encoding.ASCII.GetString(data)); }; whatsApp.OnLoginFailed += data => { MessageBox.Show("Erro no login: " + data); }; whatsApp.Login(); }
public void SendWhatsAppMessage(WhatsAppConfig whatsAppConfig) { WhatsApp whatsApp = new WhatsApp(whatsAppConfig.Phone, whatsAppConfig.Password, whatsAppConfig.Nickname, false, false); whatsApp.OnConnectSuccess += () => { MessageBox.Show("Connected to whatsapp..."); whatsApp.OnLoginSuccess += (phoneNumber, data) => { whatsApp.SendMessage(whatsAppConfig.Phone, whatsAppConfig.Message); MessageBox.Show("Message Sent..."); }; whatsApp.OnLoginFailed += (data) => { MessageBox.Show("Login failed: {0}", data); }; whatsApp.Login(); }; whatsApp.OnConnectFailed += (ex) => { MessageBox.Show("Connected Failed..."); }; whatsApp.Connect(); }
public IActionResult Index() { string from = "5511988801976"; string to = "5511988801976"; string message = "mensagem do mats"; var whatsApp = new WhatsApp(from, "", "", false, false); whatsApp.OnConnectSuccess += () => { ViewBag.IsConnected = " IsConnected: sim "; whatsApp.OnLoginSuccess += (phoneNumber, data) => { whatsApp.SendMessage(to, message); ViewBag.IsMessageSent = " IsMessageSent: sim "; }; whatsApp.OnLoginFailed += (data) => { whatsApp.SendMessage(to, message); ViewBag.IsLoginFailed = " IsLoginFailed: sim "; }; whatsApp.Login(); }; whatsApp.OnConnectFailed += (ex) => { ViewBag.IsConnectFailed = ex.Message; }; return(View()); }
private void button1_Click(object sender, EventArgs e) { string from = "923059108705"; string To = txtTo.Text; string msg = txtmsg.Text; WhatsApp wa = new WhatsApp(from, "604c6a32ffe14e04e999d064342551061a01c778", "Amin", false, false); wa.OnConnectSuccess += () => { MessageBox.Show("Connected to Whatsapp"); wa.OnLoginSuccess += (phoneNumber, data) => { wa.SendMessage(To, msg); MessageBox.Show("Message send....."); }; wa.OnLoginFailed += (data) => { MessageBox.Show("Login Failed :(0)", data); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { MessageBox.Show("Connection Failed......"); }; wa.Connect(); }
private void btnSend_Click(object sender, EventArgs e) { try { WhatsApp wa = new WhatsApp(txtPhone.Text, txtPass.Text, txtPass.Text, true); wa.OnConnectSuccess += () => { txtStatus.Text = "تم الاتصال ....."; wa.OnLoginSuccess += (phone, data) => { txtStatus.Text += "\r\n تم الاتصال .....!"; wa.SendMessage(txtTo.Text, txtMessage.Text); txtStatus.Text += "\r\n تم ارسال الرسالة !"; }; wa.OnLoginFailed += (data) => { txtStatus.Text += string.Format("\r\n Connection Failed {0}", data); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { txtStatus.Text += string.Format("\r\n Connect Failed {0}", ex.StackTrace); }; wa.Connect(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static string SendMessage(String To, String Message) { string status = string.Empty; WhatsApp wa = new WhatsApp("917709981177", "xxxxxxxxxxxxxxxxxx", "Amit", false, false); wa.OnConnectSuccess += () => { wa.OnLoginSuccess += (phonenumber, data) => { status = "Connection Success"; wa.SendMessage(To, Message); status = "Message sent Success"; }; wa.OnLoginFailed += (data) => { status = "Login Failed" + data; }; wa.Login(); }; wa.OnConnectFailed += (ex) => { status = "Connection Failed" + ex.StackTrace; }; wa.Connect(); return(status); }
static void Main(string[] args) { string to = "7978406411"; string msg = "Hii I am Abhijit Parida"; string from = "9437745159"; WhatsApp wa = new WhatsApp(from, "", "Abhijit", false, false); wa.OnConnectSuccess += () => { Console.WriteLine(" Connected with whatsApp Successfully"); wa.OnLoginSuccess += (phonenumber, data) => { wa.SendMessage(to, msg); }; wa.OnLoginFailed += (data) => { Console.WriteLine("WhatsApp Login failed please check the error through stack trace", data); }; wa.Login(); }; wa.OnConnectFailed += (data) => { Console.WriteLine("Connection Failled"); }; wa.Connect(); }
public void Stop() { _listen = false; thRecv.Abort(); wa.Disconnect(); 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 = null; _queue.PeekCompleted -= new PeekCompletedEventHandler(OnPeekCompleted); _queue.ReceiveCompleted -= new ReceiveCompletedEventHandler(OnReceiveCompleted); }
public void login(string phoneNumber, string pass) { Thread thread = new Thread(t => { wa = new WhatsApp(phoneNumber, pass, phoneNumber, true); wa.OnConnectSuccess += () => { Clients.All.notifyMessage("Conectado ..."); wa.OnLoginSuccess += (phone, data) => { Clients.All.notifyMessage("Logueo exitoso ..."); }; wa.OnLoginFailed += (data) => { Clients.All.notifyMessage(string.Format("Fallo en login {0}", data)); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { Clients.All.notifyMessage(string.Format("Fallo de conexión {0}", ex.StackTrace)); }; wa.Connect(); }) { IsBackground = true }; thread.Start(); }
protected void btnEnviar_Click(object sender, EventArgs e) { WhatsApp wp = new WhatsApp(txtTelefono.Text, txtContrasena.Text, txtNombre.Text, true); /* wp.OnConnectSuccess += () => * { * txtEstatus.Text = "Conectando ..."; * wp.OnConnectSuccess += (phone, data) => * { * txtEstatus.Text += "\r\nConnection sucess !"; * wp.SendMessage(txtA.Text, txtMemsaje.Text); * txtEstatus.Text += "\r\Mensaje enviado !"; * * }; * * wp.OnLoginFailed += (data) => * { * txtEstatus.Text += string.Format("\r\nLogin failed {0}",data); * }; * wp.Login(); * }; * * wp.OnConnectFailed += (ex) => * { * txtEstatus.Text += string.Format("\r\nLogin failed {0}",ex.StackTrace); * }; * * wp.Connect();*/ }
private void button3_Click(object sender, EventArgs e) { string from = "9199876543210"; //(Enter Your Mobile Number) string to = destinationIP.Text; string msg = infoTxt.Text; WhatsApp wa = new WhatsApp(from, "WhatsAppPassword", "NickName", false, false); wa.OnConnectSuccess += () => { MessageBox.Show("Connected to WhatsApp..."); wa.OnLoginSuccess += (phonenumber, data) => { wa.SendMessage(to, msg); MessageBox.Show("Message Sent..."); }; wa.OnLoginFailed += (data) => { MessageBox.Show("Login Failed : {0} : ", data); }; wa.Login(); }; wa.OnConnectFailed += (Exception) => { MessageBox.Show("Connection Failed..."); }; }
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 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 string SendWhats() { // Moto G dual chip // 353334061452427 // 353334061452435 string imei = "353334061452435"; //My IMEI //string imei = "00c9caf9c2ca86b624d3defcf199d4f1"; //My IMEI //WhatsApp me = new WhatsApp(sender, imei, nickname, true); WhatsApp me = null; using (MD5 md5Hash = MD5.Create()) { String corrected = new string(imei.ToCharArray()); string hash1 = GetMd5Hash(md5Hash, "353334061452427"); // IMEI SIM CLARO string hash2 = GetMd5Hash(md5Hash, "353334061452435"); // IMEI SIM TIM string hash3 = GetMd5Hash(md5Hash, "Android9589"); // Senha WART me = new WhatsApp("5521995891097", hash1, "API Test", true); me.Connect(); me.Login(); //Response.Write(me.Login(null) + " | "); //Response.Write(me.Login(md5Hash.ComputeHash(Encoding.Unicode.GetBytes(hash3))) + " | "); // byte[] b = { // getByte("00"), getByte("c9"), getByte("ca"), getByte("f9"), // getByte("c2"), getByte("ca"), getByte("86"), getByte("b6"), // getByte("24"), getByte("d3"), getByte("de"), getByte("fc"), // getByte("f1"), getByte("99"), getByte("d4"), getByte("f1") }; // me.Login(b); } //using (MD5 md5Hash = MD5.Create()) //{ // string hash1 = GetMd5Hash(md5Hash, "353334061452427"); // string hash2 = GetMd5Hash(md5Hash, "353334061452435"); // //string hashs = "00c9caf9c2ca86b624d3defcf199d4f1"; // //me.Login(md5Hash.ComputeHash(Encoding.UTF8.GetBytes(imei))); //} Response.Write(me.ConnectionStatus + " | "); // I get a Connection! Response.Write(me.SendMessage("5521969476360", "Amor! Retorna")); // Send Message //No Message received :( me.Disconnect(); return(""); }
public void xyz(string nickname, string sender, string password, string[] Datadst, string DataWhatsAppType, string DataDataToSend, string Dataext) { dst = Datadst; WhatsAppType = DataWhatsAppType; DataToSend = DataDataToSend; ext = Dataext; WhatsApp wa = new WhatsApp(sender, password, nickname, true); }
private static void Main_old(string[] args) { var tmpEncoding = Encoding.UTF8; System.Console.OutputEncoding = Encoding.Default; System.Console.InputEncoding = Encoding.Default; string nickname = "lior"; string sender = "972546252491"; // Mobile number with country code (but without + or 00) string password = "******"; //v2 password string target = "972543143131"; // 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(); }
public ChatForm(WhatsApp wa, object obj) { InitializeComponent(); this.phoneNumber = obj.GetType().GetProperty("PhoneNumber").GetValue(obj, null).ToString(); this.fullName = obj.GetType().GetProperty("FullName").GetValue(obj, null).ToString(); this.wa = wa; wa.OnGetMessage += Wa_OnGetMessage; //wa.OnGetMessageImage += Wa_OnGetMessageImage; }
public static string PostSendingMessage(string ScreenText, string PhoneNumber) { string sendingLog = string.Empty, jsonString = string.Empty, responseText = string.Empty, returnresponse = string.Empty; sendingLog += Environment.NewLine + DateTime.Now + Environment.NewLine + "Method Name: PostSendingMessage " + Environment.NewLine; sendingLog += "ScreenText:" + ScreenText + ",PhoneNumber:" + PhoneNumber + "" + Environment.NewLine; ErrorHandler.ErrorLog(sendingLog, "WHATSAPP"); WhatsappSending _objWhatsappSending = new WhatsappSending(); try { _objWhatsappSending.scenarioKey = ConfigurationManager.AppSettings["ScenarioKey"].ToString(); var httpWebRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["WhatsappBaseURL"].ToString()); WhatsApp _objWhatsApp = new WhatsApp(); _objWhatsApp.text = ScreenText; _objWhatsappSending.whatsApp = _objWhatsApp; List <Destination> _objDestinationLst = new List <Destination>(); Destination _objDestination = new Destination(); PinBoxIndiaAPIV1._0.Models.To _objTo = new PinBoxIndiaAPIV1._0.Models.To(); _objTo.phoneNumber = PhoneNumber; _objDestination.to = _objTo; _objDestinationLst.Add(_objDestination); _objWhatsappSending.destinations = _objDestinationLst; JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); serializerSettings.Converters.Add(new DataTableConverter()); jsonString = JsonConvert.SerializeObject(_objWhatsappSending, Newtonsoft.Json.Formatting.None, serializerSettings); sendingLog += "Sending Request:" + jsonString.ToString() + " " + Environment.NewLine; httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; httpWebRequest.Headers.Add("Authorization", "Basic UGluYm94V0E6UGdhbl8wMTA0"); using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(jsonString); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { responseText = streamReader.ReadToEnd(); } WhatsAppSendingResponse responseResult = JsonConvert.DeserializeObject <WhatsAppSendingResponse>(responseText); sendingLog += "Sending Response:" + responseText + " " + Environment.NewLine; List <PinBoxIndiaAPIV1._0.Models.WhatsAppSendingMessageResponse.Message> _objResultMessage = responseResult.messages; if (_objResultMessage.Count > 0) { foreach (var _objResponse in _objResultMessage) { returnresponse = _objResponse.status.groupId.ToString(); } } else { returnresponse = "0"; } } catch (WebException ex) { returnresponse = "-1"; sendingLog += "Sending Execption:" + ex.Message + " " + Environment.NewLine; } ErrorHandler.ErrorLog(sendingLog, "WHATSAPP"); return(returnresponse); }
private void btnSignIn_Click(object sender, EventArgs e) { wa = new WhatsApp(Properties.Settings.Default.PhoneNumber, Properties.Settings.Default.Password, Properties.Settings.Default.FullName, true); wa.OnLoginSuccess += Wa_OnLoginSuccess; wa.OnLoginFailed += Wa_OnLoginFailed; wa.OnConnectFailed += Wa_OnConnectFailed; wa.Connect(); wa.Login(); }
bool SendWhatsAppMessage(String receiver, String Message) { bool result = false; try { //Send ( button_click ) DataAccess.RedaV1Entities db = ModuleClass.GetConnection();//= new DataAccess.RedaV1Entities(ModuleClass.Connect()); DataAccess.Company company = db.Companies.Take(1).SingleOrDefault(); string WhatsAppCode = company.WhatsAppCode; // UserData.Default.WhatsAppCode; string WhatsAppSender = company.WhatsAppSender; // UserData.Default.WhatsAppSender; string from = WhatsAppSender; string to = receiver; string msg = Message; WhatsApp wa = new WhatsApp(from, WhatsAppCode, "RedaPos", false, true); wa.OnConnectSuccess += () => { // MessageBox.Show("Connected to whatsapp..."); wa.OnLoginSuccess += (phoneNumber, data) => { wa.SendMessage(to, msg); result = true; }; wa.OnLoginFailed += (data) => { MessageBox.Show("Login Failed : {0}", data); result = false; }; wa.Login(); }; wa.OnConnectFailed += (ex) => { MessageBox.Show("Connection Failed..."); result = false; }; wa.Connect(); } catch (Exception ex2) { result = false; } return(result); }