SDK for latest version of Telegram bots API

Overview

SDK for latest version of Telegram bots API (from April 24, 2020)

Using Examples

Installing

composer require "DiyorbekUz/Telelib: dev-master"

Init bot


require 'vendor/autoload.php';

$token = '123456:AAAAAAAAAAAAAAA';
$username = 'ExampleBot';
$bot = new DiyorbekUz\Telelib\Bot($token, $username);

Sending message

getCode()}: {$e->getMessage()}"; } catch (DiyorbekUz\Telelib\Exceptions\CurlError $e) { echo "cURL error #{$e->getCode()}: {$e->getMessage()}"; } ">

require 'vendor/autoload.php';

$token = '123456:AAAAAAAAAAAAAAA';
$username = 'ExampleBot';
$bot = new DiyorbekUz\Telelib\Bot($token, $username);

$chat_id = 123456789;
$message_text = 'Hi!';
$request = $bot->sendMessage($chat_id, $message_text);

try {
    $response = $request->sendRequest();
    echo 'Successful sent';
} catch (DiyorbekUz\Telelib\Exceptions\ApiError $e) {
    echo "API error #{$e->getCode()}: {$e->getMessage()}";
} catch (DiyorbekUz\Telelib\Exceptions\CurlError $e) {
    echo "cURL error #{$e->getCode()}: {$e->getMessage()}";
}

Set webhooks handler

getCode()}: {$e->getMessage()}"; } catch (DiyorbekUz\Telelib\Exceptions\CurlError $e) { echo "cURL error #{$e->getCode()}: {$e->getMessage()}"; } ">

require 'vendor/autoload.php';

$token = '123456:AAAAAAAAAAAAAAAA';
$username = 'ExampleBot';
$bot = new DiyorbekUz\Telelib\Bot($token, $username);

$webhooks_handler_url = 'https://example.com/script.php';
$request = $bot->setWebhook($webhooks_handler_url);

try {
    $request->sendRequest();
    echo 'Success';
} catch (DiyorbekUz\Telelib\Exceptions\ApiError $e) {
    echo "API error #{$e->getCode()}: {$e->getMessage()}";
} catch (DiyorbekUz\Telelib\Exceptions\CurlError $e) {
    echo "cURL error #{$e->getCode()}: {$e->getMessage()}";
}

Receive incoming updates via an outgoing webhook

getAction()) { case DiyorbekUz\Telelib\Types\Update::ACT_MESSAGE: $request = $bot->sendMessage($update->message->chat->id, 'Hi!'); break; case DiyorbekUz\Telelib\Types\Update::ACT_EDITED_MESSAGE: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_CHANNEL_POST: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_EDITED_CHANNEL_POST: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_INLINE_QUERY: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_CHOSEN_INLINE_RESULT: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_CALLBACK_QUERY: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_SHIPING_QUERY: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_PRE_CHECKOUT_QUERY: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_POLL: // ... break; case DiyorbekUz\Telelib\Types\Update::ACT_POLL_ANSWER: // ... break; } if ($request !== null) { header('Content-Type: application/json'); echo json_encode($request->getRequestData(), JSON_THROW_ON_ERROR); } ">

require 'vendor/autoload.php';

$token = '123456:AAAAAAAAAAAAAAA';
$username = 'ExampleBot';
$bot = new DiyorbekUz\Telelib\Bot($token, $username);

$input = file_get_contents('php://input');
if ($input === false || $input === '') {
    throw new Error('Input is empty');
}

$input_decoded = json_decode($input, true, 512, JSON_THROW_ON_ERROR);
if (!is_array($input_decoded)) {
    throw new Error("Input are not JSON array: $input");
}

$request = null;
$update = new DiyorbekUz\Telelib\Types\Update($input_decoded);

switch ($update->getAction()) {
    case DiyorbekUz\Telelib\Types\Update::ACT_MESSAGE:
        $request = $bot->sendMessage($update->message->chat->id, 'Hi!');
        break;
    
    case DiyorbekUz\Telelib\Types\Update::ACT_EDITED_MESSAGE:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_CHANNEL_POST:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_EDITED_CHANNEL_POST:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_INLINE_QUERY:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_CHOSEN_INLINE_RESULT:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_CALLBACK_QUERY:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_SHIPING_QUERY:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_PRE_CHECKOUT_QUERY:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_POLL:
        // ...
        break;

    case DiyorbekUz\Telelib\Types\Update::ACT_POLL_ANSWER:
        // ...
        break;
}

if ($request !== null) {
    header('Content-Type: application/json');
    echo json_encode($request->getRequestData(), JSON_THROW_ON_ERROR);
}

Connection database


define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'pdo_test');
require_once('config.php');
$db = new mPDO(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
?>

For example

rows) { var_dump($query->row['email']); // string(14) "[email protected]" } ">
$query = $db->query("SELECT * FROM `customer` WHERE `name` LIKE 'John'");
if ($query->rows) {
    var_dump($query->row['email']); // string(14) "[email protected]"
}
$db->query("UPDATE `customer` SET `email` = '[email protected]' WHERE `id` = '2'");

SqLite

$db = new SQLite3('database.db');

$results = $db->query('SELECT bar FROM foo');
while ($row = $results->fetchArray()) {
    var_dump($row);
}
You might also like...
Integrate Your PHP Code With Telegram Bot API for Beginner

Documentation[https://core.telegram.org/bots/api] Resource[https://github.com/bachors/KBBI.sql] Integrate Your PHP Code With Telegram Bot API for Begi

Easy to install email tracker with gui and telegram api bot with date device & ip tracking,

mail-php-tracking-with-gui 📧 Simple mail tracking program that uses php, html, telegram bot, and a gui The gui The gui lets you create specific links

Active Campaign API Version 3

Active Campaign API Version 3

A PHP SDK for the GlobalSmartOTP API.
A PHP SDK for the GlobalSmartOTP API.

GlobalSmartOTP PHP SDK A PHP SDK for the GlobalSmartOTP API. Requirements PHP 7.4 or higher cURL Installation $ git clone [email protected]:GlobalSmartOT

Official PHP SDK for interacting with the Knock API.

Knock PHP library Documentation See the documentation for PHP usage examples

Universal payments API SDK (UNOFFICIAL QIWI CLIENT)

Qiwi Php Client Especially for 🦊 Zorra Telecom and 👥 Everyone else Привет Attention: At the moment the number of methods is very limited, they will

A telegram bot to check credit cards. written in php & py

MRBANKER BOT A telegram bot to check credit cards. written in php & py. You can find me on telegram STEP1: goto botfather create a bot copy the token

NovaGram - An elegant, Object-Oriented, reliable PHP Telegram Bot Library
NovaGram - An elegant, Object-Oriented, reliable PHP Telegram Bot Library

An elegant, Object-Oriented, reliable PHP Telegram Bot Library Full Documentation • Public support group Examples • Features • Installation ?

A tool for sending fast and managed messages to Telegram bot users

👋🏻 HiToAll A tool for sending fast and managed messages to Telegram bot users About In some telegram bots programmed with php language, if there are

Owner
Diyorbek
Diyorbek Ermamatov 16 y.o Telegram bot and Site programmer
Diyorbek
TeleBot - Easy way to create Telegram-bots in PHP. Rich Laravel support out of the box.

TeleBot is a PHP library for telegram bots development. Rich Laravel support out of the box. Has an easy, clean, and extendable way to handle telegram Updates.

WeStacks 206 Jan 6, 2023
Telegraph - a Laravel package for fluently interaction with Telegram Bots

Telegraph - a Laravel package for fluently interaction with Telegram Bots

def:studio 412 Dec 30, 2022
Create modern Telegram Bots with PHP.

Telepath Create Telegram Bots with this modern PHP library Explore the docs » Report Bug · Request Feature Table of Contents About The Project Before

Telepath 5 Nov 7, 2022
PHP Telegram Bot based on the official Telegram Bot API with iTelegram Class.

iTelegram PHP Telegram Bot based on the official Telegram Bot API Bots: An introduction for developers Bots are special Telegram accounts designed to

iNeoTeam | آی نئو 5 Nov 9, 2022
PHP Telegram Bot based on the official Telegram Bot API

PHP Telegram Bot based on the official Telegram Bot API

null 4 Dec 8, 2021
Robot increase telegram post 👁‍🗨Telegram Fake Posts Viewer👁‍🗨

Program Features - ?? Very and stylish design. - ?? It has glass buttons. - ?? Has a professional management panel. - ?? Has a user area. - ?? Free di

hack4lx 4 Nov 25, 2022
The best PHP library for VK Users Longpoll Api (Page Bots).

vk-page-bot-lib Description: There are 2 commands and a logger. There is a logger of new messages and a logger that a friend has entered/left in/from

KirillChimbur 6 Jul 25, 2022
A framework agnostic PHP library to build chat bots

BotMan If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course. About BotMa

BotMan 5.8k Jan 3, 2023
API SDK for OpenTrade Commerce API: Taobao, Alibaba, JD, 1688, Aliexpress, Ebay.

OtapiPhpClient Create Client $client = new OtClient($key, $secret, $lang); key (Access Key) secret (Secret for access key) language (2 symbol lang id

OpenTrade Commerce 5 Sep 20, 2022
Telegram API made for php (Simple usage)

Telegram Telegram API made for php (Simple usage) How to use? Download the project & place Telegram folder tp your project directory (For example i se

null 0 Apr 4, 2022