PHP Classes

PHP Telegram Bot Handler: Create a Telegram bot to respond to certain events

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 44 All time: 10,821 This week: 129Up
Version License PHP version Categories
telegram-bot-handler 1.0.0MIT/X Consortium ...5PHP 5, Web services, Chat
Description 

Author

This package can create a Telegram bot to respond to specific events.

It can register the event handler to react when the package calls certain Telegram chat events happento functions that the package will call.

Currently can register callback functions to handle events like:

- Message

- Photo

- Video

- Audio

- Voice

- Documment

- Sticker

- Venue

- Location

- Inline

- Callback

- New chat member

- Left chat member

- New chat title

- New chat photo

- Group chat created

- Supergroup chat created

- Migrate to chat id

- Migrate from chat id

- Edited

- Game

- Channel

- Edited channel

Picture of Mateo
  Performance   Level  
Name: Mateo <contact>
Classes: 23 packages by
Country: Peru Peru
Age: ???
All time rank: 20464 in Peru Peru
Week rank: 63 Up1 in Peru Peru Up
Innovation award
Innovation award
Nominee: 10x

Winner: 3x

Example

<?php

use Mateodioev\Bots\Telegram\Methods;
use
Mateodioev\TgHandler\Commands;

require
__DIR__ . '/../vendor/autoload.php';
require
__DIR__ . '/functions.php';

$cmd = new Commands(cmd_prefix: ['/', '!', '.']); // Support for /start, !start, .start
$cmd->setBotUsername('your bot username');

$bot = new Methods('your telegram bot token'); // https://telegram.me/botfather

// Register new message command
$cmd->CmdMessage('start', 'sendHello', [$bot]);

$update = json_decode(file_get_contents('php://input')) or die('No update');
$cmd->setUpdate($update);

runBot($cmd);


Details

Telegram bot handler

Installation

composer require mateodioev/tg-handler

Usage

See examples folder for more information.

use Mateodioev\TgHandler\Commands;
$cmd = new Commands($namespace, $commandsPrefix);

Register commands

Text commands

$cmd->CmdMessage($cmd, $callable, $functionParams);

Callback data

$cmd->CmdCallback($cmd, $callable, $functionParams);

Inline querys

$cmd->CmdInline($cmd, $callable, $functionParams);

Middlewares

Middlewares are executed before the command is executed.

_Types:_ message, photo, video, audio, voice, documment, sticker, venue, location, inline, callback, new_chat_member, left_chat_member, new_chat_title, new_chat_photo, group_chat_created, supergroup_chat_created, migrate_to_chat_id, migrate_from_chat_id, edited, game, channel, edited_channel

$cmd->on($type, $callable, $functionParams);

Run commands

Run all comands registered and execute after middleware.

// Optional param
$cmd->run($afterMidleware);

  Files folder image Files (11)  
File Role Description
Files folder imageexamples (4 files)
Files folder imagesrc (3 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (11)  /  examples  
File Role Description
  Accessible without login Plain text file functions.php Example Example script
  Accessible without login Plain text file getUpdates.php Example Example script
  Accessible without login Plain text file hello.php Example Example script
  Accessible without login Plain text file send_button.php Example Example script

  Files folder image Files (11)  /  src  
File Role Description
  Plain text file Commands.php Class Class source
  Plain text file Updates.php Class Class source
  Plain text file UpdatesTrait.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:10,821
This week:129Up