Skip to content

Commit

Permalink
Merge pull request #86 from tanhongit/feature/menu
Browse files Browse the repository at this point in the history
Feature/menu
  • Loading branch information
tanhongit authored Aug 16, 2023
2 parents 3724ffa + 2f3852a commit 9f48afb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
🎉🎉

<p align="center">
<img alt="Menu features of this bot" src="https://github.com/lbiltech/telegram-bot-github-notify/assets/35853002/5aa42173-9443-4978-a59a-82f2ed016790" />
<img alt="Menu features of this bot" src="https://github.com/lbiltech/telegram-bot-github-notify/assets/35853002/1a725130-c7c4-4594-9669-abc6d2dc1fba" />
</p>

**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
```

<p align="center">
<img alt="Set menu" src="https://github.com/lbiltech/telegram-bot-github-notify/assets/35853002/70f79e8f-b075-455d-b928-f721ca5b11cc" /> <img alt="Set menu" src="https://github.com/lbiltech/telegram-bot-github-notify/assets/35853002/53af5d51-7aa8-4dd8-99f6-3b55a9971cbe" />
</p>

Now you will need to add the Webhook for your GitHub repository to receive notifications.
Expand Down
17 changes: 11 additions & 6 deletions resources/tools/menu.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php

use TelegramGithubNotify\App\Services\TelegramService;

$menuCommands = TelegramService::MENU_COMMANDS ?? [];
?>

<b>BOT MENU</b> 🤖

/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.
<?php foreach ($menuCommands as $menuCommand) : ?>
<b><?= $menuCommand['command'] ?></b> - <?= $menuCommand['description'] ?>

<?php endforeach; ?>

Select a button:
3 changes: 3 additions & 0 deletions resources/tools/set_menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
✅ Menu button set successfully!

Please restart the bot to apply the changes.
44 changes: 43 additions & 1 deletion src/Services/TelegramService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,8 +49,9 @@ public function __construct()
* @param string $text
* @return void
*/
public function telegramToolHandler(string $text): void
public function telegramToolHandler(string $text = '/start'): void
{
set_time_limit(60);
switch ($text) {
case '/start':
$reply = view('tools.start', ['first_name' => $this->telegram->FirstName()]);
Expand All @@ -43,6 +69,9 @@ public function telegramToolHandler(string $text): void
case '/settings':
$this->settingService->settingHandle();
break;
case '/set_menu':
$this->setMyCommands();
break;
default:
$this->sendMessage('🤨 Invalid Request!');
}
Expand Down Expand Up @@ -80,4 +109,17 @@ 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)
]);
$this->sendMessage(view('tools.set_menu'));
}
}

0 comments on commit 9f48afb

Please sign in to comment.