GetMessages decrypted in runtime
Closed this issue · 2 comments
Hi again,
This problem can be from the ChatAPI, but it may have another way to solve:
$messages = $messages = Whatsapi::getNewMessages();
if($messages)
{
foreach($messages as $message)
{
echo $message->body->data;
}
}
It's return:
["data"]=>
string(66) "3
!���7GÄaF�:��P(ea$Crmo���'���D��}���"����������R���C-���I�b�"
All messages coming to msgstore-XXXXXXXXX.db in \Vendor\ChatAPI\src\wadata and we have to get with query and open a conection with pdo. No chance to get in the foreach after getNewMessages ? I have the ID attribute in $message that make reference in DB table 'messages' !
Now I find a provisory solution:
In messageManager.php line 344
public function transformMessages(array $messages){}
I added this:
$children = $message->getChildren();
foreach ($children as $c){
if($c->getTag() == "body"){
$node = new stdClass();
$node->tag = $c->getTag();
$node->attributes = (object) $c->getAttributes();
$node->data = $c->getData();
break;
}
}
if(!isset($node)) {
$child = $message->getChild(0);
$node = new stdClass();
$node->tag = $child->getTag();
$node->attributes = (object)$child->getAttributes();
$node->data = $child->getData();
}
I see the messages it's coming with more than 1 node, so when get their we can compare the tag attribute with getTag(), when 'enc' is encrypted and when 'body' is decrypted text. anyway, the decrypted goes to sqlite in chat-api/src/wadata, but for me is not the best way.