{"id":25227220,"url":"https://github.com/php-telegram-bot/fluent-keyboard","last_synced_at":"2025-11-07T11:04:09.489Z","repository":{"id":57040018,"uuid":"472517689","full_name":"php-telegram-bot/fluent-keyboard","owner":"php-telegram-bot","description":"Fluent Keyboard builder for php-telegram-bot.","archived":false,"fork":false,"pushed_at":"2022-04-19T22:16:18.000Z","size":187,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-18T12:48:13.052Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-telegram-bot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-21T21:25:31.000Z","updated_at":"2024-09-29T12:36:47.000Z","dependencies_parsed_at":"2022-08-23T23:30:32.899Z","dependency_job_id":null,"html_url":"https://github.com/php-telegram-bot/fluent-keyboard","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/php-telegram-bot%2Ffluent-keyboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-telegram-bot%2Ffluent-keyboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-telegram-bot%2Ffluent-keyboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-telegram-bot%2Ffluent-keyboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-telegram-bot","download_url":"https://codeload.github.com/php-telegram-bot/fluent-keyboard/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238256730,"owners_count":19442092,"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":"2025-02-11T08:13:13.659Z","updated_at":"2025-10-26T04:30:21.980Z","avatar_url":"https://github.com/php-telegram-bot.png","language":"PHP","readme":"\u003cdiv id=\"top\"\u003e\u003c/div\u003e\n\n[![Version][version]](https://packagist.org/packages/php-telegram-bot/fluent-keyboard)\n![PHP Version][php-version]\n[![Bot API][bot-api-shield]](https://core.telegram.org/bots/api#january-31-2022)\n[![Tests][tests-shield]](https://github.com/php-telegram-bot/fluent-keyboard/actions/workflows/tests.yaml)\n\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\n        \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\n        \u003col\u003e\n            \u003cli\u003e\u003ca href=\"#defining-a-keyboard\"\u003eDefining a Keyboard\u003c/a\u003e\u003c/li\u003e\n            \u003cli\u003e\u003ca href=\"#defining-buttons\"\u003eDefining Buttons\u003c/a\u003e\u003c/li\u003e\n            \u003cli\u003e\n                \u003ca href=\"#bind-buttons-to-a-keyboard\"\u003eBind Buttons to a Keyboard\u003c/a\u003e\n                \u003col\u003e\n                    \u003cli\u003e\u003ca href=\"#by-row\"\u003eBy Row\u003c/a\u003e\u003c/li\u003e\n                    \u003cli\u003e\u003ca href=\"#by-button\"\u003eBy Button\u003c/a\u003e\u003c/li\u003e\n                    \u003cli\u003e\u003ca href=\"#as-stack\"\u003eAs Stack\u003c/a\u003e\u003c/li\u003e\n                \u003c/ol\u003e\n            \u003c/li\u003e\n            \u003cli\u003e\u003ca href=\"#forcereply-and-replykeyboardremove\"\u003eForceReply and ReplyKeyboardRemove\u003c/a\u003e\u003c/li\u003e\n            \u003cli\u003e\u003ca href=\"#keyboardbuttonpolltype\"\u003eKeyboardButtonPollType\u003c/a\u003e\u003c/li\u003e\n        \u003c/ol\u003e\n    \u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n## Installation\n\nInstall the package using composer:\n\n```shell\ncomposer require php-telegram-bot/fluent-keyboard \n```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Usage\n\nIf you need to create a keyboard you can use the classes provided by this package as a drop-in replacement.\n\nThis is best explained with an example:\n\n```php\nRequest::sendMessage([\n    'chat_id'      =\u003e 12345,\n    'text'         =\u003e 'Keyboard Example',\n    'reply_markup' =\u003e ReplyKeyboardMarkup::make()\n        -\u003eoneTimeKeyboard()\n        -\u003ebutton(KeyboardButton::make('Cancel'))\n        -\u003ebutton(KeyboardButton::make('OK')),\n]);\n```\n\nA ReplyKeyboardMarkup is created by calling the static `make()` method on `ReplyKeyboardMarkup`. After that every field,\nlike `one_time_keyboard`, can be chained by calling it in camelCase. Buttons can be added by calling\nthe `button()` method. We have a detailed look on that later.\n\nThe classes and fields are named after the corresponding types and fields of\nthe [Telegram Bot API](https://core.telegram.org/bots/api).\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Defining a Keyboard\n\nYou can create a keyboard by calling the static `make()` method on its class.\n\nAfter that you can chain methods to set additional fields that are available in the Bot API. This is done by calling the\nfield name in camelCase. So instead of `input_field_placeholder`, you need to call `inputFieldPlaceholder()`.\n\n```php\nReplyKeyboardMarkup::make()\n    -\u003einputFieldPlaceholder('Placeholder');\n```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Defining Buttons\n\nThe Buttons are created in the same way:\n\n```php\nKeyboardButton::make()\n    -\u003etext('Send my Contact')\n    -\u003erequestContact();\n```\n\nAs a shortcut, you can pass the mandatory `text` field as an argument to the static method `make()` like this:\n\n```php\nKeyboardButton::make('Send my Location')\n    -\u003erequestLocation();\n```\n\nThis is done the same way for `InlineKeyboardButton`:\n\n```php\nInlineKeyboardButton::make('Login')\n    -\u003eloginUrl(['url' =\u003e 'https://example.com']);\n```\n\nTo find out which fields are available have a look at the [Bot API documentation](https://core.telegram.org/bots/api).\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Bind Buttons to a Keyboard\n\nThe keyboard does not work without any buttons, so you need to pass the buttons to the keyboard. There are a few ways to\ndo this.\n\n#### By Row\n\n```php\nReplyKeyboardMarkup::make()\n    -\u003erow([\n        KeyboardButton::make('Cancel'),\n        KeyboardButton::make('OK')\n    ]);\n```\n\nIf you need more than one row, call `row()` multiple times:\n\n```php\nInlineKeyboardMarkup::make()\n    -\u003erow([\n        InlineKeyboardButton::make('1')-\u003ecallbackData('page-1'),\n        InlineKeyboardButton::make('2')-\u003ecallbackData('page-2'),\n        InlineKeyboardButton::make('3')-\u003ecallbackData('page-3')\n    ])\n    -\u003erow([\n        InlineKeyboardButton::make('prev')-\u003ecallbackData('page-prev'),\n        InlineKeyboardButton::make('next')-\u003ecallbackData('page-next')\n    ]);\n```\n\n![InlineKeyboard with multiple rows](./docs/images/inlinekeyboard-multiple-rows.png)\n\n#### By Button\n\n```php\nReplyKeyboardMarkup::make()\n    -\u003ebutton(KeyboardButton::make('First Button'))\n    -\u003ebutton(KeyboardButton::make('Second Button'));\n```\n\nIf you need more than one row, just call the row method without arguments, and continue calling `button()`:\n\n```php\nInlineKeyboardMarkup::make()\n    -\u003ebutton(InlineKeyboardButton::make('A')-\u003ecallbackData('answer-a'))\n    -\u003ebutton(InlineKeyboardButton::make('B')-\u003ecallbackData('answer-b'))\n    -\u003erow()\n    -\u003ebutton(InlineKeyboardButton::make('C')-\u003ecallbackData('answer-c'))\n    -\u003ebutton(InlineKeyboardButton::make('D')-\u003ecallbackData('answer-d'));\n```\n![InlineKeyboard with multiline buttons](./docs/images/inlinekeyboards-multiline-buttons.png)\n\nIt's up to you if you define your buttons inline like in these examples or if you'd like to generate a whole row beforehand and\npass the variable to the `row()` method.\n\n#### As Stack\n\nIf you want to add a bunch of buttons that have each a row for themselves you can use the `stack()` method.\n\n```php\nInlineKeyboardMarkup::make()\n    -\u003estack([\n        InlineKeyboardButton::make('Login')-\u003eloginUrl('https://example.com/login'),\n        InlineKeyboardButton::make('Visit Homepage')-\u003eurl('https://example.com')\n    ]);\n```\n\n![InlineKeyboard with stack](./docs/images/inlinekeyboard-stack.png)\n\n**You can mix and match the `row()`, `stack()` and `button()` methods as it fits your needs.**\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### ForceReply and ReplyKeyboardRemove\n\nForceReply and ReplyKeyboardRemove can be used the same way as a normal keyboard, but they do not receive any buttons:\n\n```php\n$this-\u003ereplyToUser('Thank you', [\n    'reply_markup' =\u003e ReplyKeyboardRemove::make()-\u003eselective(),\n]);\n```\n\n```php\n$data['reply_markup'] = ForceReply::make()-\u003einputFieldPlaceholder('Please type something...');\n```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### KeyboardButtonPollType\n\nThe `request_poll` field is a little special. You can specify which poll type the user can create by passing\na `KeyboardButtonPollType` object.\n\n```php\nKeyboardButton::make()-\u003erequestPoll(KeyboardButtonPollType::regular())\n```\n\nThe `KeyboardButtonPollType` class has static methods for each possible type. But if there are new types in the future\nyou don't have to wait until we release an update. You can either pass the array structure directly to\nthe `requestPoll()` method or you pass the array structure to the constructor of `KeyboardButtonPollType`.\n\n```php\n$pollButton = new KeyboardButtonPollType([\n    'type' =\u003e 'quiz'\n]);\n```\n\n[tests-shield]: https://img.shields.io/github/workflow/status/php-telegram-bot/fluent-keyboard/Tests?label=Tests\u0026style=for-the-badge\n\n[bot-api-shield]: https://img.shields.io/badge/Bot%20API-5.7%20(Jan%202022)-%232a9ed6?style=for-the-badge\n\n[php-version]: https://img.shields.io/packagist/php-v/php-telegram-bot/fluent-keyboard?style=for-the-badge\n\n[version]: https://img.shields.io/packagist/v/php-telegram-bot/fluent-keyboard?color=orange\u0026label=Version\u0026style=for-the-badge\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-telegram-bot%2Ffluent-keyboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-telegram-bot%2Ffluent-keyboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-telegram-bot%2Ffluent-keyboard/lists"}