1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?php function sendMessage($chatID, $messaggio, $token, $message_id = null) { echo "sending message to " . $chatID . "\n"; $url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chatID; $url = $url . "&text=" . urlencode($messaggio); if ($message_id) { $url = $url . "&reply_to_message_id=" . $message_id; } $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; } function sendPhoto($chatID, $messaggio, $token) { echo "sending message to " . $chatID . "\n"; $url = "https://api.telegram.org/bot" . $token . "/sendPhoto?chat_id=" . $chatID; $url = $url . "&photo=http://site.ru/img.png&caption=Тут кароче до 200символов типа ФИО можно грузить и город)"; $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; } $obj = new stdClass(); $obj->token = 'ТУТ ТОКЕН'; $obj->chat = '@my_CHAnnel'; $obj->message = isset($_GET['m']) ? $_GET['m'] : 'нет гет параметра'; $photo = sendPhoto($obj->chat, $obj->message, $obj->token); $result = json_decode($photo); $img_id = $result->result->message_id; var_dump(sendMessage($obj->chat, $obj->message, $obj->token, $img_id)); |