1.create a new Windows Form Application in Visual Studio
2.in the form add two textboxes with these names: txt_msg and txt_to and add a button
3. in references search whatsapp and add it
4. use this code below:
2.in the form add two textboxes with these names: txt_msg and txt_to and add a button
3. in references search whatsapp and add it
4. use this code below:
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Send_WhatsApp_Message_Using_CSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string From = "phone number";
//send to
string To = txt_To.Text;
//your message
string Msg = txt_Msg.Text;
WhatsAppApi.WhatsApp wa = new WhatsAppApi.WhatsApp(From, "generated password", "Display name", false, false);
wa.OnConnectSuccess += () =>
{
MessageBox.Show("connected...");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
MessageBox.Show("your message has been sent");
};
wa.OnLoginFailed += (data) =>
{
MessageBox.Show("error" + data);
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
MessageBox.Show("connection timeout");
};
wa.Connect();
wa.SendMessage(To, Msg);
}
}
}
