{"id":13609737,"url":"https://github.com/Eleirbag89/TelegramBotPHP","last_synced_at":"2025-04-12T20:32:19.596Z","repository":{"id":34547460,"uuid":"38492095","full_name":"Eleirbag89/TelegramBotPHP","owner":"Eleirbag89","description":"A very simple PHP Telegram Bot API for sending messages.","archived":false,"fork":false,"pushed_at":"2024-03-22T04:15:34.000Z","size":1596,"stargazers_count":814,"open_issues_count":0,"forks_count":343,"subscribers_count":63,"default_branch":"master","last_synced_at":"2024-11-07T15:46:30.451Z","etag":null,"topics":["bot","composer-package","php","telegram"],"latest_commit_sha":null,"homepage":"http://eleirbag89.github.io/TelegramBotPHP","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/Eleirbag89.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"liberapay":"eleirbag89","custom":["https://paypal.me/eleirbag89","https://flattr.com/@Eleirbag89"]}},"created_at":"2015-07-03T12:40:20.000Z","updated_at":"2024-10-29T11:51:28.000Z","dependencies_parsed_at":"2024-06-11T01:55:58.730Z","dependency_job_id":"d06013d3-06b9-415a-8a4d-2af0d365624f","html_url":"https://github.com/Eleirbag89/TelegramBotPHP","commit_stats":{"total_commits":286,"total_committers":24,"mean_commits":"11.916666666666666","dds":0.2727272727272727,"last_synced_commit":"ffef97116af712e2557f6e0372ba4e9d28dbecdf"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eleirbag89%2FTelegramBotPHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eleirbag89%2FTelegramBotPHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eleirbag89%2FTelegramBotPHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eleirbag89%2FTelegramBotPHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Eleirbag89","download_url":"https://codeload.github.com/Eleirbag89/TelegramBotPHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248629963,"owners_count":21136351,"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","composer-package","php","telegram"],"created_at":"2024-08-01T19:01:37.582Z","updated_at":"2025-04-12T20:32:18.331Z","avatar_url":"https://github.com/Eleirbag89.png","language":"PHP","funding_links":["https://liberapay.com/eleirbag89","https://paypal.me/eleirbag89","https://flattr.com/@Eleirbag89","https://liberapay.com/eleirbag89/donate"],"categories":["PHP"],"sub_categories":[],"readme":"# TelegramBotPHP\n[![API](https://img.shields.io/badge/Telegram%20Bot%20API-April%2016%2C%202022-36ade1.svg)](https://core.telegram.org/bots/api)\n![PHP](https://img.shields.io/badge/php-%3E%3D5.3-8892bf.svg)\n![CURL](https://img.shields.io/badge/cURL-required-green.svg)\n\n[![Total Downloads](https://poser.pugx.org/eleirbag89/telegrambotphp/downloads)](https://packagist.org/packages/eleirbag89/telegrambotphp)\n[![License](https://poser.pugx.org/eleirbag89/telegrambotphp/license)](https://packagist.org/packages/eleirbag89/telegrambotphp)\n[![StyleCI](https://styleci.io/repos/38492095/shield?branch=master)](https://styleci.io/repos/38492095)\n\nA very simple PHP [Telegram Bot API](https://core.telegram.org/bots).    \nCompliant with the April 16, 2022 Telegram Bot API update.\n\nRequirements\n---------\n\n* PHP \u003e= 5.3\n* Curl extension for PHP5 must be enabled.\n* Telegram API key, you can get one simply with [@BotFather](https://core.telegram.org/bots#botfather) with simple commands right after creating your bot.\n\nFor the WebHook:\n* An VALID SSL certificate (Telegram API requires this). You can use [Cloudflare's Free Flexible SSL](https://www.cloudflare.com/ssl) which crypts the web traffic from end user to their proxies if you're using CloudFlare DNS.    \nSince the August 29 update you can use a self-signed ssl certificate.\n\nFor the getUpdates(Long Polling):\n* Some way to execute the script in order to serve messages (for example cronjob)\n\nDownload\n---------\n\n#### Using Composer\n\nFrom your project directory, run:\n```\ncomposer require eleirbag89/telegrambotphp\n```\nor\n```\nphp composer.phar require eleirbag89/telegrambotphp\n```\nNote: If you don't have Composer you can download it [HERE](https://getcomposer.org/download/).\n\n#### Using release archives\n\nhttps://github.com/Eleirbag89/TelegramBotPHP/releases\n\n#### Using Git\n\nFrom a project directory, run:\n```\ngit clone https://github.com/Eleirbag89/TelegramBotPHP.git\n```\n\nInstallation\n---------\n\n#### Via Composer's autoloader\n\nAfter downloading by using Composer, you can include Composer's autoloader:\n```php\ninclude (__DIR__ . '/vendor/autoload.php');\n\n$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');\n```\n\n#### Via TelegramBotPHP class\n\nCopy Telegram.php into your server and include it in your new bot script:\n```php\ninclude 'Telegram.php';\n\n$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');\n```\n\nNote: To enable error log file, also copy TelegramErrorLogger.php in the same directory of Telegram.php file.\n\nConfiguration (WebHook)\n---------\n\nNavigate to \nhttps://api.telegram.org/bot(BOT_TOKEN)/setWebhook?url=https://yoursite.com/your_update.php\nOr use the Telegram class setWebhook method.\n\nExamples\n---------\n\n```php\n$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');\n\n$chat_id = $telegram-\u003eChatID();\n$content = array('chat_id' =\u003e $chat_id, 'text' =\u003e 'Test');\n$telegram-\u003esendMessage($content);\n```\n\nIf you want to get some specific parameter from the Telegram response:\n```php\n$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');\n\n$result = $telegram-\u003egetData();\n$text = $result['message'] ['text'];\n$chat_id = $result['message'] ['chat']['id'];\n$content = array('chat_id' =\u003e $chat_id, 'text' =\u003e 'Test');\n$telegram-\u003esendMessage($content);\n```\n\nTo upload a Photo or some other files, you need to load it with CurlFile:\n```php\n// Load a local file to upload. If is already on Telegram's Servers just pass the resource id\n$img = curl_file_create('test.png','image/png'); \n$content = array('chat_id' =\u003e $chat_id, 'photo' =\u003e $img );\n$telegram-\u003esendPhoto($content);\n```\n\nTo download a file on the Telegram's servers\n```php\n$file = $telegram-\u003egetFile($file_id);\n$telegram-\u003edownloadFile($file['result']['file_path'], './my_downloaded_file_on_local_server.png');\n```\n\nSee update.php or update cowsay.php for the complete example.\nIf you wanna see the CowSay Bot in action [add it](https://telegram.me/cowmooobot).\n\nIf you want to use getUpdates instead of the WebHook you need to call the the `serveUpdate` function inside a for cycle.\n```php\n$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');\n\n$req = $telegram-\u003egetUpdates();\n\nfor ($i = 0; $i \u003c $telegram-\u003e UpdateCount(); $i++) {\n\t// You NEED to call serveUpdate before accessing the values of message in Telegram Class\n\t$telegram-\u003eserveUpdate($i);\n\t$text = $telegram-\u003eText();\n\t$chat_id = $telegram-\u003eChatID();\n\n\tif ($text == '/start') {\n\t\t$reply = 'Working';\n\t\t$content = array('chat_id' =\u003e $chat_id, 'text' =\u003e $reply);\n\t\t$telegram-\u003esendMessage($content);\n\t}\n\t// DO OTHER STUFF\n}\n```\nSee getUpdates.php for the complete example.\n\nFunctions\n------------\n\nFor a complete and up-to-date functions documentation check http://eleirbag89.github.io/TelegramBotPHP/\n\nBuild keyboards\n------------\n\nTelegram's bots can have two different kind of keyboards: Inline and Reply.    \nThe InlineKeyboard is linked to a particular message, while the ReplyKeyboard is linked to the whole chat.    \nThey are both an array of array of buttons, which rapresent the rows and columns.    \nFor instance you can arrange a ReplyKeyboard like this:\n![ReplyKeabordExample](https://picload.org/image/rilclcwr/replykeyboard.png)\nusing this code:\n```php\n$option = array( \n    //First row\n    array($telegram-\u003ebuildKeyboardButton(\"Button 1\"), $telegram-\u003ebuildKeyboardButton(\"Button 2\")), \n    //Second row \n    array($telegram-\u003ebuildKeyboardButton(\"Button 3\"), $telegram-\u003ebuildKeyboardButton(\"Button 4\"), $telegram-\u003ebuildKeyboardButton(\"Button 5\")), \n    //Third row\n    array($telegram-\u003ebuildKeyboardButton(\"Button 6\")) );\n$keyb = $telegram-\u003ebuildKeyBoard($option, $onetime=false);\n$content = array('chat_id' =\u003e $chat_id, 'reply_markup' =\u003e $keyb, 'text' =\u003e \"This is a Keyboard Test\");\n$telegram-\u003esendMessage($content);\n```\nWhen a user click on the button, the button text is send back to the bot.    \nFor an InlineKeyboard it's pretty much the same (but you need to provide a valid URL or a Callback data)\n![InlineKeabordExample](https://picload.org/image/rilclcwa/replykeyboardinline.png)\n```php\n$option = array( \n    //First row\n    array($telegram-\u003ebuildInlineKeyBoardButton(\"Button 1\", $url=\"http://link1.com\"), $telegram-\u003ebuildInlineKeyBoardButton(\"Button 2\", $url=\"http://link2.com\")), \n    //Second row \n    array($telegram-\u003ebuildInlineKeyBoardButton(\"Button 3\", $url=\"http://link3.com\"), $telegram-\u003ebuildInlineKeyBoardButton(\"Button 4\", $url=\"http://link4.com\"), $telegram-\u003ebuildInlineKeyBoardButton(\"Button 5\", $url=\"http://link5.com\")), \n    //Third row\n    array($telegram-\u003ebuildInlineKeyBoardButton(\"Button 6\", $url=\"http://link6.com\")) );\n$keyb = $telegram-\u003ebuildInlineKeyBoard($option);\n$content = array('chat_id' =\u003e $chat_id, 'reply_markup' =\u003e $keyb, 'text' =\u003e \"This is a Keyboard Test\");\n$telegram-\u003esendMessage($content);\n```\nThis is the list of all the helper functions to make keyboards easily:     \n\n```php\nbuildKeyBoard(array $options, $onetime=true, $resize=true, $selective=true)\n```\nSend a custom keyboard. $option is an array of array KeyboardButton.  \nCheck [ReplyKeyBoardMarkUp](https://core.telegram.org/bots/api#replykeyboardmarkup) for more info.    \n\n```php\nbuildInlineKeyBoard(array $inline_keyboard)\n```\nSend a custom keyboard. $inline_keyboard is an array of array InlineKeyboardButton.  \nCheck [InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) for more info.    \n\n```php\nbuildInlineKeyBoardButton($text, $url, $callback_data, $switch_inline_query)\n```\nCreate an InlineKeyboardButton.    \nCheck [InlineKeyBoardButton](https://core.telegram.org/bots/api#inlinekeyboardbutton) for more info.    \n\n```php\nbuildKeyBoardButton($text, $url, $request_contact, $request_location)\n```\nCreate a KeyboardButton.    \nCheck [KeyBoardButton](https://core.telegram.org/bots/api#keyboardbutton) for more info.    \n\n\n```php\nbuildKeyBoardHide($selective=true)\n```\nHide a custom keyboard.  \nCheck [ReplyKeyBoarHide](https://core.telegram.org/bots/api#replykeyboardhide) for more info.    \n\n```php\nbuildForceReply($selective=true)\n```\nShow a Reply interface to the user.  \nCheck [ForceReply](https://core.telegram.org/bots/api#forcereply) for more info.\n\nEmoticons\n------------\nFor a list of emoticons to use in your bot messages, please refer to the column Bytes of this table:\nhttp://apps.timwhitlock.info/emoji/tables/unicode\n\nLicense\n------------\n\nThis open-source software is distributed under the MIT License. See LICENSE.md\n\nContributing\n------------\n\nAll kinds of contributions are welcome - code, tests, documentation, bug reports, new features, etc...\n\n* Send feedbacks.\n* Submit bug reports.\n* Write/Edit the documents.\n* Fix bugs or add new features.\n\nContact me\n------------\n\nYou can contact me [via Telegram](https://telegram.me/ggrillo) but if you have an issue please [open](https://github.com/Eleirbag89/TelegramBotPHP/issues) one.\n\nSupport me\n------------\n\nYou can support me using via LiberaPay [![Donate using Liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/eleirbag89/donate)\n\nor buy me a beer or two using [Paypal](https://paypal.me/eleirbag89). \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEleirbag89%2FTelegramBotPHP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEleirbag89%2FTelegramBotPHP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEleirbag89%2FTelegramBotPHP/lists"}