sanderdriesen / WhatsAPINet

A .NET WhatsApp API
32 stars 48 forks source link

i cant sendmessageImage #6

Closed sebas0066 closed 8 years ago

sebas0066 commented 9 years ago

hi, i using visual basic 2013 and i cant Use the sendMessageImage() i mean, i dont get any error but the image dont arrive to my cel phone, Some one can help me?, i let the code that i try to use for send the pic.

Dim usrMan As New WhatsAppApi.Account.WhatsUserManager() Dim tmpUser = usrMan.CreateUser(Num, "Contacto") Dim ImageData = File.ReadAllBytes("C:\WhatsApp\Image\12.JPG") Dim toNum = tmpUser.GetFullJid() wa.SendMessageImage(tmpUser.GetFullJid(), ImageData, ApiBase.ImageType.JPEG) Return True

janpieterz commented 9 years ago

Hi @sebas0066 Perhaps you can try the following? Please excuse my lack of VB knowledge ;)

Dim identifierKey = new FMessage.FMessageIdentifierKey(tmpUser.GetFullJid(), true, "your random id");
wa.SendMessageImage(identifierKey, ImageData, ApiBase.ImageType.JPEG)

Perhaps you could try debugging it to see if it really is sent over the socket, and verify it is using the right number as well (keep in mind it's supposed to be an international number without leading 0's or +'s, so including country code).

sebas0066 commented 9 years ago

Thanks janpieterz for answer, i try this and this is what i see in debug image1

i wrong or in serverName must have some data?, i dont know what i doing worng.. actually i using VB but like a web service not win Forms.. another idea that i can try?. Regards.

janpieterz commented 9 years ago

Not sure if you're using the source or a compiled DLL for this, but perhaps you could debug into the SendMessageImage method itself and see what's going on? For example, your socket might be setup in the wrong way and be disconnected. Stepping into the code behind should show some kind of insight in why it's not going as expected.

Just to confirm, are you able to send a text message? If you are that means the connection is setup correctly, all authentication and socket connections are in place etc. Besides that, could you show me how you're creating the wa variable (instance of WhatsApp)?

sebas0066 commented 9 years ago

yes i can send text messages and even i can receive text, image, video and audio, but cant send (image, video, audio) Only text i can send.

Tihis is how i set the wa Instance

    wa = New WhatsApp(WANum, WAPass, NickName, debug, True)
    wa.Connect()
    Dim datFile As String = getDatFileName(WANum)
    Dim nextChallenge() As Byte
    If (File.Exists(datFile)) Then
        Dim foo As String = File.ReadAllText(datFile)
        nextChallenge = Convert.FromBase64String(foo)
    End If
    wa.Login(nextChallenge)

And i Use this Handdler

   Private Sub wa_OnLoginSuccess(phoneNumber As String, data() As Byte)
    ' next password
    Dim sdata As String = Convert.ToBase64String(data)
    My.Computer.FileSystem.WriteAllText(getDatFileName(phoneNumber), sdata, False)
    End Sub
janpieterz commented 9 years ago

I assume this won't fix a lot, but perhaps try instead of

wa.SendMessageImage(identifierKey.id, ImageData, ApiBase.ImageType.JPEG)

this

wa.SendMessageImage(identifierKey, ImageData, ApiBase.ImageType.JPEG)

Besides that, could you perhaps debug into the SendMessageImage method, and basically walk the sending of the message towards the actual send over the socket? There must be something somewhere, a handled but unexpected exception, an if statement about message type or something else that is not giving you the right results. I'm sorry I can't be of more help to you so far, but it's really hard figuring out what's wrong without having the code to try and debug it ;)

sebas0066 commented 9 years ago

if you Have a Time i can send you the project by email that way when you have a momment mabe can give me hand or two ;D because it will cause me a brain explode.

janpieterz commented 9 years ago

Hi @sebas0066.

I'm currently busy but will have some time later today (I'm in the Netherlands). Could you contact me on twitter so we can set it up? Might be helpful to perhaps setup a teamviewer connection for example so it runs totally on your environment.

My twitter handle is janpieter_z

sebas0066 commented 9 years ago

yes, thank you, i will contact you through the day.

azernadeem commented 9 years ago

Need your support to send Images through API.

sebas0066 commented 9 years ago

Hi azernadeem i cant contact janpieterz because i'm out of my work until tomorrow, if you have a problem with the API, post it, that way they can help you, in this moment i cant send image too, but i cant continue with this api by family problems.

Regards

ccejas commented 9 years ago

Hi guys! if you try send image with PhoneNumber@s.whatsapp.net it works fine!!!!!

sebas0066 commented 9 years ago

i Using this code

Dim usrMan As New WhatsAppApi.Account.WhatsUserManager() Dim tmpUser = usrMan.CreateUser(Num, "Contact")

Dim ImageData = File.ReadAllBytes("C:\WhatsApp\Image\12.JPG") Dim toNum = tmpUser.GetFullJid() wa.SendMessageImage(toNum, ImageData, ApiBase.ImageType.JPEG)

but it dont send the image, while i debugging i get this message: image2

i try it downloading the api from nuget, and from this repo, both stil dont send the image... i am programming a webservice visual basic code... i dont know what i'm doing wrong.

ccejas commented 9 years ago

Ok, did you try compile the solución and use the generated dll?? I did that and it works fine!

sebas0066 commented 9 years ago

yes i do that too, even i created another web project on the solution on this repo i set references on it, but even on that way it dont send the image.. and i dont have more ideas. :(

ccejas commented 9 years ago

ok, I modified the code, try change this line -> while (this.uploadResponse == null && i <= 20), replace 20 by 50, there are times that I not receive the uploadResponse because 20 is small. This line is in UploadFile method in the WhatsApp class. Good Luck! ;)

ccejas commented 9 years ago

Other reason it doesn't work is in your code, you need execute PullMessages, if you don't do it never will receive uploadResponse message

sebas0066 commented 9 years ago

i will try this thanks for support. :D

sebas0066 commented 9 years ago

Hi ccejas, i have update the code like you tell me but still not working :( even with pollMessages it dont works. another idea?.

    Dim usrMan As New WhatsAppApi.Account.WhatsUserManager()
    Dim tmpUser = usrMan.CreateUser(Num, "Contacto")

    Dim ImageData = File.ReadAllBytes("C:/WhatsApp/Image/12.JPG")
    Dim toNum = tmpUser.GetFullJid()

    wa.SendMessageImage(toNum, ImageData, ApiBase.ImageType.JPEG)
    wa.PollMessages()
ccejas commented 9 years ago

you need execute PollMessages() in parallel, put that method in a thread ;)

sebas0066 commented 9 years ago

i have not idea how to do the parallel execute :(

janpieterz commented 9 years ago

@sebas0066 Parallel executing is very valuable in this type of application, so I'd suggest trying some tutorials first with random apps and figuring out how to deal with it. As said above I only know C#, though the API used will be the same. I've looked up some tutorials and stuff for VB.NET: MSDN - Multithreading in Visual Basic CodeProject - Multithreading with VB.NET - A beginner's choice DreamInCode - Tasks (>= .Net 4.0) Slaks - Threads vs Tasks

I really tried to look for some VB examples so I can't guarantee the quality, but from glancing over it they'd give you an easy start with a couple of examples!

janpieterz commented 9 years ago

@sebas0066 have you been able to make any progress on this? I've pasted below our C# implementation.

_listeningWorker = new BackgroundWorker();
_listeningWorker.DoWork += ProcessMessages;
_listeningWorker.WorkerSupportsCancellation = true;
private void ProcessMessages(object sender, DoWorkEventArgs e)
{
    try
    {
        if (Thread.CurrentThread.Name == null)
            Thread.CurrentThread.Name = string.Format("WhatsApp Message Polling ({0})", MobileNumber);

        var worker = (sender as BackgroundWorker);

        while (!worker.CancellationPending)
        {
            if (!_wa.HasMessages())
            {
                _wa.PollMessages();
                Thread.Sleep(100);
                continue;
            }

            var tmpMessages = _wa.GetAllMessages();
            worker.ReportProgress(1, tmpMessages);
        }

        e.Cancel = true;
    }
    catch (Exception ex)
    {
        log.ErrorFormat("Error during processing messages for WHatsApp socket:{0}", SocketId);

        throw;
    }
}
sanderdriesen commented 9 years ago

@sebas0066 do you still need support on this? Otherwise I will close this issue.

sebas0066 commented 8 years ago

Hi @sanderdriesen , i cant resolve this issue. i mus susspend my develoment for now by personal reasons. if somebody have a solution please help!.