Thursday, 1 September 2016

sending whatsapp message through c#

Sending Whatsapp message using C# coding

 

In this blog I'm going to show you  How to send whatsapp message by using c# Coding first design Windows Form as shown in above image. Before writing code to send whatsapp message first we need to Install WhatsApp API in our application, based on this WhatsApp API we can create object for WhatsApp. By using WhatsApp Object we can call WhatsApp Methods:

OnconnectSuccess,OnLoginsucces,OnLoginFailed

C# Coding

C# Coding : Namespace


using System;
using System.Collections.Generic;
using System.Component;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WhatsApp_Application;
using WhatsAppApi;
 

C# Coding : To Send Whats App Message

namespace Whats App_Application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            Initialize Component();
        }

        private void btn_send_Click(object sender, EventArgs e)
        {
            string from = "9199876543210"; //(Enter Your Mobile Number)
            string to = txt_to.Text;
            string msg = txt_msg.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...");
                };           
        }
    }
}

 

 

 

 

6 comments: