This repository was archived by the owner on Sep 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 176
Getting updates via Webhook
Alexey Skobkin edited this page Jan 5, 2017
·
5 revisions
The first thing you'll have to do is register a webhook with Telegram via the SetWebhook method:
use \unreal4u\TelegramAPI\TgLog;
use \unreal4u\TelegramAPI\Telegram\Methods\SetWebhook;
$setWebhook = new SetWebhook();
$setWebhook->url = '[YOUR HTTPS URL]';
$tgLog = new TgLog(BOT_TOKEN);
$tgLog->performApiRequest($setWebhook);This will leave you prepared to start receiving updates on the chosen URL:
use \unreal4u\TelegramAPI\Telegram\Types\Update;
// Getting POST request body and decoding it from JSON to associative array
$updateData = json_decode(file_get_contents('php://input'), true);
$update = new Update($updateData);Now $update will contain the actual Update object. Hope that wasn't too difficult :)
More information on this? You can check how I implemented my timeBot. Take however into account that the cited repo is only a playground (for now), so it can happen that things in that repository may or may not work as expected.