Skip to content
Milly Khamroev edited this page Sep 9, 2024 · 1 revision

Laragram – Simplified Telegram Bot Development for Laravel

Laragram is a powerful and easy-to-use Laravel package that streamlines the development of Telegram bots. Whether you're building a simple bot or a complex multi-bot system, Laragram offers seamless integration with Laravel’s rich feature set, making bot development more efficient than ever.

Key Features

1. Local Development (No Webhook Required)

Developing Telegram bots locally has never been easier! With Laragram, you can start your bot locally without needing to configure webhooks. Simply use the following command to get updates in real-time during development:

php artisan laragram:start

This allows you to instantly receive and test Telegram updates in your local environment, boosting development speed and convenience.


2. Multi-Bot Support

Laragram’s multi-bot feature allows you to manage multiple bots within a single project effortlessly. You can dynamically set the token for each bot, making it easy to switch between different bots on the fly.

Example Usage:

Laragram::setToken('token1');
Laragram::sendMessage(chat_id: $chatId, text:'This is from the first bot']);

Laragram::setToken('token2');
Laragram::sendMessage(chat_id: $chatId, text: 'This is from the second bot']);

This feature allows flexibility in managing multiple bots and their respective contexts, even within the same application logic, by simply switching tokens when needed.


3. FSM Routing Support

Laragram supports Finite State Machine (FSM) Routing, similar to Laravel's routing, making it easy to manage user state transitions. You can define state-based routing to control how your bot interacts with users based on their current state.

Example:

// in routes: api.php
FSM::route('awaiting_input', [BotController::class, 'handleInput']);

// in controller
FSM::update('got_input');

This feature simplifies the management of complex bot interactions, making it easy to track user progress and flow through different states.


4. Automatic Telegram SDK Updates

Keep your bots up-to-date with Telegram’s latest features without waiting for a new package release. Laragram includes an auto-update command that updates the Telegram SDK methods as soon as new API features are available:

php artisan laragram:update-api

This ensures that your bots always have access to the newest Telegram features without requiring package upgrades, saving you time and effort.


Why Choose Laragram?

  • Effortless Local Development: No need for webhooks during local development, making it quick and easy to test and iterate on your bot's features.
  • Manage Multiple Bots: Seamlessly switch between multiple bots with the Laragram::setToken() method, ideal for projects requiring several bot instances.
  • Advanced FSM Routing: Handle user states with ease using FSM routing, giving your bots a more interactive and context-aware flow.
  • Stay Current with Telegram API: Automatically update to the latest Telegram SDK methods with a single command, ensuring your bots are always equipped with the latest tools.

Get Started

  1. Installation Guide
  2. Basic Bot Setup
  3. Advanced Features

Explore the full documentation to get started with Laragram and see how it can transform your Telegram bot development.