chipslays/litegram

Simple, flexible, modular library for Telegram Bot Api.

3.0.17 2023-08-08 05:46 UTC

README

GitHub Workflow Status GitHub

v3.x under wip, but can usable.

Simple, flexible, modular library based on events for Telegram Bot Api.

Litegram can be used as a regular lightweight library or as a framework with added of plugins.

⭐ Features

  • Events based (Routing);
  • Cache (Redis, Memcached);
  • Database (based on Laravel Database + Eloquent);
  • Middlewares;
  • Localization (based on Phrase);
  • Sessions (based on Storage plugin);
  • Storage (Flat files, Database drivers);
  • Talk (Chain Conversation);
  • Validation (based on Respect/Validation);
  • Stemming;
  • Plugins and Components;
  • Supports Webhooks & Simple Long-polling (not async);

🔩 Installation

Install via Composer:

$ composer require chipslays/litegram

📁 Litegram Project

You can use a ready-made and configured project for a quick start.

See more information here.

1️⃣ Create project:

composer create-project chipslays/litegram-project SuperDuperBot

2️⃣ Change the parameters of the configs and finally type in Terminal:

php lite webhook:set
php lite migration:up

🎉 Congratulation, bot project was set up.

💡 Examples

require 'vendor/autoload.php';

$bot = bot($config)->webhook();

$bot->command('start', function () use ($bot) {
    $bot->ask('What is your name?', function () use ($bot) {
        $name = $bot->payload('message.text');
        $bot->reply("👋 Nice to meet you, {$name}!");
    });
});

// or
$bot->command('start', 'BotController@startConversation');

$bot->run();

Note: Method ask work correctly only if storage driver set as file.

More examples you can see here.

📖 Documentation

Documentation can be found here.

🧩 VS Code Extension

Install Litegram Snippets extension for VS Code to increase productivity.

🔑 License

Released under the MIT public license. See the enclosed LICENSE for details.