PDA

View Full Version : نحوه گرفتن عکس از ربات در تلگرام



hadi2016
شنبه 08 مهر 1396, 01:13 صبح
سلام دوستان
من چطوری میتونم عکسی رو که کاربر از طریق ربات برام فرستاده را توی هاستم ذخیره کنم؟
واسه دریافت متن از این کد استفاده میکنم اما واسه عکس نمیدونم چه تغییری توی کد بدم
لطفا راهنماییم کنید


$message= file_get_contents("php://input");$arrayMessage= json_decode($message, true);$token= "my token";$chat_id= $arrayMessage['message']['from']['id'];$command= $arrayMessage['message']['text'];

thacker
شنبه 08 مهر 1396, 15:24 عصر
<?php
$message = file_get_contents("php://input");
$arrayMessage = json_decode($message, true);
$token = "my token";
$chat_id = $arrayMessage['message']['from']['id'];
$command = $arrayMessage['message']['text'];
$photoID = $arrayMessage['message']['photo'][2]['file_id'];

$telegram_file_path = "https://api.telegram.org/bot" . $token . "/getFile?file_id=" . $photoID;
$file_url = json_decode(file_get_contents($telegram_file_path) ,true);
$photo = $file_url['result']['file_path'];
$photoPath = 'https://api.telegram.org/file/bot'.$token.'/'.$photo;
$fileName = 'userImage.jpg';
file_put_contents($fileName, fopen($photoPath, 'r'));


$caption = "تصویر با موفقیت دریافت شد";
$url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chat_id . "&text=" . $text;
file_get_contents($url);
?>

saeed2922
جمعه 08 دی 1396, 14:31 عصر
با سلام خدمت شما عزیزان
این کد کار نمیکنه