Skip to content

Commit 9f48afb

Browse files
authored
Merge pull request #86 from tanhongit/feature/menu
Feature/menu
2 parents 3724ffa + 2f3852a commit 9f48afb

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,24 @@ If you want to check the menu, you can send the following message to your bot.
316316
/menu
317317
```
318318

319-
🎊 **At this point, the configuration process for your telegram bot is completed. You can use all the features of this bot.** 🎉🎉
319+
🎊 At this point, the configuration process for your telegram bot is completed.
320+
You can use all the features of this bot.
321+
🎉🎉
320322

321323
<p align="center">
322-
<img alt="Menu features of this bot" src="https://github.com/lbiltech/telegram-bot-github-notify/assets/35853002/5aa42173-9443-4978-a59a-82f2ed016790" />
324+
<img alt="Menu features of this bot" src="https://github.com/lbiltech/telegram-bot-github-notify/assets/35853002/1a725130-c7c4-4594-9669-abc6d2dc1fba" />
325+
</p>
326+
327+
**To increase ease of use. Let's create a menu with a list of commands listed for you.**
328+
329+
Please send the following message to your bot to create a menu button.
330+
331+
```text
332+
/set_menu
333+
```
334+
335+
<p align="center">
336+
<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" />
323337
</p>
324338

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

resources/tools/menu.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
<?php
2+
3+
use TelegramGithubNotify\App\Services\TelegramService;
4+
5+
$menuCommands = TelegramService::MENU_COMMANDS ?? [];
6+
?>
7+
18
<b>BOT MENU</b> 🤖
29

3-
/server - To get Server Information.
4-
/id - To get your Chat ID.
5-
/token - To get this bot token.
6-
/usage - How to use me.
7-
/settings - Settings GitHub notify.
8-
/menu - To get this menu.
10+
<?php foreach ($menuCommands as $menuCommand) : ?>
11+
<b><?= $menuCommand['command'] ?></b> - <?= $menuCommand['description'] ?>
12+
13+
<?php endforeach; ?>
914

1015
Select a button:

resources/tools/set_menu.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
✅ Menu button set successfully!
2+
3+
Please restart the bot to apply the changes.

src/Services/TelegramService.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@
66

77
class TelegramService extends AppService
88
{
9+
public const MENU_COMMANDS = [
10+
[
11+
'command' => '/start',
12+
'description' => 'Welcome to the bot'
13+
], [
14+
'command' => '/menu',
15+
'description' => 'Show menu of the bot'
16+
], [
17+
'command' => '/token',
18+
'description' => 'Show token of the bot'
19+
], [
20+
'command' => '/id',
21+
'description' => 'Show the ID of the current chat'
22+
], [
23+
'command' => '/usage',
24+
'description' => 'Show step by step usage'
25+
], [
26+
'command' => '/server',
27+
'description' => 'To get Server Information'
28+
], [
29+
'command' => '/settings',
30+
'description' => 'Show settings GitHub notify'
31+
],
32+
];
33+
934
public array $messageData;
1035

1136
public SettingService $settingService;
@@ -24,8 +49,9 @@ public function __construct()
2449
* @param string $text
2550
* @return void
2651
*/
27-
public function telegramToolHandler(string $text): void
52+
public function telegramToolHandler(string $text = '/start'): void
2853
{
54+
set_time_limit(60);
2955
switch ($text) {
3056
case '/start':
3157
$reply = view('tools.start', ['first_name' => $this->telegram->FirstName()]);
@@ -43,6 +69,9 @@ public function telegramToolHandler(string $text): void
4369
case '/settings':
4470
$this->settingService->settingHandle();
4571
break;
72+
case '/set_menu':
73+
$this->setMyCommands();
74+
break;
4675
default:
4776
$this->sendMessage('🤨 Invalid Request!');
4877
}
@@ -80,4 +109,17 @@ public function checkCallback(): bool
80109
}
81110
return false;
82111
}
112+
113+
/**
114+
* Set the menu button for a telegram
115+
*
116+
* @return void
117+
*/
118+
public function setMyCommands(): void
119+
{
120+
$this->telegram->setMyCommands([
121+
'commands' => json_encode(self::MENU_COMMANDS)
122+
]);
123+
$this->sendMessage(view('tools.set_menu'));
124+
}
83125
}

0 commit comments

Comments
 (0)