-2

I am getting 5 errors as mentioned below:

Error 1 The name 'txtTo' does not exist in the current context

Error 2 The name 'txtMessage' does not exist in the current context

Error 3 The type or namespace name 'WhatsApp' could not be found (are you missing a using directive or an assembly reference?)

Error 4 The type or namespace name 'WhatsApp' could not be found (are you missing a using directive or an assembly reference?)

Error 5 The name 'data' does not exist in the current context

Could someone please help me with the above errors?

Here is the code that i am using:

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 WindowsFormsApplication2
{
 public partial class Form1 : Form
 {
     public Form1()
     {
         InitializeComponent();
     }

     private void btnSend_Click(object sender, EventArgs e)
     {
         //Send ( button_click )
         string from = " ";
         string to = txtTo.Text;
         string msg = txtMessage.Text;

         WhatsApp wa = new WhatsApp(from, "S2pRzjF5WnVcHCwGFkjJuFI2oCM=", "Shri", false, false);

         wa.OnConnectSuccess += () =>
         {
             MessageBox.Show("Connected to whatsapp...");

             wa.OnLoginSuccess += (phoneNumber, data) =>
             {
                 wa.sendmessage(to, msg);
             };

             wa.OnLoginFailed += (DataBindings) =>
             {
                 MessageBox.Show("Login Failed : {0}", data);
             };

             wa.Login();
         };

         wa.OnConnectFailed += (ex) =>
         {
             MessageBox.Show("Connection Failed...");
         };

         wa.Connect();

     }
 }
}
Chandan Kumar
  • 4,570
  • 4
  • 42
  • 62
Shri
  • 51
  • 3
  • 11
  • You have copied that code from somewhere? It is incomplete. – Mykola Kovalchuk Jun 06 '17 at 04:52
  • yes. It is incomplete. Please help me complete it – Shri Jun 06 '17 at 04:58
  • string to ="add something"; string msg = "add your msg"; – Laxman Gite Jun 06 '17 at 04:59
  • 2
    I am voting to close this question because (although you haven't asked for it directly) what you're really looking for is a C# tutorial. – BJ Myers Jun 06 '17 at 05:00
  • To be more specific: txtTo and txtMessage are probably text edit controls. WhatsApp is some external class, not part of .Net framework. data in OnLoginFailed handler is not defined indeed, but it is defined in OnLoginSuccess handler and is not used there, so probably incorrectly copied/replicated code. – Mykola Kovalchuk Jun 06 '17 at 05:00
  • Looks like you're using the answer to a similar question on [Quora](https://www.quora.com/How-can-I-send-WhatsApp-messages-using-C). Make sure you add the references for the API and include `using` statements so the object types in the API will be recognized. – Poosh Jun 06 '17 at 05:12
  • Please help me in correcting the code – Shri Jun 06 '17 at 16:05

1 Answers1

1

Please check below code :

First you need to Register your No on WART check below link :

http://www.c-sharpcorner.com/uploadfile/ansh06031982/send-message-on-whatsapp-number-using-web-service/

And your Method should be :

private void btnSend_Click(object sender, EventArgs e)
{
     //Send To details
     string Phnumber = textBox1.Text;
     string message = textBox2.Text;

     //send From details

     string FromNumber = "9177677377";
     string password = "bbRvfrEbePyI/uGOqyyw9yeHlys=";
     string nickName = "Laxman";

     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();
 }

Cheers !!

Laxman Gite
  • 2,248
  • 2
  • 15
  • 23
  • System.Exception occurred HResult=0x80131500 Message=Auth response error Source=WhatsAppApi StackTrace: at WhatsAppApi.WhatsSendBase.addAuthResponse() at WhatsAppApi.WhatsSendBase.Login(Byte[] nextChallenge) at WindowsFormsApp1.Form1.<>c__DisplayClass2_0.b__0() in C:\Users\bshrinid\Documents\Visual Studio 2017\Projects\WindowsFormsApp1\WindowsFormsApp1\Form1.cs:line 56 at WhatsAppApi.WhatsEventBase.fireOnConnectSuccess() at WhatsAppApi.WhatsAppBase.Connect() – Shri Jun 06 '17 at 09:20
  • got the above error. Please help – Shri Jun 06 '17 at 09:20
  • WART is also not working to get the password – Shri Jun 06 '17 at 09:25
  • https://www.codeproject.com/Questions/1114592/Auth-response-error-in-whatapp-api-code check this link – Laxman Gite Jun 06 '17 at 09:26
  • Use this dll https://drive.google.com/file/d/0BwBxpfm3kmmgNGtKNkRTRF9fS0k/view?pli=1 – Laxman Gite Jun 06 '17 at 09:33
  • Got the error while registering WART as status:fail, reason:bad_token – Shri Jun 06 '17 at 16:09