tony power
Posts: 33
Joined: Tue Mar 08, 2016 9:07 pm

PHP telegrambot to execute http get/post requests

Wed Aug 17, 2016 9:06 pm

I set up PHP telegramBot successfully on hosting website using webhook with https link

this is the library
https://github.com/TelegramBot/

I want it when I user sends a command on telegramBot conversation, then the php page of telegrambot to execute http get or post to the webserver installed on raspberry pi it has public ip with dns name and it is reachable from public internet.

I tried this PHP code which is telegrambot callback webhook (https://server.com/bot.php)

Code: Select all

<?php
require_once "vendor/autoload.php";
try {
 /// XXXXXXX is the token
    $bot = new \TelegramBot\Api\Client('XXXXXXX');

    $bot->command('test', function ($message) use ($bot) {
        file_get_contents("http://1.2.3.4:11258/get.php");
       $bot->sendMessage($message->getChat()->getId(), 'received');
    });
	

    $bot->run();

} catch (\TelegramBot\Api\Exception $e) {
    $e->getMessage();
}
?>

when user enters /test in the bot conversation on telegram it receives the message 'received' but http get is not executed.
apache installed on raspberry pi is listening on port 11258
http://1.2.3.4:11258


am I doing something wrong?
if there are any different approaches please let me know.

tony power
Posts: 33
Joined: Tue Mar 08, 2016 9:07 pm

Re: PHP telegrambot to execute http get/post requests

Thu Aug 18, 2016 9:04 am

Solved the problem using manual getUpdates polling api of telegram API. webhook is a better way but I cannot use it because I cannot pass http get requests throught telegram servers and cannot get public ip of web server on raspberry pi and reachable to the internet.

because my ISP is blocking portforwarding.

I used this python library on raspberry pi

https://github.com/eternnoir/pyTelegram ... /README.md

Return to “Beginners”