This little project is designed specifically for Telegram bots.
Steps
git clone https://github.com/ismailian/bot-web-handler
mv bot-web-handler /var/www/
cd /var/www/bot-web-handler/
composer install
cp .env.sample .env
[Configurations]
- domain url
APP_DOMAIN
- bot token
BOT_TOKEN
- webhook secret
TG_BOT_SIGNATURE
(Optional) - Telegram source IP
TG_SOURCE_IP
(Optional)
- routes - routes to accept requests from (Optional)
- whitelist - list of allowed user ids (Optional)
- blacklist - list of disallowed user ids (Optional)
/**
* handle all incoming photos
*
* @param IncomingPhoto $photo
* @return void
*/
#[Photo]
public function photos(IncomingPhoto $photo): void
{
echo '[+] File ID: ' . $photo->getFileId(0);
}
/**
* handle all incoming videos
*
* @param IncomingVideo $video
* @return void
*/
#[Video]
public function videos(IncomingVideo $video): void
{
echo '[+] File ID: ' . $video->getFileId();
}
/**
* handle all incoming commands
*
* @return void
*/
#[Command('start')]
public function onStart(): void
{
$this->telegram->sendMessage('welcome!');
}
/**
* handle incoming callback query
*
* @param IncomingCallbackQuery $query
* @return void
*/
#[CallbackQuery('game:type')]
public function callbacks(IncomingCallbackQuery $query): void
{
echo '[+] response: ' . $query('game:type');
}