Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram php example send message [closed]

Tags:

I can't find an example of sending message by telegram protocol from php. Can you give me any functional examples?

like image 746
user3537042 Avatar asked Jul 24 '15 21:07

user3537042


People also ask

How can I send Message to Telegram using PHP?

To send a message to the Telegram channel use the following PHP script example: <? php $apiToken = "5082654068:AAF7quCLZ4xuTq2FBdo3POssdJsM_FRHwTs"; $data = [ 'chat_id' => '515382482', 'text' => 'Hello from PHP! ' ]; $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .

Can Telegram bot send Message to phone number?

It is NOT possible for a bot to send messages to a phone number.


1 Answers

I use the following function:

function sendMessage($chatID, $messaggio, $token) {     echo "sending message to " . $chatID . "\n";      $url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chatID;     $url = $url . "&text=" . urlencode($messaggio);     $ch = curl_init();     $optArray = array(             CURLOPT_URL => $url,             CURLOPT_RETURNTRANSFER => true     );     curl_setopt_array($ch, $optArray);     $result = curl_exec($ch);     curl_close($ch);     return $result; } 

and you call in this way

$token = "<insert bot token here>"; $chatid = "<chatID>"; sendMessage($chatid, "Hello World", $token); 
like image 57
Mauro Delrio Avatar answered Dec 26 '22 05:12

Mauro Delrio