venomous0x / WhatsAPI

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

How to get the group name and messages simultaneously? #866

Closed vibhoo closed 9 years ago

vibhoo commented 10 years ago

I am using onGetGroupMessage(); to get the messages from the groups but, How would I get the name of the group(s)

Help me I am stuck

mgp25 commented 10 years ago
function onGetGroupMessage($phone, $from, $author, $msgid, $type, $time, $name, $message)
{
       echo "Group name: " . $name;
}
vibhoo commented 10 years ago

That function doesn't work, it will give you the name of the sender & message (if you want) not the 'group name'

I need 'group name' (group subject)

mgp25 commented 10 years ago

This one for example...? Please take time to read the API code, read the wiki too, you will find useful information.

function onGetGroupsSubject($phone, $gId, $time, $author, $participant, $name, $subject){
     echo "Group name: ". $subject;
}
vibhoo commented 10 years ago

Yeah that function also but still I am not getting 'group name'. I think this function is never called up

Here is what I am doing.Let me know what I am doing wrong

function asunto($phone, $gId, $time, $author, $participant, $name, $subject)
    {
     echo "Group name: ". $subject;
    }

$w = new WhatsProt($username, $token, $nickname, $debug);
$w->eventManager()->bind("onGetGroupsSubject","asunto");
$w->Connect();
$w->loginWithPassword($password);
$w->PollMessages();
mgp25 commented 10 years ago

It's because of this:

            if ($node->getAttribute('type') == "subject") {
                print_r($node);
                $reset_from = explode('@', $node->getAttribute('from'));
                $reset_author = explode('@',$node->getAttribute('author'));
                $this->eventManager()->fireGetGroupsSubject(
                    $this->phoneNumber,
                    reset($reset_from),
                    $node->getAttribute('t'),
                    reset($reset_author),
                    reset($reset_author),
                    $node->getChild(0)->getAttribute('name'),
                    $node->getChild(2)->getData()
                );
            }

I did not try it. When get a message with the attribute subject, it will fire the event. Let's do a thing, post here a sample debug of a message group and ill try to see if its fire or not

vibhoo commented 10 years ago

Yeah I also figured out the same thing, for message group I am able to send message & receive message

What else you need

mgp25 commented 10 years ago

I need to see the debug output when you receive group messages.

vibhoo commented 10 years ago

Getting NULL when trying this

$w = new WhatsProt($username, $token, $nickname, false); // tried with true & false both getting same output
$res = $w->eventManager()->bind("onGetGroupSubject","asunto");
var_dump($res);

For onGetGroupMessage function also I am getting NULL

$res = $w->eventManager()->bind("onGetGroupMessage","ongrpMessage");
var_dump($res);
mgp25 commented 10 years ago

Why you do that? Its not the way you supose to use it

vibhoo commented 10 years ago

Then what's the proper way to you it ? I am new to this Just lemme know how should i proceed

vibhoo commented 10 years ago
$w = new WhatsProt($username, $identity, $nickname, $debug);
$res = $w->eventManager()->bind("onGetGroupMessage","ongrpMessage");
var_dump($w);

object(WhatsProt)#1 (25) { ["accountInfo":protected]=> NULL ["challengeFilename":protected]=> string(17) "nextChallenge.dat" ["challengeData":protected]=> NULL ["debug":protected]=> bool(true) ["event":protected]=> object(WhatsAppEvent)#4 (0) { } ["groupList":protected]=> array(0) { } ["identity":protected]=> string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ["inputKey":protected]=> NULL ["outputKey":protected]=> NULL ["groupId":protected]=> bool(false) ["lastId":protected]=> bool(false) ["loginStatus":protected]=> string(12) "disconnected" ["mediaFileInfo":protected]=> array(0) { } ["mediaQueue":protected]=> array(0) { } ["messageCounter":protected]=> int(1) ["messageQueue":protected]=> array(0) { } ["name":protected]=> string(8) "xxxxxxx" ["newMsgBind":protected]=> bool(false) ["outQueue":protected]=> array(0) { } ["password":protected]=> NULL ["phoneNumber":protected]=> string(12) "91xxxxxxxxxxx" ["reader"]=> object(BinTreeNodeReader)#3 (2) { ["input":"BinTreeNodeReader":private]=> NULL ["key":"BinTreeNodeReader":private]=> NULL } ["serverReceivedId":protected]=> NULL ["socket":protected]=> NULL ["writer":protected]=> object(BinTreeNodeWriter)#2 (2) { ["output":"BinTreeNodeWriter":private]=> NULL ["key":"BinTreeNodeWriter":private]=> NULL } } Sender name: xxxxx\nGroup Message: Ghjj

mgp25 commented 10 years ago

Edit your comment, you shared your number and identity with us

vibhoo commented 10 years ago

Okay Thanks I have edited, Anyways that was a testing no.

Now back to main question, How to get the Group Name(Group Subject) ? any clue or help from your side ?

mgp25 commented 10 years ago

Yes, i have how is the message node, once i see how it is, i can see if its working or not, if not ill make a fix, i haven't had time to work on this yet.

shirioko commented 10 years ago

You need to call sendGetGroupInfo to trigger the onGetGroupSubject event

vibhoo commented 10 years ago

@shirioko can you please tell me how to use it any example/snippet of code will work for me as I am new to Php

mgp25 commented 10 years ago

$gjid is the group jid

$w->sendGetGroupsInfo($gjid)
vibhoo commented 10 years ago
$w = new WhatsProt($username, $identity, $nickname, $debug);
$res = $w->sendGetGroupsInfo($groupId);
var_dump($res);

I am doing like this still no success getting exception 'Socket Error'

mgp25 commented 10 years ago

@vibhoo can you try and practice with /test/whatsapp.php and /examples/exapleFunctional.php before trying to do your own scripts...

vibhoo commented 10 years ago

I tried those scripts I am able to Send & Receive Message to a Number & Even I am able to Receive Message of a group just what I want to do is to get the Group Name

mgp25 commented 10 years ago

--> here

Once you call that function, it will fire the event. You only need the group jid. Also how to obtain the group jid has already been answered, so you can search in the issue tracker :)

mayankgpt1 commented 8 years ago

dera Friends, Is there any way to Post the message to the WhatsApp group using API?