PHP Classes

PHP Telegram Bot to Purge Messages: Bot to delete messages in telegram

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-03-26 (6 months ago) RSS 2.0 feedNot enough user ratingsTotal: 20 All time: 11,292 This week: 73Up
Version License PHP version Categories
purge-bot 1.0MIT/X Consortium ...7Web services, Chat, PHP 7
Description 

Author

This package implements a bot to delete messages in Telegram.

It implements an application that can purge messages upon a command sent to the application.

The applications must be registered as Telegram bots using a Webhook application URL.

Innovation Award
PHP Programming Innovation award nominee
March 2024
Number 4
Telegram is a prevalent chat application. It allows developers to implement new chat commands that extend the original functionality of Telegram.

This package implements a Telegram chatbot that implements a command that can purge old messages.

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

Winner: 3x

Example

<?php

use Dotenv\Dotenv;
use
Mateodioev\TgHandler\Bot;
use
App\Commands\{Purge, Start, All};
use
App\MemoryDbAdapter;
use
Mateodioev\TgHandler\Log\{BulkStream, FileStream, Logger, TerminalStream};

if (
$argv[0] === \basename(__FILE__)) {
   
fprintf(STDERR, "Do not run this file directly\n");
    exit(
1);
}

Dotenv::createImmutable(__DIR__)->load();

$logger = new Logger(
    new
BulkStream( // Log to both terminal and file
       
new TerminalStream(),
        new
FileStream(env('PWD_PATH', __DIR__) . '/info.log')
    ),
);
// $logger->setLevel(Logger::DEBUG, false); // Disable debug logs

$bot = new Bot(env('BOT_TOKEN'), $logger);
$bot->setDb(new MemoryDbAdapter());

$bot->setLogger($logger)
    ->
onEvent(Purge::get())
    ->
onEvent(Start::get())
    ->
onEvent(new All());

return
$bot;


Details

Purge bot

Example bot to delete messages

Installation

Clone the repository

git clone https://github.com/Mateodioev/purge-bot purge-bot-php
cd purge-bot-php

Install dependencies

composer install

Usage

Webhook mode

For this you will need a public endpoint with https In the file webhook.php you can find an example of a simple server with _amphp/http-server_

php webhook.php

You can also set the webhook with the file setwebhook.php

php setwebhook.php

Longpolling

For this you dont need a public server, only execute the script

php longpolling.php

  Files folder image Files (16)  
File Role Description
Files folder imagesrc (5 files, 1 directory)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file .php-cs-fixer.dist.php Example Example script
Accessible without login Plain text file bot.php Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file longpolling.php Example Example script
Accessible without login Plain text file readme.md Doc. Documentation
Accessible without login Plain text file setwebhook.php Example Example script
Accessible without login Plain text file webhook.php Example Example script

  Files folder image Files (16)  /  src  
File Role Description
Files folder imageCommands (3 files)
  Plain text file FilterPublicChat.php Class Class source
  Accessible without login Plain text file helpers.php Aux. Auxiliary script
  Plain text file LoggerFactory.php Class Class source
  Plain text file MemoryDbAdapter.php Class Class source
  Plain text file RequestHandler.php Class Class source

  Files folder image Files (16)  /  src  /  Commands  
File Role Description
  Plain text file All.php Class Class source
  Plain text file Purge.php Class Class source
  Plain text file Start.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:20
This week:0
All time:11,292
This week:73Up