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?