From 7b75139b0bee1fce6fadae1cdf29193bffa29a4a Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Wed, 16 Aug 2023 18:53:07 +0700 Subject: [PATCH 1/3] (#70) Create the menu button in telegram bot and update menu command --- resources/tools/menu.php | 17 ++++++++----- src/Services/TelegramService.php | 42 +++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/resources/tools/menu.php b/resources/tools/menu.php index 0636c70..b09de19 100644 --- a/resources/tools/menu.php +++ b/resources/tools/menu.php @@ -1,10 +1,15 @@ + + BOT MENU ๐Ÿค– -/server - To get Server Information. -/id - To get your Chat ID. -/token - To get this bot token. -/usage - How to use me. -/settings - Settings GitHub notify. -/menu - To get this menu. + + - + + Select a button: diff --git a/src/Services/TelegramService.php b/src/Services/TelegramService.php index 43186ad..fbfff4f 100644 --- a/src/Services/TelegramService.php +++ b/src/Services/TelegramService.php @@ -6,6 +6,31 @@ class TelegramService extends AppService { + public const MENU_COMMANDS = [ + [ + 'command' => '/start', + 'description' => 'Welcome to the bot' + ], [ + 'command' => '/menu', + 'description' => 'Show menu of the bot' + ], [ + 'command' => '/token', + 'description' => 'Show token of the bot' + ], [ + 'command' => '/id', + 'description' => 'Show the ID of the current chat' + ], [ + 'command' => '/usage', + 'description' => 'Show step by step usage' + ], [ + 'command' => '/server', + 'description' => 'To get Server Information' + ], [ + 'command' => '/settings', + 'description' => 'Show settings GitHub notify' + ], + ]; + public array $messageData; public SettingService $settingService; @@ -24,7 +49,7 @@ public function __construct() * @param string $text * @return void */ - public function telegramToolHandler(string $text): void + public function telegramToolHandler(string $text = '/start'): void { switch ($text) { case '/start': @@ -43,6 +68,9 @@ public function telegramToolHandler(string $text): void case '/settings': $this->settingService->settingHandle(); break; + case '/set_menu': + $this->setMyCommands(); + break; default: $this->sendMessage('๐Ÿคจ Invalid Request!'); } @@ -80,4 +108,16 @@ public function checkCallback(): bool } return false; } + + /** + * Set the menu button for a telegram + * + * @return void + */ + public function setMyCommands(): void + { + $this->telegram->setMyCommands([ + 'commands' => json_encode(self::MENU_COMMANDS) + ]); + } } From 66442897df5a6a34f12ce58511923a80a4fcdebb Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Wed, 16 Aug 2023 19:20:17 +0700 Subject: [PATCH 2/3] (#70) add a message for set the menu button to telegram --- resources/tools/set_menu.php | 3 +++ src/Services/TelegramService.php | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 resources/tools/set_menu.php diff --git a/resources/tools/set_menu.php b/resources/tools/set_menu.php new file mode 100644 index 0000000..6b22b5d --- /dev/null +++ b/resources/tools/set_menu.php @@ -0,0 +1,3 @@ +โœ… Menu button set successfully! + +Please restart the bot to apply the changes. diff --git a/src/Services/TelegramService.php b/src/Services/TelegramService.php index fbfff4f..33738ee 100644 --- a/src/Services/TelegramService.php +++ b/src/Services/TelegramService.php @@ -51,6 +51,7 @@ public function __construct() */ public function telegramToolHandler(string $text = '/start'): void { + set_time_limit(60); switch ($text) { case '/start': $reply = view('tools.start', ['first_name' => $this->telegram->FirstName()]); @@ -119,5 +120,6 @@ public function setMyCommands(): void $this->telegram->setMyCommands([ 'commands' => json_encode(self::MENU_COMMANDS) ]); + $this->sendMessage(view('tools.set_menu')); } } From 2f3852a527ab2b096bd263c6e490a8834235bb6c Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Wed, 16 Aug 2023 21:29:45 +0700 Subject: [PATCH 3/3] (#70) docs: update documentation for set menu button --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e705f5..187124b 100644 --- a/README.md +++ b/README.md @@ -316,10 +316,24 @@ If you want to check the menu, you can send the following message to your bot. /menu ``` -๐ŸŽŠ **At this point, the configuration process for your telegram bot is completed. You can use all the features of this bot.** ๐ŸŽ‰๐ŸŽ‰ +๐ŸŽŠ At this point, the configuration process for your telegram bot is completed. +You can use all the features of this bot. +๐ŸŽ‰๐ŸŽ‰

- Menu features of this bot + Menu features of this bot +

+ +**To increase ease of use. Let's create a menu with a list of commands listed for you.** + +Please send the following message to your bot to create a menu button. + +```text +/set_menu +``` + +

+ Set menu Set menu

Now you will need to add the Webhook for your GitHub repository to receive notifications.