1

I want to get the full message sent by the person's ID in telegram bot , including all the attached files, such as a photo , audio, image, or a caption and photo ... , and send it to another person's ID. I don't want it to be forward , I want to be sent! I receive all updates this way:

$data=json_decode(file_get_contents("php://input"));

my code :

    <?php
const apiKey='112';
$channels=[
    '1'=>'-1001233909561',
    '2'=>'-1001198102700',
];
const admin='668400001';
//-------------------------------------------------------- End Channels and ADMIN Info
$data=json_decode(file_get_contents("php://input"));
$json_data=json_encode($data);
file_put_contents('data.json', $json_data);
function bot($method, $datas = [])
{
    $url = "https://api.telegram.org/bot" . apiKey . "/" . $method;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($datas));
    $res = curl_exec($ch);
    if (curl_error($ch))
    {
        var_dump(curl_error($ch));
    }
    else
    {
        return json_decode($res);
    }
}

 function forwardMessage($messageId)
{

    bot('forwardMessage',[
        'chat_id'=>backupChannelId,
        'from_chat_id'=>firstChannelId,
        'message_id'=>$messageId,
    ]);
}

function sendMessage($toChannel,$message)
{

}



?>

1 Answers1

2

If I understand correctly, you want to get the text and all the attachments of all messages sent to the bot. For example, the text of the message is in update->message-> text.

$text = $data['message']['text'];
$audio = $data['message']['audio'];

The easiest way to send the exact same massage to another chat is by forwarding it, otherwise you have to search for all the possible attachments in the message object and, if present, send them to the other chat with the corrisponding method (sendPhoto, sendAudio etc.).


Tip:

use

$data = json_decode(file_get_contents("php://input"), true);

instead of

$data = json_decode(file_get_contents("php://input"));

More details here

GioIacca9
  • 406
  • 4
  • 8