![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBTsPTz4JO10KRsFFmE-QKdTx_OBLrWag3pXc0pgpbBWng7EwGRmJIqCV0kajlb-9ELm_wDVg1laIX8yw8xc9gsUhoEknQfTOugCrzSidMhSUk0omx8SQ42aKgod4arVX0od4G6HzQ498/s1600/Screen+Shot+2017-05-02+at+03.27.45.png)
All data saved up to 24h on telegram server.
If you are using direct telegram link you will get all request as json data * Bot and Channel messages.
You will get all data from your bot.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAQDoIN5Vef2_-RPaqn1bae2dFTzA4JF7RsQ_fPFMzOUjBpzXzGCE-Xg9dnL_Tm_X1_-qd1cEB0oxkJsmfJVYktz6MxmpQWaePAXx2qLQu5vw92zDBY53nDReX-o7v57h4NBJpLA_Pq7E/s640/Screen+Shot+2017-05-02+at+03.25.16.png)
getUpdates updates telegram bot without Webhook
Get all TELEGRAM data from your bot with PHP. 1 message /start
1 Message ID and 2 Text
$token = "******";
$response = file_get_contents('https://api.telegram.org/bot$token/getUpdates');
$response = json_decode($response, true);
foreach($response['result'] as $result) {
if ($result['message'] == "") {
} else {
echo $result['message']['message_id'], ' ';
echo $result['message']['text'], '
';
}
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiYxzEI5oCzQk7xMJOIpLc-4158HarqeufYai1Tn37cwMQazOHVrML31FTYKWqPbjKf8D07zgIbsXokm4MmCz62aVjGRpGY6N8kCFWBvmRxuIs_FO19LBLVa_Acrx9iqV6G2nZVPG3WZA/s1600/Screen+Shot+2017-05-02+at+03.42.28.png)
How to get only last element from Telegram getUpdates bot?
With this code you will get last element from telegram getUpdates ( Message ID and Text)
$token = "******";
$response = file_get_contents('https://api.telegram.org/bot$token/getUpdates');
$response = json_decode($response, true);
$numItems = count($response['result'])-1;
$i = 0;
foreach($response['result'] as $key=>$value) {
if(++$i === $numItems) {
if($response['result'][$numItems]['message'] == "") {
$data = "Channel post";
$msgid = $response['result'][$numItems]['channel_post']['message_id'];
$msgtext = $response['result'][$numItems]['channel_post']['text'];
}
else {
$data = "Bot post";
$msgid = $response['result'][$numItems]['message']['message_id'];
$msgtext = $response['result'][$numItems]['message']['text'];
}
}
}
echo "Last $data : ID: $msgid | Text: $msgtext";
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb4Lz_zAFo-9FFHkgOs8gs3E0_a4PV8NdSiwnkkt_lz2ciaBIE5ra0QmyMYcbmaIt5Lvxm5WvVT4BPXlNNjTjthpr5_tWTWMsyuRVoocoCeMCE-ix1eZSY5nOx8sWq4CyWWNUAsu3V4OI/s1600/Screen+Shot+2017-05-02+at+03.52.59.png)
This script not automatic. You can use CRON for script auto launch. Then you can save data from Telegram to Data base (Mysql,Sql).
https://www.facebook.com/chakabiz
https://www.youtube.com/channel/UCYuMRNb_SRZ4FMsZjnHRZUA
HEllo trying to run this code but it fails when sending message it appears blank or this messages on php
ReplyDeleteE_NOTICE : type 8 -- Undefined index: message -- at line 7
E_NOTICE : type 8 -- Undefined index: message -- at line 7
E_NOTICE : type 8 -- Undefined index: message -- at line 7