Skip to content

Instantly share code, notes, and snippets.

@luizmarcus
Created October 27, 2021 11:17
Show Gist options
  • Save luizmarcus/21164bba9b127ad2f139679548930410 to your computer and use it in GitHub Desktop.
Save luizmarcus/21164bba9b127ad2f139679548930410 to your computer and use it in GitHub Desktop.
<?php
//Obtém a URL do arquivo hospedado nos servidores do telegram de acordo com o ID
function getFileURL($id){
$result = file_get_contents("https://api.telegram.org/bot".BOT_TOKEN."/getFile?file_id=".$id);
$response = json_decode($result,true);
return "https://api.telegram.org/file/bot".BOT_TOKEN."/".$response["result"]["file_path"];
}
//Salva arquivo obtido a partir da URL do telegram
function saveFile($id){
$file = getFileURL($id);
$content = file_get_contents($file);
$filename = explode("/", $file);
file_put_contents($_SERVER['DOCUMENT_ROOT']."/seubot/files/".$filename[count($filename)-1], fopen($file, 'r'));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment