user3783206
user3783206

Reputation: 1

how to send image from whatsapp C# api

I am not getting how to send image to any number using WhatsApiNet ?

case "/image":
byte[] imgData = File.ReadAllBytes(@"d:\My Creations\DSC_0423 copy.jpg");
wa.SendMessageImage(tmpUser.GetFullJid(), imgData, ApiBase.ImageType.JPEG);
break;!

But its not working..

Upvotes: 0

Views: 8047

Answers (2)

Rupesh Vaingankar
Rupesh Vaingankar

Reputation: 31

I too was facing the same problem, fortunately I got the solution :)

byte[] img = File.ReadAllBytes("e:\\img.gif");
wa.OnConnectSuccess += () =>
{
      MessageBox.Show("Connected to whatsapp...");

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

          wa.SendMessageImage(to + "@s.whatsapp.net",img,ApiBase.ImageType.GIF);
          MessageBox.Show("Message Sent...");
      };
}

You will just need to modify only 1 line in your code.

wa.SendMessageImage(tmpUser.GetFullJid()+ "@s.whatsapp.net", imgData, ApiBase.ImageType.JPEG);

Hop this will help others too :D Hav a Nyc day :)

Upvotes: 1

Clint
Clint

Reputation: 6220

See: Is it legal to use WhatsAPI?

There seems to be an indication of ongoing legal issues between WhatsApp and the creator of the API open-source project.

There's also mention that WhatsApp have changed some of the details around authentication, so it may be the case that you can't send the message simply because WhatsApp have stopped allowing access.

Upvotes: 0

Related Questions