Telegram

Installation & Setup

First you need to pull in the Telegram Driver.

composer require botman/driver-telegram

Then load the driver before creating the BotMan instance (only when you don't use BotMan Studio):

DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);

// Create BotMan instance
BotManFactory::create($config);

Or if you use BotMan Studio:

php artisan botman:install-driver telegram

This driver requires a valid and secure URL in order to set up webhooks and receive events and information from the chat users. This means your application should be accessible through an HTTPS URL.

{callout-info} ngrok is a great tool to create such a public HTTPS URL for your local application. If you use Laravel Valet, you can create it with "valet share" as well.

To connect BotMan with your Telegram Bot, you first need to follow the official guide to create your Telegram Bot and an access token.

Once you have obtained the access token, place it in your .env file like TELEGRAM_TOKEN=YOUR-TELEGRAM-TOKEN-HERE. There it gets automatically loaded to your config/botman/telegram.php file.

If you don't use BotMan Studio, add these line to $config array that you pass when you create the object from BotManFactory.

'telegram' => [
	'token' => 'YOUR-TELEGRAM-TOKEN-HERE',
]

Supported Features

This is a list of features that the driver supports. If a driver does not support a specific action, it is in most cases a limitation from the messaging service - not BotMan.

Feature Supported?
Question-Buttons ✅
Image Attachment ✅
Video Attachment ✅
Audio Attachment ✅
Location Attachment ✅

Register Your Webhook

To let your Telegram Bot know, how it can communicate with your BotMan bot, you have to register the URL where BotMan is running at, with Telegram.

You can do this by sending a POST request to this URL:

https://api.telegram.org/bot<YOUR-TELEGRAM-TOKEN-HERE>/setWebhook

This POST request needs only one parameter called url with the URL that points to your BotMan logic / controller. If you use BotMan Studio it will be: https://yourapp.domain/botman. HTTPS is a must, because of security reasons.

Instead of manually sending the request to Telegram you can use a console command to register your Webhook.

$ php artisan botman:telegram:register

Optionally you can pass the --output flag to see the json that Telegram returns.