E
E
eshanglar2020-04-20 22:17:47
PHP
eshanglar, 2020-04-20 22:17:47

Forward a Telegram message on button click?

I need that when clicking on the button under the message, this message is sent to another user specified in the script. Here is the code. Thanks in advance!

function message_to_telegram($text, $url, $recipient)
{
    $ch = curl_init();
    $keyboard = [
        'inline_keyboard' => [
            [
                ['text' => 'Загрузить', 'url' => $url],
                ['text' => 'Переслать', ТУТ ДОЛЖНО БЫТЬ ДЕЙСТВИЕ],
            ]
        ]
    ];
    $encoded_keyboard = json_encode($keyboard);
    curl_setopt_array(
        $ch,
        array(
            CURLOPT_URL => 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendMessage',
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_POSTFIELDS => array(
                'chat_id' => $recipient,
                'text' => $text,
                'reply_markup' => $encoded_keyboard
            ),
        )
    );
    curl_exec($ch);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hesy, 2020-04-20
@eshanglar

What is the problem with specifying callback_data with the user id instead of "THE SHOULD BE ACTION HERE", and when clicking, get it from the incoming array ['callback_query']['data'] and send sendMessage?

['text' => 'Переслать', 'callback_data' => 'phpfanatsuckcock'],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question