Created
August 12, 2020 22:57
-
-
Save RuslanAsadov/abc06d1b88983367f2031b424d59115a to your computer and use it in GitHub Desktop.
Send to telegram php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function construct_telegram_text($arr) { | |
$str = ''; | |
foreach($arr as $row){ | |
$str .= '*'.$row[0].'*: '.$row[1]."\r\n"; | |
} | |
return $str; | |
} | |
function send_to_telegram($message, $files = [], $caption = '') { | |
$token = '1377229810:AAEMrzk-EgRqP99bCvaIfF8YwX6_N8gGQzg'; | |
$chat_id = '-420564757'; | |
$url = "https://api.telegram.org/bot$token"; | |
$data_text = array( | |
'chat_id'=>$chat_id, | |
'parse_mode' => 'markdown', | |
'text'=>$message | |
); | |
$response_text = file_get_contents("$url/sendMessage?" . http_build_query($data_text) ); | |
$data_files = array( | |
'chat_id'=>$chat_id | |
); | |
$path_files = parse_files_send($files); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
"Content-Type:multipart/form-data" | |
)); | |
curl_setopt($ch, CURLOPT_URL, $url . '/sendPhoto?chat_id='.$chat_id); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
foreach($path_files as $filename => $fileupload) { | |
$data_files['photo'] = new CURLFile(realpath($fileupload)); | |
$data_files['caption'] = $caption; | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_files); | |
$output = curl_exec($ch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment