Muaath5 / SimpleBotAPI

Simple & Easy Telegram Bot API in PHP

Home Page:https://muaath5.github.io/SimpleBotAPI/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple Bot API

Licence: GPL v3.0 Bot API Version: 5.6 PHP Unit Tests

This is a simple Telegram Bot API library in PHP. This library should support all Bot API methods in any version update. I created this library to make creating bots more simpliler, No need to bunch of classes And objects after today!

Features

  • Always supports all Bot API methods
  • Auto handling for flood & chat ID migrating errors
  • Uses stdClass for updates
  • Uses OOP
  • Optional Settings for each bot can be saved in JSON
  • Based on cURL for speed
  • Downloadable via composer
  • Tested via GitHub Actions
  • Has examples of working bots
  • Telegram Errors as PHP Exceptions
  • Up to date
  • Documented

Installation

Installation Guide

Simple Usage

Creating bot

use SimpleBotAPI/TelegramBot;
use SimpleBotAPI/BotSettings;

$Bot = new TelegramBot('bot_token');

More documentation here

Using method

It should be in this format:

$Result = $Bot->{methodName}([
    '{paramName}' => {value1},
    '{paramName2}' => {value2}
]);

Like this:

$Bot->SendMessage([
    'chat_id' => '@MuaathBots',
    'text' => 'This post was sent by the bot..'
]);

$my_channel_info = $Bot->getChat([
    'chat_id' => '@MuaathBots',
]);
echo "Your channel (@{$my_channel_info->username}) ID: {$my_channel_info->id}";

Note: There's NO PROBLEM if methodName was in upper or lower case.

Contibuting

You can contribute by:

  • Reporting a bug.
  • Suggesting a feature.
  • Improving code style.
  • Completing the TODO List.
  • Adding more examples to examples/.
  • Documenting undocumented topics in docs/.
  • Updating the library to the next version of Bot API (if needed).
  • Adding more tests in test/ folder.

Contact me

@Muaath_5 on Telegram muaath1428@hotmail.com

Examples

Currently, There're three examples in examples/ folder:

  • Echo Bot, Which sends same as you sent
  • Weclome Bot, Which sends Welcome & ID of user who joins the group
  • Contact Me Bot, Which is a Bot be same as you, You'll receive messages & Reply
  • FAQ Bot, Which has one message & buttons to swap between questions, And you can see answers.

You can see a full example here

All of these examples doesn't need any databases or files to storage, Only Settings file.

TODO List

  • API via HTTP response in webhooks method
  • Using namespace for exceptions
  • Documenting sending message with reply markup
  • Add webhook authorization
  • Auto-store for bot users
  • Add JSON Storage can be used by bot
  • Method that posts to all bot users
  • Add logging
  • Add DB Storage can be used by bot
  • Document missed things

License

Licence: GPL v3.0 GPL-3.0, In LICENCE file.

About

Simple & Easy Telegram Bot API in PHP

https://muaath5.github.io/SimpleBotAPI/

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%