protected function sendMessageNode($to, $node, $id = null, $plaintextNode = null)
    {
        $msgId = ($id == null) ? $this->createMsgId() : $id;
        $to = $this->getJID($to);

        if ($node->getTag() == 'body' || $node->getTag() == 'enc') {
            $type = 'text';
        } else {
            $type = 'media';
        }

        $messageNode = new ProtocolNode('message', [
            'to'      => $to,
            'type'    => $type,
            'id'      => $msgId,
            't'       => time(),
            'notify'  => $this->name,
        ], [$node], '');

        $this->sendNode($messageNode);

        if ($node->getTag() == 'enc') {
            $node = $plaintextNode;
        }

        $this->logFile('info', '{type} message with id {id} sent to {to}', ['type' => $type, 'id' => $msgId, 'to' => ExtractNumber($to)]);
        $this->eventManager()->fire('onSendMessage',
            [
                $this->phoneNumber,
                $to,
                $msgId,
                $node,
            ]);

       // $this->waitForServer($msgId);

        return $msgId;
    }