Y
Y
Yuriy2017-03-24 17:25:41
Telegram
Yuriy, 2017-03-24 17:25:41

How to send a message to a user from a telegram bot?

How to send a message to a user from a telegram bot?
the bot has been added to the contact list, how can I send a message from the bot now?
Well, like
Hello Vasya, my name is Bot Ivanovich, it's 12:04, I need to go to lunch.
ps. meaning POST or GET request

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2017-03-24
@AloneCoder

function sendMessage($chatId, $message, $token)
{
    $url = "https://api.telegram.org/{$token}/sendMessage?" . http_build_query([
            'chat_id' => $chatId,
            'text' => $message
        ]);
    $ch = curl_init();
    $optArray = [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true
    ];
    curl_setopt_array($ch, $optArray);
    curl_exec($ch);
    curl_close($ch);
}

V
Vitaly, 2017-04-22
@MrCute

This is done via the API:
https://api.telegram.org/bot <YOUR_TOKEN>/sendMessage?chat_id=&text=<TEXT>
For example (see link),
https://api.telegram.org/ bot365877050:AAE232342348...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question