venomous0x / WhatsAPI

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

Send Video Take Time #847

Open faisalcse opened 10 years ago

faisalcse commented 10 years ago

I am trying to send video and it takes time to send. I am trying to send to 8 receiver. The video size is 3MB.

What is the best way to send bulk video?

mgp25 commented 10 years ago

Recently we update the function to send media messages, so once you have uploaded the video to WhatsApp servers, bind the event to capture the video size and hash, and you don't have to re-upload it:

$w->sendMessageVideo($to, $filepath, false, $fsize, $fhash);
faisalcse commented 10 years ago

what is $fsize and $fhash? What are the value we have to pass?

mgp25 commented 10 years ago

You have to use this to capture that:

function onMediaMessageSent(
    $phone, // The user phone number including the country code.
    $to,
    $id,
    $filetype,
    $url,
    $filename,
    $filesize,
    $filehash,
    $icon        
);

so...

function onMediaMessageSent( $phone, $to, $id, $filetype, $url, $filename, $filesize, $filehash, $icon){
echo "File size is: $filesize \n\n File hash is: $filehash";
}   

$w->eventManager()->bind("onMediaMessageSent", "onMediaMessageSent");

Once you have the size and the hash, you can do this:

$myVideoSize = ""; // here the size you get
$myVideoHash = ""; // here the hash you get

$w->sendMessageVideo($to, $filepath, false, $myVideoSize, $myVideoHash);
faisalcse commented 10 years ago

Is it updated in the code so that I can take the updates?

mgp25 commented 10 years ago

Yes, it is updated, you can get the latest code and use it.

faisalcse commented 10 years ago

I was using the whatsapi code from: https://github.com/shirioko/WhatsAPI/blob/master/src/php/whatsprot.class.php but I see in this code not updated.

shirioko commented 10 years ago

Nope, haven't merged @mgp25's latest pull requests into my fork. I'll do it later today.

faisalcse commented 10 years ago

But I see in the code not updated.

mgp25 commented 10 years ago

You are using @shirioko 's fork. Use this https://github.com/venomous0x/WhatsAPI

faisalcse commented 10 years ago

If I copy -> whatsprot.class.php from https://github.com/venomous0x/WhatsAPI and replace in https://github.com/shirioko/WhatsAPI, Will it be ok?

mgp25 commented 10 years ago

Take the whole code from https://github.com/venomous0x/WhatsAPI Many files have been updated

faisalcse commented 10 years ago

How can I get the value of $myVideoSize and $myVideoHash?

mgp25 commented 10 years ago

0.0 i already told you above. Send the video only once. Capture the file size and file hash binding the event with the function i post it above. Once you have that values, send a video message using that values.

Oks, let do a thing, create a file named video.php and put the following code inside:

<?php
require_once 'whatsprot.class.php';

////////////////CONFIGURATION///////////////////////
////////////////////////////////////////////////////
$username = "";  // Your number                      
$password = ""; // Your password
$nickname = "Nick"; // Your nickname 
$debug = false;                        
$target = ""; // the number you are going to send the media message (the video in this case) 
$path = ""; // Path to the video    
/////////////////////////////////////////////////////
$w = new WhatsProt($username, null, $nickname, $debug);

function onMediaMessageSent( $phone, $to, $id, $filetype, $url, $filename, $filesize, $filehash, $icon){
echo "File size is: $filesize \n\n File hash is: $filehash";
}   

$w->eventManager()->bind("onMediaMessageSent", "onMediaMessageSent");

$w->connect();
$w->loginWithPassword($password);

$w->sendMessageVideo($target, $path);
$w->pollMessages();
$w->disconnect();

?>

And run that script (set your data first), and then post the output and ill guide you.

The output should be similar to this:

File size: 45221

File hash is: hbdkfjjeodnde=
faisalcse commented 10 years ago

OK let me do it

faisalcse commented 10 years ago

I Execute the file and output:

File size is: 2164835 File hash is: CGbuo/jRmcmmy0U6h0TrsMB9f4vOm/ZM/JMYwclZRQc=

mgp25 commented 10 years ago

Now use this:

$myVideoSize = ""; // here the size you get
$myVideoHash = ""; // here the hash you get

$w->sendMessageVideo($to, $filepath, false, $myVideoSize, $myVideoHash);

And it will send the video without re-uploading it to wa servers :)

faisalcse commented 10 years ago

Can I use this method in bulk.php?

mgp25 commented 10 years ago

Yes

faisalcse commented 10 years ago

Image will be the same way?

mgp25 commented 10 years ago

Yes, and audio too

faisalcse commented 10 years ago

Shall I need to make Encode the Hash Value because I am passing using POST method?

faisalcse commented 10 years ago

How can we know it send by hashvalue?

mgp25 commented 10 years ago

It only sends without re-uploading it to wa servers when you set the size and the file hash, if you dont set that, it will send it normally.