🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Last update: Aug 1, 2022

Telegram Bot API PHP SDK

Join PHP Chat Chat on Telegram Build Status Latest Version Total Downloads

Telegram Bot API - PHP SDK

Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box.

Telegram Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.

To learn more about the Telegram Bot API, please consult the Introduction to Bots and Bot FAQ on official Telegram site.

To get started writing your bots using this SDK, Please refer the documentation.

Documentation

Documentation for the SDK can be found on the website.

Are You Using Telegram Bot SDK?

If you're using this SDK to build your Telegram Bots or have a project that's relevant to this SDK, We'd love to know and share it with the world.

Head over to Awesome Telegram Bots to share, discover, and learn more.

Additional information

Any issues, feedback, suggestions or questions please use issue tracker here.

Contributing

Thank you for considering contributing to the project. Please review the CONTRIBUTING guidelines before submitting any pull requests.

Credits

Thanks

Thanks to these companies for providing access to their products that have been very useful in developing this SDK. Please go check them out!

JetBrains 1Password

Disclaimer

This project and its author is neither associated, nor affiliated with Telegram in anyway. See License section for more details.

License

This project is released under the BSD 3-Clause License.

GitHub

https://github.com/irazasyed/telegram-bot-sdk
Comments
  • 1. Add the ability to send markdown messages

    Telegram has added an option to send markdown formatted messages passing Markdown as parse_mode when sending a message, as seen here. I couldn't seem to find how to use this option.

    Reviewed by filipekiss at 2015-11-11 16:36
  • 2. send automatic message for all user and group with telegram bot

    i want put a part in my bot that when user want from my bot send new data automatic (with link or command for active this) when i put a new record in my table of database my bot send this new record in message for all user that want give this data automatic it is my work that i will do it and now my question is: telegram bot has function or part for manage this work or i should get user_id when active this part and save id in the table and when i create new record i send new message for all user that i save the id in the table and do this work with programming?

    Reviewed by lalehshariat at 2015-08-20 05:15
  • 3. [Todo] Add Commands Handler System

    A system to handle and process commands automatically. Maybe like Laravel's command bus.

    So when a new message arrives through a webhook or when manually getting updates, Make it easy to process such messages if they're commands.

    Reviewed by irazasyed at 2015-07-02 13:45
  • 4. I am using v2.2.0 of the package and cant run any command

    I am using v2.2.0 of this brilliant package and I am wondering how to fire a command by user!! I used this way for creating a command for my bot: at first I added bellow line to telegram.php App\Http\Controllers\StartCommand::class then I created StartCommand.php at App\Http\Controllers folder as the documentation example StartCommand.php then I started webhook and it gaved me {"ok":true,"result":true,"description":"Webhook is already set"}

    afterall I used this route for commandhandler and disabled csrf token too: Route::post('/test/webhook', function () { $update = Telegram::commandsHandler(true); return 'salam in revale'; }); the route can be reached by this address and its ok. but in my bot @yamatabot the /start command doesn not work yet. what step is wrong for me?

    Reviewed by marn65 at 2017-03-18 17:08
  • 5. Determine preferred language of Telegram device that sends message to bot

    Is there a way to find out what language the user has set as preferred language? Both on my Android device and Mac laptop the application allows a user to set a language.

    For example:

    screen shot 2016-12-03 at 21 56 17

    In order to have a bot respond in the 'proper' language, it would be nice to be aware of this preference.

    Could not find anything on the Telegram Bot API page, so it might not even be supported?

    Reviewed by holtkamp at 2016-12-03 21:01
  • 6. Problem in setting up web hook at Telegram

    I've designed a robot for Telegram. After setting up web hook and sending messages to this robot, the robot response me as repetitious, as if the response of robot is on loop. My code is simple, but I don’t know why telegram sends duplicate massages for my web hook.

    Reviewed by HamoonDBA at 2015-09-02 06:52
  • 7. TokenMismatchException with telegram requests

    I have a problem with laravel. the webhook is set but whenever a request is sent to my webhook I just want to log that it's working with "Log::info('webhook is working!');" but I get this error : "Illuminate\Session\TokenMismatchException" I tried to solve it by adding the route exceptions in protected $except in this file: app/Http/Middleware/VerifyCsrfToken.php but I'm still getting the error :( can you help me please?

    <?php namespace App\Http\Controllers;
    
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Log;
    
    class ForumController extends Controller {
    
        /**
         * Display a listing of the resource.
         *
         * @return Response
         */
        public function index()
        {
            Log::info('webhook is working22!');
            /*$updates = Telegram::getWebhookUpdates();
            foreach ($updates as $update) {
                Log::info('webhook is working00!');
                //$response = $telegram->sendMessage('CHAT_ID', 'Hello World');
    
            }*/
        }
    
        /**
         * Show the form for creating a new resource.
         *
         * @return Response
         */
        public function create()
        {
            //
        }
    
        /**
         * Store a newly created resource in storage.
         *
         * @return Response
         */
        public function store()
        {
            //
        }
    
        /**
         * Display the specified resource.
         *
         * @param  int  $id
         * @return Response
         */
        public function show($id)
        {
            //
        }
    
        /**
         * Show the form for editing the specified resource.
         *
         * @param  int  $id
         * @return Response
         */
        public function edit($id)
        {
            //
        }
    
        /**
         * Update the specified resource in storage.
         *
         * @param  int  $id
         * @return Response
         */
        public function update($id)
        {
            //
        }
    
        /**
         * Remove the specified resource from storage.
         *
         * @param  int  $id
         * @return Response
         */
        public function destroy($id)
        {
            //
        }
    
    }
    
    // app/Http/Middleware/VerifyCsrfToken.php
    
    <?php namespace App\Http\Middleware;
    
    use Closure;
    use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
    
    class VerifyCsrfToken extends BaseVerifier {
        protected $except = [
            'forum/*',
        ];
    
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle($request, Closure $next)
        {
            return parent::handle($request, $next);
        }
    
    }
    
    Reviewed by mobasher92 at 2016-09-03 04:53
  • 8. [WIP] Add Conversational System

    I have plans to create a system with which, we can build a Q/A kinda interactive bots easily.

    Since the commands system is not designed to handle this nor it was intended to do that, A separate functionality makes sense.

    The only part that's quite complex is to track the answers/responses and to map it to the right question and then move to next in a queue.

    Any inputs would be good.

    Reviewed by irazasyed at 2015-12-27 19:05
  • 9. One time keyboard may not be working correctly.

    Hi there,

    This package is just fantastic. I have it working really well at the moment. Just noticed one thing that I'm not sure is actually broken but I'll run it past you.

    The official docs state:

    github

    So in my mind, you should receive a message, when you go to reply, the custom keyboard appears and you can select your option but then the keyboard is GONE and doesn't come back.

    When I try this code:

        $keyboard = [
            ['Yes', 'No', 'Maybe'],
            ["I'm Not Sure", 'Can You'],
            ['Repeat the question?']
        ];
    
    $response = Telegram::sendMessage('<myid>', 'Hello!', false, null, Telegram::replyKeyboardMarkup($keyboard, true, true, false));
    

    I get my message perfectly and the custom keyboard pops up:

    2015-07-18 16 00 18

    However when I press my reply, the custom keyboard icon doesn't disappear:

    2015-07-18 16 00 26

    Pressing on this icon brings up the custom keyboard all the time.

    The only way to remove the custom keyboard is to send a new message with

        $response = Telegram::sendMessage('<myid>', 'Just removing the keyboard', false, null, Telegram::replyKeyboardHide());
    

    Now instantly it disappears:

    2015-07-18 16 00 58

    Is this intentional or is there a bug with how the one-time-keyboard should work?

    Reviewed by jonnywilliamson at 2015-07-18 15:12
  • 10. seting webhooks

    hi can someone give me a sample webhook laravel project, like this: https://irazasyed.github.io/telegram-bot-sdk/usage/webhook-updates/ i will appreciate that

    Reviewed by moeinrahimi at 2015-11-30 15:21
  • 11. Async Requests not working

    Hi, I was trying to use asynchronous requests using the following setup:

    -Windows 7 64 Bit -PHP 5.6.3 (32 Bit) -Telegram Bot SDK 0.2.4 -Guzzle 6.0.2

    Plain sending messages using this

    $telegram->setAsyncRequest(true)
        ->sendMessage($message->get('chat')->get('id'), 'Test');
    

    does not work although requests without async do work. I don't know if this is Windows related. There is no error message nor exception, there is just nothing being sent to the Telegram server.

    With best regards,

    Stefan Hueg

    Reviewed by codengine at 2015-07-20 14:12
  • 12. Custom "http_client_handler" (Error)

    • irazasyed/telegram-bot-sdk version: 3.4
    • PHP Version: 7.3
    • Laravel Version: 8.75

    Description:

    Использую пользовательский класс клиента GuzzleHttpClient, к примеру логирую в нём запросы и ответы к API Telegram.
    Получаю ошибку при кешировании конфигурации, т.к. нельзя использовать замыкания или инициализированные экземпляры классов:

    In ConfigCacheCommand.php line 71:
    Your configuration files are not serializable.
    
    In config.php line 719:
    Call to undefined method ...\GuzzleHttpClient::__set_state()
    

    Steps To Reproduce:

    // in "config/telegram.php"
    
    return [
    
        /*
        |--------------------------------------------------------------------------
        | HTTP Client Handler [Optional]
        |--------------------------------------------------------------------------
        |
        | If you'd like to use a custom HTTP Client Handler.
        | Should be an instance of \Telegram\Bot\HttpClients\HttpClientInterface
        |
        | Default: GuzzlePHP
        |
        */
    
        'http_client_handler' => new GuzzleHttpClient()
    ];
    

    Прошу помочь мне разобраться как правильно это делать или обратить внимание, если это ошибка. Просмотрев исходный код SDK наблюдаю, что из конфигурации ожидается именно инициализированный экземпляр, что уже не неверно.

    Reviewed by the-alex-mark at 2022-07-28 20:14
  • 13. callback not working with version 3.4

    I have try many day for fix callback function but still not working. It show nothing when I click on inline keyboard. I have use all this in my custom command handle.

    use Telegram;
    use Telegram\Bot\Commands\Command;
    use Telegram\Bot\Keyboard\Keyboard;
    use Telegram\Bot\Objects\Update;
    

    this is my handle function

    public function handle()
        {
    		$update = $this->telegram->getWebhookUpdate();
            if ($update->isType('callback_query')) {
                $this->telegram->sendMessage([
                    'chat_id' => "123456",
                    'parse_mode' => 'HTML',
                    'text' => 'ddd',
                ]);
            } else {
                $keyboard = json_encode([
    		"inline_keyboard" => [
    			[
    				[
    					"text" => "english",
    					"callback_data" => "/english"
    				],
    				[
    					"text" => "russian",
    					"callback_data" => "/russian"
    				]
    			]
    		]
    	]);
    
                $this->telegram->sendMessage([
                    'chat_id' => $update->getMessage()->chat->id,
                    'text' => 'Text with inline button',
                    'reply_markup' => $keyboard
                ]);
            }
    }
    

    image Thank for help me

    Reviewed by chansovann at 2022-06-09 03:45
  • 14. Installation via composer fails

    Downloading https://packagist.phpcomposer.com/p/irazasyed/telegram-bot-sdk%243a3dd0869927fd8181763a9ab05491653da39b85308aa73b4bd07756fb66310a.json Downloading https://packagist.phpcomposer.com/p/irazasyed/telegram-bot-sdk%243a3dd0869927fd8181763a9ab05491653da39b85308aa73b4bd07756fb66310a.json

    [Composer\Downloader\TransportException] The "https://packagist.phpcomposer.com/p/irazasyed/telegram-bot-sdk%243a3dd0869927fd8181763a9ab05491653da39b85308aa73b4bd07756fb66310a.json" fi le could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed Failed to enable crypto failed to open stream: operation failed

    Reviewed by wangyoukun at 2022-06-08 13:59
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

Jun 20, 2022
PHP Telegram Bot based on the official Telegram Bot API

PHP Telegram Bot based on the official Telegram Bot API

Dec 8, 2021
SDK for latest version of Telegram bots API

SDK for latest version of Telegram bots API (from April 24, 2020) Using Examples Installing composer require "DiyorbekUz/Telelib: dev-master" Init bot

Sep 5, 2021
A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP
A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP

A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP. Including adding reviews to a store's products. It is used to import and export reviews through the API. This is the official package built and developed by A2Reviews, Inc.

Sep 25, 2021
Telegraph - a Laravel package for fluently interaction with Telegram Bots
Telegraph - a Laravel package for fluently interaction with Telegram Bots

Telegraph - a Laravel package for fluently interaction with Telegram Bots

Aug 5, 2022
Build a Telegram Bot

Build a Telegram Bot

Jul 22, 2022
A framework agnostic PHP library to build chat bots
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

Jul 28, 2022
A bot that translates the words you choose during the chat in Telegram to the language you want.
A bot that translates the words you choose during the chat in Telegram to the language you want.

About Needy Telegram Translator If you are constantly using telegram and want to translate words into different languages, this library is for you. Qu

May 27, 2022
The Telegram bot framework that doesn't drive you nuts.
The Telegram bot framework that doesn't drive you nuts.

Nutgram The Telegram bot framework that doesn't drive you nuts This framework takes advantage of the latest PHP 8 features, and tries to make the spee

Jul 25, 2022
The Telegram bot framework that doesn't drive you nuts.
The Telegram bot framework that doesn't drive you nuts.

This framework takes advantage of the latest PHP 8 features, and tries to make the speed, scalability and flexibility of use its strength, it will allow you to quickly make simple bots, but at the same time, it provides more advanced features to handle even the most complicated flows

Aug 5, 2022
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

Oct 19, 2021
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

Jul 23, 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

Jul 25, 2022
laravel package untuk memudahkan penggunaan MCA dengan Telegram Bot USDI di aplikasi Universitas Udayana.

MCA KubeMQ Laravel laravel package untuk memudahkan penggunaan MCA dengan Telegram Bot USDI di aplikasi Universitas Udayana. Motivasi Proyek ini berfu

Nov 17, 2021
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

Aug 3, 2022
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 ?

Jul 24, 2022
Simple telegram auto reminder BOT with PHP

Telebot Script Telegram BOT Auto Reminder Dibuat pake PHP OOP Sebenernya bukan buat dipublish sih, ini cuma buat praktek PHP OOP sama praktek Commit &

May 26, 2022
A simple php telegram bot to check if the bin is valid or not!

Bin-Checker A simple php telegram bot to check if the bin is valid or not! Deploy FORK the Repo by clicking HERE Add your bot token in LINE 12 THEN DE

Nov 23, 2021
Simple php telegram bot.
Simple php telegram bot.

PHPTGBot Description Simple php telegram bot. Just for fun ?? Work In Progress ?? Maybe found error, since im not tested yet! Still on working, so be

Nov 24, 2021