venomous0x / WhatsAPI

Interface to WhatsApp Messenger
2.59k stars 2.14k forks source link

connection closed after sending text after an image? #1050

Open dahansi opened 9 years ago

dahansi commented 9 years ago

Hi there,

I'm stuck and can't find any solution: I have an input form where i can type my text and images ([img]path/to/img.jpg[/img]. Then I seperate Text from Images and send them step by step. But after I sent an image i get:

"<b>Fatal error</b>:  Uncaught exception 'Exception' with message 'Connection Closed!' in [..]/src/whatsprot.class.php:602"    

I replaced the sendImage with sendMsg and this is delivered correctly.

I do it like this:

  1. Login
  2. sendClientConfig
  3. sendGetServerProperties
  4. while(pollMessages)
  5. Login (if I don't I get the same error as above)
  6. sendSync
  7. sendPresenceSubscription
  8. while(pollMessages)
  9. Login (if I don't I get the same error as above)
  10. sendPresenceSubscription
  11. sendMessageComposing
  12. Wait 1/2 sec
  13. sendMessagePaused
  14. sendMessage [Message is sent and arrives]
  15. sendPresenceSubscription
  16. wait 1/2 sec
  17. sendMessagePaused
  18. SendMessageImage
  19. waitForMessageReceipt() [HERE IT CRASHES]

If I skip step 19 it won't send the image, but the script keeps running and sends the rest of the text. After I call pollMessage() I have to login again. After I send an image, I even cant reconnect with login().

The Stack Trace:

Stack trace:
#0 [..]/whatsprot.class.php(1957): WhatsProt-&gt;pollMessage()
#1 [..]/myClass.php(954): WhatsProt-&gt;waitForMessageReceipt()
#2 [..]/myClass.php(995): MyWA-&gt;sendImage('123456789', '../path/to/img.jpg')
#3 [..]/ajax.php(87): MyWA-&gt;sendNL('MyMessage...')
#4 {main}
  thrown in <b>[..]/whatsprot.class.php</b> on line <b>602</b><br />

Can you help me with this? Thanks so much!

echoashu commented 9 years ago

you can refer to this issue https://github.com/mgp25/WhatsAPI-Official/issues/192#issuecomment-66620444

dahansi commented 9 years ago

Great, thanks! That's working now :)

I tried setting up a little broadcast with my friends (4 numbers only), because if I use the normal sendMessage it takes too long until the last one gets it (~ 1 Minute).

To send a broadcast I do this:

  1. Login
  2. sendClientConfig
  3. sendGetServerProperties
  4. while(pollMessages)
  5. sendSync
  6. sendBroadcastMessage
  7. while(pollMessage)

One of my friends is receiving the message, the other 3 (and me) are not getting anything. sendSync says, that the number exists. I dont get any error.

I call it like:

$msgs = "Hello";
$nrs = array("49123456789","49123456987","49123456788","49123456777");
$this->w->sendBroadcastMessage($nrs,$msgs);

Can you help me again, please?

Thanks!!

mgp25 commented 9 years ago

@dahansi https://github.com/mgp25/WhatsAPI-Official

dahansi commented 9 years ago

@mgp25 I'm using your API. The error occurs there. Do you want me to start a new issue at yours?

mgp25 commented 9 years ago

@dahansi there is a wiki with examples there...

dahansi commented 9 years ago

@mgp25 Yes, I know, I read it and I did it the same way. But I dont get any messages. If I call onBroadcastLists($nr,$lists), I get every broadcast I started. But I never received any message :(

mgp25 commented 9 years ago

@dahansi Send broadcast messages only works with synced contacts

dahansi commented 9 years ago

@mgp25 I do sync it (https://github.com/venomous0x/WhatsAPI/issues/1050#issuecomment-67169577):

$nrs = array("49xxx","49yyy");
$this->w->sendSync($nrs);
$this->w->sendBroadcastMessage($nrs,$msgs);

I tried creating a group and that worked and sending a message there worked, too ($this->w->sendMessage("xxx-xxx",$msgs);)

I just cant get the broadcast to work -.-

Thank you so much for all your help!!

mgp25 commented 9 years ago

Not you, the other contacts must have synced your number

dahansi commented 9 years ago

The contacts have me saved in their contact list. They tried sending a Broadcast to my number and that worked. So I think they are synced?

How else can I sync a number on the smartphone?