{"id":21625975,"url":"https://github.com/muhammadmp97/telebot","last_synced_at":"2025-10-12T16:31:12.823Z","repository":{"id":44326640,"uuid":"266105551","full_name":"muhammadmp97/TeleBot","owner":"muhammadmp97","description":"A minimal library to develop your new Telegram bot 🐘","archived":false,"fork":false,"pushed_at":"2024-07-27T16:37:16.000Z","size":85,"stargazers_count":56,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-21T21:03:41.418Z","etag":null,"topics":["php-telegram-bot","telegram","telegram-api","telegram-bot","telegram-sdk"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muhammadmp97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-22T12:30:02.000Z","updated_at":"2024-08-16T13:21:56.000Z","dependencies_parsed_at":"2023-09-02T07:16:01.676Z","dependency_job_id":"b626ff3d-7edd-4e0b-b9bc-c743fe889e78","html_url":"https://github.com/muhammadmp97/TeleBot","commit_stats":null,"previous_names":["muhammadmp97/telebot"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadmp97%2FTeleBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadmp97%2FTeleBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadmp97%2FTeleBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadmp97%2FTeleBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muhammadmp97","download_url":"https://codeload.github.com/muhammadmp97/TeleBot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236248199,"owners_count":19118488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php-telegram-bot","telegram","telegram-api","telegram-bot","telegram-sdk"],"created_at":"2024-11-25T01:11:30.869Z","updated_at":"2025-10-12T16:31:07.464Z","avatar_url":"https://github.com/muhammadmp97.png","language":"PHP","readme":"[![Latest Stable Version](http://poser.pugx.org/webpajooh/telebot/v)](https://packagist.org/packages/webpajooh/telebot) [![Total Downloads](http://poser.pugx.org/webpajooh/telebot/downloads)](https://packagist.org/packages/webpajooh/telebot) [![PHP Version Require](http://poser.pugx.org/webpajooh/telebot/require/php)](https://packagist.org/packages/webpajooh/telebot) [![License](http://poser.pugx.org/webpajooh/telebot/license)](https://packagist.org/packages/webpajooh/telebot)\n\n# TeleBot\nA minimal library to develop your new Telegram bot\n\n## Installation\n`composer require webpajooh/telebot`\n\n## How to use\n\n### Start point\nWe start by creating an instance of `TeleBot` class:\n```php\ntry {\n    $tg = new TeleBot('YOUR_BOT_TOKEN');\n} catch (Throwable $th) {...}\n```\n\n### Get the update object\nThere are short ways to access the `update` object and some important fields. I recommend you to read [the official documentation](https://core.telegram.org/bots/api) to understand these objects well.\n```\n$tg-\u003eupdate\n$tg-\u003emessage\n$tg-\u003echat\n$tg-\u003euser\n```\nYou also can use the `hasCallbackQuery()` method, when you want to check if the `update` object has a `callback_query` field.\n\n### Methods\nThanks to [magic methods](https://www.php.net/manual/en/language.oop5.magic.php), we can use API methods without implementing them, and just call them by name and pass an array as parameter:\n```php\n$tg-\u003eeditMessageText([...])\n```\n\n### Router\nYou may define some routes to your bot features; define them by the `listen()` method:\n```php\n$tg-\u003elisten('/start', function () use ($tg) {\n    $tg-\u003esendMessage([\n        'chat_id' =\u003e $tg-\u003euser-\u003eid,\n\t'text' =\u003e 'Hello, world!',\n    ]);\n}, false);\n```\nThe third parameter that is true by default, makes you able to terminate the script after running a command. In the previous example we passed `false` so script continues.\n\nYou can also get parameters and use them as variables:\n```php\n$tg-\u003elisten('set_age_%d', function ($age) use ($tg) {\n    // TODO\n});\n```\n\nTeleBot translates them to regex, so it will be good to take a look at this table to know how to use them properly:\n\n| Type |TeleBot| Regex |\n|--|--|--|\n| Digits | %d | (\\d+) |\n| String (Anything but a whitespace) | %s | (\\S+) |\n| Character | %c | (\\S) |\n| Everything including an empty string| %p | (.*) |\n\n### Logger\nYou may need to log something into a `log.txt` file:\n```php\nLogger::log($tg-\u003euser-\u003eid);\ntl($tg-\u003euser-\u003eid); // Does the same thing\n```\n\n### Keyboard\nTeleBot includes two classes for making keyboards; `InlineKeyboard` and `ReplyKeyboard`. Here you see an example:\n```php\n$keyboard = (new InlineKeyboard())\n    -\u003eaddCallbackButton('📕 Help', 'help_callback')\n    -\u003eaddUrlButton('📱 Share', 'https://t.me/share/url?url=https://t.me/your_awesome_bot\u0026text=Some text')\n    -\u003echunk(1)\n    -\u003erightToLeft()\n    -\u003eget();\n```\nThen you can use it as bellow:\n```php\n$tg-\u003esendMessage([\n    // Other parameters\n    'reply_markup' =\u003e $keyboard,\n]);\n```\n\nConsider that the `chunk()` method supports more complex orders, just pass an array like [1, 3, 2] to build such a keyboard:  \n\u003cpre\u003e\n[        1        ]  \n[ 2 ]  [ 3️ ]  [ 4 ]  \n[   5   ] [   6   ]  \n\u003c/pre\u003e\n\n### Default parameters\nSometimes you do not want to repeat yourself by passing a parameter everywhere, so you can define default parameters for each method. Here are three example that makes it clear how to use it:\n```php\n$tg-\u003esetDefaults('sendMessage', ['parse_mode' =\u003e 'html']); // You will not need passing parse_mode anymore\n$tg-\u003esetDefaults(['sendMessage', 'banChatMember'], ['chat_id' =\u003e $chatId]);\n$tg-\u003esetDefaults('*', ['chat_id' =\u003e $chatId]); // a default parameter for all methods\n```\n\n### Extend it!\nYou may want to add some methods to TeleBot class to improve your code readability and avoid duplication. Look at this simple example as an inspiration:\n```php\nTeleBot::extend('isReply', function () {\n    return property_exists($this-\u003emessage, 'reply_to_message');\n});\n\nif ($tg-\u003eisReply()) { ... }\n```\n\n## Have you seen a problem?\nCreate an issue and explain your problem!\n\n## Made with TeleBot\n- \u003ca  href=\"https://github.com/muhammadmp97/AntiBot\"\u003eAntiBot\u003c/a\u003e\n- \u003ca  href=\"https://github.com/muhammadmp97/MediumBot\"\u003eMediumBot\u003c/a\u003e\n- \u003ca  href=\"https://github.com/MahdiyarGHD/ToigBot\"\u003eToigBot\u003c/a\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammadmp97%2Ftelebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuhammadmp97%2Ftelebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammadmp97%2Ftelebot/lists"}