Longman\TelegramBot\Commands\AdminCommands\SendtochannelCommand::sendBack PHP Method

sendBack() protected method

Received a message, the bot can send a copy of it to another chat/channel. You don't have to care about the type of the message, the function detect it and use the proper REQUEST:: function to send it. $data include all the var that you need to send the message to the proper chat
protected sendBack ( Message $message, array $data ) : ServerResponse
$message Longman\TelegramBot\Entities\Message
$data array
return Longman\TelegramBot\Entities\ServerResponse
    protected function sendBack(Message $message, array $data)
    {
        $type = $message->getType();
        in_array($type, ['command', 'text'], true) && ($type = 'message');
        if ($type === 'message') {
            $data['text'] = $message->getText(true);
        } elseif ($type === 'audio') {
            $data['audio'] = $message->getAudio()->getFileId();
            $data['duration'] = $message->getAudio()->getDuration();
            $data['performer'] = $message->getAudio()->getPerformer();
            $data['title'] = $message->getAudio()->getTitle();
        } elseif ($type === 'document') {
            $data['document'] = $message->getDocument()->getFileId();
        } elseif ($type === 'photo') {
            $data['photo'] = $message->getPhoto()[0]->getFileId();
        } elseif ($type === 'sticker') {
            $data['sticker'] = $message->getSticker()->getFileId();
        } elseif ($type === 'video') {
            $data['video'] = $message->getVideo()->getFileId();
        } elseif ($type === 'voice') {
            $data['voice'] = $message->getVoice()->getFileId();
        } elseif ($type === 'location') {
            $data['latitude'] = $message->getLocation()->getLatitude();
            $data['longitude'] = $message->getLocation()->getLongitude();
        }
        $callback_path = 'Longman\\TelegramBot\\Request';
        $callback_function = 'send' . ucfirst($type);
        if (!method_exists($callback_path, $callback_function)) {
            throw new TelegramException('Methods: ' . $callback_function . ' not found in class Request.');
        }
        return $callback_path::$callback_function($data);
    }