{"id":13793908,"url":"https://github.com/radyakaze/phptelebot","last_synced_at":"2025-05-11T04:56:46.926Z","repository":{"id":56246859,"uuid":"73479176","full_name":"radyakaze/phptelebot","owner":"radyakaze","description":"Telegram bot framework written in PHP","archived":false,"fork":false,"pushed_at":"2020-11-19T13:22:03.000Z","size":33,"stargazers_count":67,"open_issues_count":6,"forks_count":67,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-11T04:56:20.745Z","etag":null,"topics":["bot-api","inline-bots","php","telegram-bot","telegram-bot-framework"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/radyakaze.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}},"created_at":"2016-11-11T13:18:12.000Z","updated_at":"2025-01-20T15:29:51.000Z","dependencies_parsed_at":"2022-08-15T15:20:51.683Z","dependency_job_id":null,"html_url":"https://github.com/radyakaze/phptelebot","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radyakaze%2Fphptelebot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radyakaze%2Fphptelebot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radyakaze%2Fphptelebot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radyakaze%2Fphptelebot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radyakaze","download_url":"https://codeload.github.com/radyakaze/phptelebot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253518967,"owners_count":21921083,"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":["bot-api","inline-bots","php","telegram-bot","telegram-bot-framework"],"created_at":"2024-08-03T23:00:33.086Z","updated_at":"2025-05-11T04:56:46.884Z","avatar_url":"https://github.com/radyakaze.png","language":"PHP","readme":"# PHPTelebot\nTelegram bot framework written in PHP\n\n## Features\n\n* Simple, easy to use.\n* Support Long Polling and Webhook.\n\n## Requirements\n\n- [cURL](http://php.net/manual/en/book.curl.php)\n- PHP 5.4+\n- Telegram Bot API Token - Talk to [@BotFather](https://telegram.me/@BotFather) and generate one.\n\n## Installation\n\n### Using [Composer](https://getcomposer.org)\n\nTo install PHPTelebot with Composer, just add the following to your `composer.json` file:\n\n```json\n{\n    \"require\": {\n        \"radyakaze/phptelebot\": \"*\"\n    }\n}\n```\n\nor by running the following command:\n\n```shell\ncomposer require radyakaze/phptelebot\n```\n\nComposer installs autoloader at `./vendor/autoloader.php`. to include the library in your script, add:\n\n```php\nrequire_once 'vendor/autoload.php';\n```\n\n### Install from source\n\nDownload the PHP library from Github, then include `PHPTelebot.php` in your script:\n\n```php\nrequire_once '/path/to/phptelebot/src/PHPTelebot.php';\n```\n\n\n## Usage\n\n\n### Creating a simple bot\n```php\n\u003c?php\n\nrequire_once './src/PHPTelebot.php';\n$bot = new PHPTelebot('TOKEN', 'BOT_USERNAME'); // Bot username is optional, its required for handle command that contain username (/command@username) like on a group.\n\n// Simple command\n$bot-\u003ecmd('*', 'Hi, human! I am a bot.');\n\n// Simple echo command\n$bot-\u003ecmd('/echo|/say', function ($text) {\n    if ($text == '') {\n        $text = 'Command usage: /echo [text] or /say [text]';\n    }\n    return Bot::sendMessage($text);\n});\n\n// Simple whoami command\n$bot-\u003ecmd('/whoami|!whoami', function () {\n    // Get message properties\n    $message = Bot::message();\n    $name = $message['from']['first_name'];\n    $userId = $message['from']['id'];\n    $text = 'You are \u003cb\u003e'.$name.'\u003c/b\u003e and your ID is \u003ccode\u003e'.$userId.'\u003c/code\u003e';\n    $options = [\n        'parse_mode' =\u003e 'html',\n        'reply' =\u003e true\n    ];\n\n    return Bot::sendMessage($text, $options);\n});\n\n$bot-\u003erun();\n```\nThen run\n```shell\nphp file.php\n```\n\nYou can also see my other [sample](https://github.com/radyakaze/phptelebot/blob/master/sample.php).\n\n*NOTE:*\n- If function parameters is more than one, PHPTelebot will split text by space.\n- If you don't set chat_id on options bot will send message to current chat.\n- If you add option **reply =\u003e true**, bot will reply current message (Only work if you don't set custom chat_id and reply_to_mesage_id).\n\n## Commands\n\nUse `$bot-\u003ecmd(\u003ccommand\u003e, \u003cfunction\u003e)` to handle command.\n```php\n// simple answer\n$bot-\u003ecmd('*', 'I am a bot');\n\n// catch multiple commands\n$bot-\u003ecmd('/start|/help', function () {\n   // Do something here.\n});\n\n// call a function name\nfunction googleSearch($search) {\n   // Do something here.\n}\n$bot-\u003ecmd('/google', 'googleSearch');\n```\nUse **\u0026#42;** to catch any command.\n\n#### File upload\nThis code will send a photo to users when type command **/upload**.\n```php\n// Simple photo upload\n$bot-\u003ecmd('/upload', function () {\n    $file = '/path/to/photo.png'; // File path, file id, or url.\n    return Bot::sendPhoto($file);\n});\n```\n\n## Events\n\nUse `$bot-\u003eon(\u003cevent\u003e, \u003cfunction\u003e)` to handle all possible PHPTelebot events.\n\nTo handle inline message, just add:\n```php\n$bot-\u003eon('inline', function($text) {\n    $results[] = [\n        'type' =\u003e 'article',\n        'id' =\u003e 'unique_id1',\n        'title' =\u003e $text,\n        'message_text' =\u003e 'Lorem ipsum dolor sit amet',\n    ];\n    $options = [\n        'cache_time' =\u003e 3600,\n    ];\n\n    return Bot::answerInlineQuery($results, $options);\n});\n```\nAlso, you can catch multiple events:\n```php\n$bot-\u003eon('sticker|photo|document', function() {\n  // Do something here.\n });\n```\n\n## Supported events:\n- **\u0026#42;** - any type of message\n- **text** – text message\n- **audio** – audio file\n- **voice** – voice message\n- **document** – document file (any kind)\n- **photo** – photo\n- **sticker** – sticker\n- **video** – video file\n- **contact** – contact data\n- **location** – location data\n- **venue** – venue data\n- **edited** – edited message\n- **pinned_message** – message was pinned\n- **new_chat_member** – new member was added\n- **left_chat_member** – member was removed\n- **new_chat_title** – new chat title\n- **new_chat_photo** – new chat photo\n- **delete_chat_photo** – chat photo was deleted\n- **group_chat_created** – group has been created\n- **channel_chat_created** – channel has been created\n- **supergroup_chat_created** – supergroup has been created\n- **migrate_to_chat_id** – group has been migrated to a supergroup\n- **migrate_from_chat_id** – supergroup has been migrated from a group\n- **inline** - inline message\n- **callback** - callback message\n- **game** - game\n- **channel** - channel\n- **edited_channel** - edited channel post\n\n## Command with custom regex *(advanced)*\n\nCreate a command: */regex string number*\n```php\n$bot-\u003eregex('/^\\/regex (.*) ([0-9])$/i', function($matches) {\n    // Do something here.\n});\n```\n\n## Methods\n\n### PHPTelebot Methods\n##### `cmd(\u003ccommand\u003e, \u003canswer\u003e)`\nHandle a command.\n##### `on(\u003cevent\u003e, \u003canswer\u003e)`\nHandles events.\n##### `regex(\u003cregex\u003e, \u003canswer\u003e)`\nCreate custom regex for command.\n##### `Bot::type()`\nReturn [message event](#supported-events) type.\n##### `Bot::message()`\nGet [message properties](https://core.telegram.org/bots/api#message).\n\n### Telegram Methods\nPHPTelebot use standard [Telegram Bot API](https://core.telegram.org/bots/api#available-methods) method names.\n##### `Bot::getMe()` [?](https://core.telegram.org/bots/api#getme)\nA simple method for testing your bot's auth token.\n##### `Bot::sendMessage(\u003ctext\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendmessage)\nUse this method to send text messages.\n##### `Bot::forwardMessage(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#forwardmessage)\nUse this method to forward messages of any kind.\n##### `Bot::sendPhoto(\u003cfile path | file id | url\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendphoto)\nUse this method to send a photo.\n##### `Bot::sendVideo(\u003cfile path | file id | url\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendvideo)\nUse this method to send a video.\n##### `Bot::sendAudio(\u003cfile path | file id | url\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendaudio)\nUse this method to send a audio.\n##### `Bot::sendVoice(\u003cfile path | file id | url\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendvoice)\nUse this method to send a voice message.\n##### `Bot::sendDocument(\u003cfile path | file id | url\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#senddocument)\nUse this method to send a document.\n##### `Bot::sendSticker(\u003cfile path | file id | url\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendsticker)\nUse this method to send a sticker.\n##### `Bot::sendLocation(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendlocation)\nUse this method to send point on the map.\n##### `Bot::sendVenue(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendvenue)\nUse this method to send information about a venue.\n##### `Bot::sendContact(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendcontact)\nUse this method to send phone contacts.\n##### `Bot::sendChatAction(\u003caction\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendchataction)\nUse this method when you need to tell the user that something is happening on the bot's side.\n##### `Bot::getUserProfilePhotos(\u003cuser id\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#getuserprofilephotos)\nUse this method to get a list of profile pictures for a user.\n##### `Bot::getFile(\u003cfile id\u003e)` [?](https://core.telegram.org/bots/api#getfile)\nUse this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size.\n##### `Bot::answerInlineQuery(\u003carray of results\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#answerinlinequery)\nUse this method to send answers to an inline query.\n##### `Bot::answerCallbackQuery(\u003ctext\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#answercallbackquery)\nUse this method to send answers to callback queries sent from inline keyboards.\n##### `Bot::getChat(\u003cchat_id\u003e)` [?](https://core.telegram.org/bots/api#getchat)\nUse this method to get up to date information about the chat.\n##### `Bot::leaveChat(\u003cchat_id\u003e)` [?](https://core.telegram.org/bots/api#leavechat)\nUse this method for your bot to leave a group, supergroup or channel.\n##### `Bot::getChatAdministrators(\u003cchat_id\u003e)` [?](https://core.telegram.org/bots/api#getchatadministrators)\nUse this method to get a list of administrators in a chat.\n##### `Bot::getChatMembersCount(\u003cchat_id\u003e)` [?](https://core.telegram.org/bots/api#getchatmemberscount)\nUse this method to get the number of members in a chat.\n##### `Bot::getChatMember(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#getchatmember)\nUse this method to get information about a member of a chat.\n##### `Bot::kickChatMember(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#kickchatmember)\nUse this method to kick a user from a group or a supergroup.\n##### `Bot::unbanChatMember(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#unbanchatmember)\nUse this method to unban a previously kicked user in a supergroup.\n##### `Bot::editMessageText(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#editmessagetext)\nUse this method to edit text messages sent by the bot or via the bot (for inline bots).\n##### `Bot::editMessageCaption(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#editmessagecaption)\nUse this method to edit captions of messages sent by the bot or via the bot (for inline bots).\n##### `Bot::editMessageReplyMarkup(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#editmessagereplymarkup)\nUse this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).\n#####  `Bot::sendGame(\u003cgame short name\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#sendgame)\nUse this method to send a game.\n##### `Bot::setGameScore(\u003coptions\u003e)` [?](https://core.telegram.org/bots/api#setgamescore)\nUse this method to set the score of the specified user in a game.\n##### `Bot::getGameHighScores(\u003cuser id\u003e, \u003coptions\u003e)` [?](https://core.telegram.org/bots/api#getgamehighscores)\nUse this method to get data for high score tables.\n\n## Webhook installation\nOpen via browser `https://api.telegram.org/bot\u003cBOT TOKEN\u003e/setWebhook?url=https://yourdomain.com/your_bot.php`\n","funding_links":[],"categories":["Library \u0026 Framework"],"sub_categories":["Tutorial Made"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradyakaze%2Fphptelebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradyakaze%2Fphptelebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradyakaze%2Fphptelebot/lists"}