michyaraque/simpletelegrambot

There is no license information available for the latest version (v1.0.0) of this package.

A complete Telegram bot API implementation written in PHP, with support for inline bots and fully componetized!

v1.0.0 2021-11-29 03:15 UTC

This package is auto-updated.

Last update: 2024-03-29 04:20:05 UTC


README

Imagine being able to create a bot with a few steps and each menu or function as if it were a method of a class. I have developed this tool to make it easier to create bots that require interaction between several screens.

Project overview

Prerequisites

- PHP >= 7.4
- Redis
- Mysql Mariadb
- Domain with SSL

Features

  • Components inside another components
  • Easy component creation
  • Easy step proccess

How to use Components

In the event Events folder you can create a bunch of different loader or separated bots.

Events Folder Structure

Events
   └── example
       ├── main.php
       └── __query_helpers.php

To load this structure folder you have to define in the public folder

$events = new EventLoader(Updates::userId(), Updates::language());
$events->setPath('example');
$events->forceEvents(['main.php', '__query_helpers.php']);
$events->getEvents();

In main.php you have to declare the Components route like this

Component::group('Example', function ($component) {
    $component->include('initialPanels')->get([
        'start' => ['commands' => ['start', 'cancel']],
    ])->init();
});
  • start refers to the static function inside the initialPanels folder that is inside the Example path
  • initialPanels has to be named as InitialPanelsComponent.php

The folder structure of the components is as follows and you can add as many as you like

Components
   ├── Example
   │   └── InitialPanelsComponent.php
   └── Component.php

initialPanelsComponent.php overview

<?php

namespace App\Components\Example;

use App\Models\Data;
use App\Components\Component;
use Telegram\{Client, Updates};

class InitialPanelsComponent extends Component {

    public static function start() {
        Client::sendMessage(Updates::userId(), "Example message");
    }

}

How to > Telegram functions

Telegram updates are loaded globally in the Updates class, which you can use anywhere in static form

Simple sendMessage with inline keyboard

$inline_keyboard = new InlineKeyboard;
$inline_keyboard->inlineKeyboardButton('Button name', 'callback_identifier');
$inline_keyboard->endRow();

Client::sendMessage(Updates::userId(), "Example message", [
    'reply_markup' => $inline_keyboard->inlineKeyboardMarkup()
]);

License

MIT