{"id":18860042,"url":"https://github.com/duhow/telegram-php","last_synced_at":"2025-04-14T12:22:42.793Z","repository":{"id":47278999,"uuid":"78770622","full_name":"duhow/Telegram-PHP","owner":"duhow","description":"PHP Library to parse Telegram messages and perform bot API calls. Check Telegram-PHP-App for a full implementation!","archived":false,"fork":false,"pushed_at":"2021-09-05T09:52:55.000Z","size":133,"stargazers_count":43,"open_issues_count":0,"forks_count":13,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-28T01:44:10.064Z","etag":null,"topics":["api","bot","php","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"https://github.com/duhow/Telegram-PHP-App","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/duhow.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":"2017-01-12T17:42:41.000Z","updated_at":"2025-01-04T02:39:24.000Z","dependencies_parsed_at":"2022-07-20T20:34:38.085Z","dependency_job_id":null,"html_url":"https://github.com/duhow/Telegram-PHP","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/duhow%2FTelegram-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhow%2FTelegram-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhow%2FTelegram-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhow%2FTelegram-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duhow","download_url":"https://codeload.github.com/duhow/Telegram-PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248878464,"owners_count":21176334,"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":["api","bot","php","telegram","telegram-bot"],"created_at":"2024-11-08T04:20:43.029Z","updated_at":"2025-04-14T12:22:42.729Z","avatar_url":"https://github.com/duhow.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram-PHP\n\nAnother library to use Telegram bots with PHP.\n\n- Include the **src/Autoloader.php** file.\n- Create a *Telegram\\Bot* object.\n- Create a *Telegram\\Receiver* object using the *$bot*.\n\n```php\n$bot = new Telegram\\Bot(\"11111111:AAAAAAAAAAzzzzzzzzzzzzzzzzzzz\", \"MyUserBot\", \"The Name of Bot\");\n$tg  = new Telegram\\Receiver($bot);\n```\n\nYou can create as many *Bots* and *Receivers* or *Senders* as you want.\nUsing *Receiver* includes a *Sender*.\n\n# Usage\n\nOnce the page is loaded (manually or via webhook), you can send or reply the requests.\n\nTo send a message to a user or group chat:\n```php\n$tg-\u003esend\n  -\u003echat(\"123456\")\n  -\u003etext(\"Hello world!\")\n-\u003esend();\n```\n\nTo reply a user command:\n```php\nif($tg-\u003etext_command(\"start\")){\n  $tg-\u003esend\n    -\u003etext(\"Hi!\")\n  -\u003esend();\n}\n```\n\nTo reply a user message:\n```php\nif($tg-\u003etext_has(\"are you alive\")){\n  $tg-\u003esend\n    -\u003etext(\"Yes!\")\n  -\u003esend();\n}\n```\n\n**NEW:** To parse a string:\n```php\nif($tg-\u003etext_regex(\"I'm {N:age}\") and $tg-\u003ewords() \u003c= 4){\n  $num = $tg-\u003einput-\u003eage;\n  $str = \"So old...\";\n  if($num \u003c 18){ $str = \"You're young!\"; }\n  $tg-\u003esend\n    -\u003etext($str)\n  -\u003esend();\n}elseif($tg-\u003etext_regex(\"My name's {name}\")){\n  $tg-\u003esend\n    -\u003etext(\"Nice to meet you, \" .$tg-\u003einput-\u003ename .\"!\")\n  -\u003esend();\n}\n```\n\nSend an Inline Keyboard and parse it:\n```php\nif($tg-\u003ecallback == \"but 1\"){\n  $tg-\u003eanswer_if_callback(\"\"); // Stop loading button.\n  $tg-\u003esend\n    -\u003emessage(TRUE)\n    -\u003echat(TRUE)\n    -\u003etext(\"You pressed the first button!\")\n  -\u003eedit(\"text\");\n}elseif($tg-\u003ecallback == \"but 2\"){\n  $tg-\u003eanswer_if_callback(\"You pressed the second button!\", TRUE);\n  // Display an alert and stop loading button.\n}\n\nif($tg-\u003etext_has(\"matrix\") and $tg-\u003ewords() \u003c= 5){\n  $tg-\u003esend\n    -\u003etext(\"Red or blue. You choose.\")\n    -\u003einline_keyboard()\n      -\u003erow()\n        -\u003ebutton(\"Red\",  \"but 1\")\n        -\u003ebutton(\"Blue\", \"but 2\")\n      -\u003eend_row()\n    -\u003eshow()\n  -\u003esend();\n}\n```\n\n# Examples\n- [Profesor Oak](https://github.com/duhow/ProfesorOak), an assistant for Pokemon GO.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduhow%2Ftelegram-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduhow%2Ftelegram-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduhow%2Ftelegram-php/lists"}