Last active
April 7, 2020 19:43
-
-
Save salvatorecordiano/714bdcdf93ac489d0f55611adf6de337 to your computer and use it in GitHub Desktop.
Sample Telegram Bot (4)
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 | |
// insert here your Bot API token | |
define("BOT_TOKEN", "..."); | |
$content = file_get_contents("php://input"); | |
$update = json_decode($content, true); | |
if(!$update) | |
{ | |
exit; | |
} | |
$message = isset($update['message']) ? $update['message'] : ""; | |
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : ""; | |
$text = isset($message['text']) ? $message['text'] : ""; | |
$botUrl = "https://api.telegram.org/bot" . BOT_TOKEN . "/sendPhoto"; | |
// change image name and path | |
$postFields = array('chat_id' => $chatId, 'photo' => new CURLFile(realpath("image.png")), 'caption' => $text); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data")); | |
curl_setopt($ch, CURLOPT_URL, $botUrl); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); | |
// read curl response | |
$output = curl_exec($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ciao Salvatore,
grazie per la guida! volevo chiederti se è possibile realizzare un bot che in base al messaggio ricevuto, possa rispondere con un messaggio di testo o con un'immagine a seconda dei casi.
Grazie