@@ -37,7 +37,14 @@ public function registerBundles()
37
37
``` yaml
38
38
BoShurikTelegramBotBundle :
39
39
resource : " @BoShurikTelegramBotBundle/Resources/config/routing.php"
40
- prefix : /_telegram/<some-secret>
40
+ prefix : /_telegram/%telegram_bot_route_secret%
41
+ ` ` `
42
+
43
+ or for multiple bots:
44
+ ` ` ` yaml
45
+ BoShurikTelegramBotBundle :
46
+ resource : " @BoShurikTelegramBotBundle/Resources/config/routing.php"
47
+ prefix : /_telegram/{bot}/%telegram_bot_route_secret%
41
48
` ` `
42
49
43
50
#### Configuration
@@ -49,12 +56,39 @@ boshurik_telegram_bot:
49
56
proxy : " socks5://127.0.0.1:8888"
50
57
` ` `
51
58
59
+ or for multiple bots:
60
+ ` ` ` yaml
61
+ boshurik_telegram_bot :
62
+ api :
63
+ default_bot : first
64
+ bots :
65
+ first : " %first_telegram_bot_api_token%"
66
+ second : " %second_telegram_bot_api_token%"
67
+ proxy : " socks5://127.0.0.1:8888"
68
+ ` ` `
69
+
52
70
## Usage
53
71
54
72
#### API
55
73
74
+ To get default bot api:
75
+ ` ` ` php
76
+ use TelegramBot\Api\BotApi;
77
+ public function __construct(private BotApi $api)
78
+ ```
79
+
80
+ For multiple bots:
81
+
56
82
``` php
57
- $api = $this->container->get(TelegramBot\Api\BotApi::class);
83
+
84
+ use BoShurik\TelegramBotBundle\Telegram\BotLocator;
85
+ use TelegramBot\Api\BotApi;
86
+
87
+ public function foo(BotLocator $botLocator)
88
+ {
89
+ /** @var BotApi $api */
90
+ $api = $botLocator->get('first');
91
+ }
58
92
```
59
93
60
94
For more info see [ Usage] [ 2 ] section in [ ` telegram-bot/api ` ] [ 1 ] library
@@ -63,6 +97,7 @@ For more info see [Usage][2] section in [`telegram-bot/api`][1] library
63
97
64
98
``` bash
65
99
bin/console telegram:updates
100
+ bin/console telegram:updates first
66
101
```
67
102
68
103
For more information see [ official documentation] [ 3 ]
@@ -72,13 +107,15 @@ For more information see [official documentation][3]
72
107
##### Set
73
108
74
109
``` bash
75
- bin/console telegram:webhook:set < url> [< path-to-certificate> ]
110
+ bin/console telegram:webhook:set < url-or-hostname> [< path-to-certificate> ]
111
+ bin/console telegram:webhook:set < url-or-hostname> [< path-to-certificate> ] --bot first
76
112
```
77
113
78
114
##### Unset
79
115
80
116
``` bash
81
117
bin/console telegram:webhook:unset
118
+ bin/console telegram:webhook:unset first
82
119
```
83
120
84
121
For more information see [ official documentation] [ 4 ]
@@ -118,16 +155,43 @@ app.telegram.command:
118
155
119
156
If you use `autoconfigure` tag will be added automatically
120
157
121
- There is predefined `\BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand`. You need to register it :
158
+ For application with multiple bots you need to pass bot id :
159
+ ` ` ` yaml
160
+ app.telegram.command:
161
+ class: AppBundle\T elegram\C ommand\S omeCommand
162
+ tags:
163
+ - { name: boshurik_telegram_bot.command, bot: first }
164
+ ` ` `
165
+ If you need to use same command for multiple bots you must add multiple tags for each bot :
166
+ ` ` ` yaml
167
+ app.telegram.command:
168
+ class: AppBundle\T elegram\C ommand\S omeCommand
169
+ tags:
170
+ - { name: boshurik_telegram_bot.command, bot: first }
171
+ - { name: boshurik_telegram_bot.command, bot: second }
172
+ ` ` `
173
+
174
+ There is predefined `\BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand`.
175
+ It displays commands which additionally implement `\BoShurik\TelegramBotBundle\Telegram\Command\PublicCommandInterface`
176
+
177
+ You need to register it :
122
178
` ` ` yaml
123
179
app.telegram.command.help:
124
180
class: BoShurik\T elegramBotBundle\T elegram\C ommand\H elpCommand
125
181
arguments:
126
- - '@BoShurik \T elegramBotBundle \T elegram \C ommand \C ommandRegistry '
182
+ - '@boshurik_telegram_bot.command.registry.default '
127
183
tags:
128
184
- { name: boshurik_telegram_bot.command }
129
185
` ` `
130
- It displays commands which additionally implement `\BoShurik\TelegramBotBundle\Telegram\Command\PublicCommandInterface`
186
+ or for multiple bots :
187
+ ` ` ` yaml
188
+ app.telegram.command.help:
189
+ class: BoShurik\T elegramBotBundle\T elegram\C ommand\H elpCommand
190
+ arguments:
191
+ - '@boshurik_telegram_bot.command.registry.first'
192
+ tags:
193
+ - { name: boshurik_telegram_bot.command, bot: first }
194
+ ` ` `
131
195
132
196
# ### Events
133
197
@@ -147,7 +211,7 @@ public function onUpdate(UpdateEvent $event)
147
211
148
212
This bundle supports login through Telegram Api
149
213
150
- If you want allow your Bot's users to login without requiring them to register again
214
+ If you want to allow your Bot's users to login without requiring them to register again
151
215
follow these [instructions](LOGIN_WITH_TELEGRAM.md).
152
216
153
217
[1] : https://github.com/TelegramBot/Api
0 commit comments