{"id":19807059,"url":"https://github.com/wpdew/telegrambotphp","last_synced_at":"2025-08-09T02:27:44.551Z","repository":{"id":57043572,"uuid":"112378037","full_name":"wpdew/TelegramBotPHP","owner":"wpdew","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-16T16:52:38.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T06:26:34.190Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/wpdew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-28T19:15:11.000Z","updated_at":"2017-11-28T19:16:50.000Z","dependencies_parsed_at":"2022-08-23T23:30:17.525Z","dependency_job_id":null,"html_url":"https://github.com/wpdew/TelegramBotPHP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdew%2FTelegramBotPHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdew%2FTelegramBotPHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdew%2FTelegramBotPHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdew%2FTelegramBotPHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wpdew","download_url":"https://codeload.github.com/wpdew/TelegramBotPHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241150565,"owners_count":19918353,"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":[],"created_at":"2024-11-12T09:09:23.997Z","updated_at":"2025-02-28T12:31:04.474Z","avatar_url":"https://github.com/wpdew.png","language":"PHP","funding_links":["https://paypal.me/"],"categories":[],"sub_categories":[],"readme":"# TelegramBotPHP\n[![API](https://img.shields.io/badge/Telegram%20Bot%20API-August%2023%2C%202017-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/112378037/shield?branch=master)](https://styleci.io/repos/112378037)\n\n\u003e A very simple PHP [Telegram Bot API](https://core.telegram.org/bots).    \n\u003e Compliant with the August 23, 2017 Telegram Bot API update.\n\nRequirements\n---------\n\n* PHP5\n* Curl 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 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:\n* Some way to execute the script in order to serve messages (for example cronjob)\n\nInstallation\n---------\n\n\n* Copy Telegram.php into your server and include it in your new bot script\n```php\ninclude(\"Telegram.php\");\n$telegram = new Telegram($bot_token);\n```\n\n* To enable error log file, also copy TelegramErrorLogger.php in the same directory of Telegram.php file\n\n#### Using Composer\n\nFrom your project directory, run\n```\ncomposer require eleirbag89/telegrambotphp\n```\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($bot_token);\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($bot_token);\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$req = $telegram-\u003egetUpdates();\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------------\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\nList of Bots using the library\n------------\nLet me know using this [Issue](https://github.com/Eleirbag89/TelegramBotPHP/issues/80) if you have made a bot using this API, I will add it to this section.    \n* [Notifyadbot](https://telegram.me/notifyadbot) - Lang : Persian/Farsi (Down as 16/09/17)\n* [Partners_shakibonline_bot](https://telegram.me/Partners_shakibonline_bot) - Lang : Persian/Farsi (Down as 16/09/17)\n* [Pishvazrobot](https://t.me/pishvazrobot) - Lang : Persian/Farsi - the most comprehensive bot for searching and listening to more than 100,000 RBT sound for two most popular and famous mobile operator in iran - MTN Irancell and Hamrahe Aval\n* [iHarfBot](https://t.me/iHarfBot) - Lang: Persian/Farsi\n* [AsansorBot](https://t.me/AsansorBot) - Lang: Persian/Farsi\n* [IDPbot](https://t.me/IDPbot) - Lang: Persian/Farsi\n* [Evil Insult Generator](https://telegram.me/EvilInsultGeneratorBot) - Lang English/German\n* [ibelitbot](https://telegram.me/ibelitbot) -Lang Persian\n* [skydrivebot](https://telegram.me/skydrivebot) - Lang Persian - Instagram Post Downloader - Youtube Link Generator\n* [Advanced Pools Bot](https://telegram.me/apollbot ) - Lang Italian/English([Contribute](https://poeditor.com/join/project/NMAUjrAZ5f))\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\nContact me\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------------\nYou can buy me a beer or two using [Paypal](https://paypal.me/)    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwpdew%2Ftelegrambotphp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwpdew%2Ftelegrambotphp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwpdew%2Ftelegrambotphp/lists"}