Wallogit.com
2017 © Pedro Peláez
Telegram package
Allow your users to connect Telegram with your app and receive notifications;, (*1)
composer require furqansiddiqui/telegram, (*2)
Telegram instance by passing your telegram bot API key to constructor<?php
$telegram = new \Telegram\Telegram("YOUR-API-KEY");
<?php
/** @var $telegram \Telegram\Telegram */
$telegram->webHooks()->setWebHook("https://www.domain.tld/telegram");
Create a handler class that extends AbstractHandler with each method for every command you wish to respond to., (*3)
BasicHandler class for an example.<?php /** @var $telegram \Telegram\Telegram */ $telegram->setHandler(new MyCustomHandler($telegram)); $telegram->listen($_REQUEST);
Refer to class BasicHandler for better understanding on writing your own custom handler., (*4)
Use sendMessage method to send a message to specific user or chat., (*5)
If you have associated a "chat_id" param with one of your users, retrieve this value to send a notification/message to that specific user at any time., (*6)
<?php /** @var $telegram \Telegram\Telegram */ $telegram->sendMessage($chatId, "Your-Message");
NOTE: This method is ideal for Non-interactive messaging, i.e. User had previously subscribed to your bot via "start" or any other custom command and now you can send alerts/notification to this user., (*7)
For interactive messaging, You can use sendReply method in your custom handler as a quicker way around., (*8)