Thanks to this question and Andre Soares I have managed to write correct code for connecting to WhatsApp and sending simple message.
using System;
using WhatsAppApi;
using WhatsAppApi.Register;
namespace WhatsAppBot
{
class Program
{
static void Main(string[] args)
{
WhatsApp wa = new WhatsApp("********", "********", "sakher", false, false);
// I tried with phone numbers like "38xxxxxxx", "+38xxxxxxx".
// The phone number wasn't previously registered in WhatsApp.
// Password was generated using WART.
wa.OnConnectSuccess += () =>
{
Console.WriteLine("Connected");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
Console.WriteLine("Connection success!");
wa.SendMessage("********", "Hello World!");
// Number is correct and registered in WhatsApp
Console.WriteLine("Message sent!");
};
wa.OnLoginFailed += data => {
Console.WriteLine("Login failed: {0}", data);
// Login failed: not-authorized
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
Console.WriteLine("Connect failed: {0}", ex.StackTrace);
};
wa.Connect();
wa.Disconnect();
Console.WriteLine("BYE");
}
}
}
I have generated password in WART for several times for the same number, but none worked.
An App simply says: Login failed: not-authorized.
Perhaps, someone knows how to fix this?
WhatsApp is the most popular messaging service, with nearly 2 billion monthly users and was created using the ERLANG programming language.
WhatsApp Business is a free to download app available on Android and iPhone, and was built with the small business owner in mind. WhatsApp Business makes interacting with customers easy by providing tools to automate, sort and quickly respond to messages.
WhatsApp can be used on your desktop without a browser. To install WhatsApp Desktop on your computer, download it from the Microsoft Store, Apple App Store, or WhatsApp website. WhatsApp Desktop will only work on computers that meet the following operating system requirements: Windows 8.1 or newer.
WhatsApp Web login: WhatsApp Web allows you to use the messaging service on your laptop or PC if you don't like reaching for your phone constantly. WhatsApp Web lets you read, send, and receive messages directly from a laptop or PC.
private void button1_Click(object sender, EventArgs e)
{
//Send To details
string Phnumber = textBox1.Text;
string message = textBox2.Text;
//send From details
string FromNumber = "917673943979";
string password = "aaRvxtEbePyI/uBOqpqw9yeHlys=";
string nickName = "Dayakar";
WhatsApp wap = new WhatsApp(FromNumber, password, nickName, false, false);
wap.OnConnectSuccess += () =>
{
MessageBox.Show("Connected to whatsapp SuccessFully...");
wap.OnLoginSuccess += (PhoneNumber, data) =>
{
MessageBox.Show("Enterned");
wap.SendMessage(Phnumber, message);
MessageBox.Show("Message Sent Successfully...");
};
wap.OnLoginFailed += (data) =>
{
MessageBox.Show(data);
MessageBox.Show("Yes Failed login : {0}", data);
};
wap.Login();
};
wap.OnConnectFailed += (ex) =>
{
MessageBox.Show("Conncetion Failure");
};
wap.Connect();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With