Windows Forms: Sending WhatsApp Message using C#
By FoxLearn 7/12/2017 9:04:04 PM 22.92K
How to send WhatsApp Message using C# Code
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "SmsWhatsApp" and then click OK
Step 2: Download WhatsApp API. This is an API written in C# but it can be used in any .NET language. It's a fork from WhatsAPINet, which is based on Chat API
Step 3: Design your form as below
Step 4: Add code to handle your form
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WhatsAppApi; namespace SmsWhatsApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { WhatsApp wa = new WhatsApp(txtPhone.Text, txtPassword.Text, txtName.Text, true); //Open connect wa.OnConnectSuccess += () => { txtStatus.Text = "Connected..."; byte[] img = File.ReadAllBytes("e:\\250.gif"); //Login wa.OnLoginSuccess += (phone, data) => { txtStatus.Text += "\r\nLogin success !"; //wa.SendMessage(txtTo.Text, txtMessage.Text); //Send whatsapp message with image file wa.SendMessageImage(txtTo.Text, img, ApiBase.ImageType.GIF); txtStatus.Text += "\r\nMessage sent !"; }; wa.OnLoginFailed += (data) => { txtStatus.Text += string.Format("\r\nLogin failed {0}", data); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { txtStatus.Text += string.Format("\r\nConnect failed {0}", ex.StackTrace); }; wa.Connect(); } } }
VIDEO TUTORIALS
- How to update UI from another thread in C#
- How to get CheckedListBox selected values in C#
- How to use Advanced Filter DataGridView in C#
- How to create a Notification Popup in C#
- How to Use Form Load and Button click Event in C#
- How to Link Chart /Graph with Database in C#
- How to Check SQL Server Connection in C#
- How to Generate Serial Key in C#
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
12/19/2024