Skip to content

Commit 394893d

Browse files
committed
Update to include latest changes from PHP Telegram API.
1 parent 0312722 commit 394893d

File tree

7 files changed

+68
-52
lines changed

7 files changed

+68
-52
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ Parameter | Description
159159
--------- |------------
160160
webhook | URL to the manager PHP file used for setting up the Webhook.
161161
| *e.g.* `'https://example.com/manager.php'`
162-
selfcrt | Path to a self-signed certificate (if necessary).
162+
certificate | Path to a self-signed certificate (if necessary).
163163
| *e.g.* `__DIR__ . '/server.crt'`
164+
max_connections | Maximum allowed simultaneous HTTPS connections to the webhook
165+
| *e.g.* `20`
166+
allowed_updates | List the types of updates you want your bot to receive
167+
| *e.g.* `['message', 'edited_channel_post', 'callback_query']`
164168
logging | Path(s) where to the log files should be put. This is an array that can contain all 3 log file paths (`error`, `debug` and `update`).
165169
| *e.g.* `['error' => __DIR__ . '/php-telegram-bot-error.log']`
166170
admins | An array of user ids that have admin access to your bot.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": "^7.0",
22-
"longman/telegram-bot": "^0.36"
22+
"longman/telegram-bot": "^0.38"
2323
},
2424
"require-dev": {
2525
"phpunit/phpunit": "^5.5",

composer.lock

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BotManager.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,27 @@ public function validateSecret(bool $force = false): self
172172
public function validateAndSetWebhook(): self
173173
{
174174
$webhook = $this->params->getBotParam('webhook');
175-
$selfcrt = $this->params->getBotParam('selfcrt');
176175
if (empty($webhook) && $this->action->isAction(['set', 'reset'])) {
177176
throw new \InvalidArgumentException('Invalid webhook');
178177
}
179178

180179
if ($this->action->isAction(['unset', 'reset'])) {
181-
$this->handleOutput($this->telegram->unsetWebHook()->getDescription() . PHP_EOL);
180+
$this->handleOutput($this->telegram->deleteWebhook()->getDescription() . PHP_EOL);
182181
// When resetting the webhook, sleep for a bit to prevent too many requests.
183182
$this->action->isAction('reset') && sleep(1);
184183
}
184+
185185
if ($this->action->isAction(['set', 'reset'])) {
186+
$webhook_params = array_filter([
187+
'certificate' => $this->params->getBotParam('certificate'),
188+
'max_connections' => $this->params->getBotParam('max_connections'),
189+
'allowed_updates' => $this->params->getBotParam('allowed_updates'),
190+
]);
191+
186192
$this->handleOutput(
187-
$this->telegram->setWebHook(
193+
$this->telegram->setWebhook(
188194
$webhook . '?a=handle&s=' . $this->params->getBotParam('secret'),
189-
$selfcrt
195+
$webhook_params
190196
)->getDescription() . PHP_EOL
191197
);
192198
}

src/Params.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class Params
3636
*/
3737
private static $valid_extra_bot_params = [
3838
'webhook',
39-
'selfcrt',
39+
'certificate',
40+
'max_connections',
41+
'allowed_updates',
4042
'logging',
4143
'admins',
4244
'mysql',
@@ -65,7 +67,9 @@ class Params
6567
* botname (string) Telegram Bot name
6668
* secret (string) Secret string to validate calls
6769
* webhook (string) URI of the webhook
68-
* selfcrt (string) Path to the self-signed certificate
70+
* certificate (string) Path to the self-signed certificate
71+
* max_connections (int) Maximum allowed simultaneous HTTPS connections to the webhook
72+
* allowed_updates (array) List the types of updates you want your bot to receive
6973
* logging (array) Array of logger files to set.
7074
* admins (array) List of admins to enable.
7175
* mysql (array) MySQL credentials to use.

tests/TelegramBotManager/Tests/BotManagerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ public function testValidateAndSetWebhookSuccess()
141141
'telegram',
142142
$this->getMockBuilder(Telegram::class)
143143
->disableOriginalConstructor()
144-
->setMethods(['setWebHook', 'unsetWebHook', 'getDescription'])
144+
->setMethods(['setWebhook', 'deleteWebhook', 'getDescription'])
145145
->getMock()
146146
);
147147

148148
$telegram = $botManager->getTelegram();
149149

150150
/** @var \PHPUnit_Framework_MockObject_MockObject $telegram */
151151
$telegram->expects(static::any())
152-
->method('setWebHook')
152+
->method('setWebhook')
153153
->with('https://web/hook.php?a=handle&s=secret_12345')
154154
->will(static::returnSelf());
155155
$telegram->expects(static::any())
156-
->method('unsetWebHook')
156+
->method('deleteWebhook')
157157
->will(static::returnSelf());
158158
$telegram->expects(static::any())
159159
->method('getDescription')
@@ -229,7 +229,7 @@ public function testValidateAndSetWebhookSuccessLiveBot()
229229
/**
230230
* @group live
231231
*/
232-
public function testUnsetWebhookViaRunLiveBot()
232+
public function testDeleteWebhookViaRunLiveBot()
233233
{
234234
$_GET = ['a' => 'unset'];
235235
$botManager = new BotManager(array_merge(self::$live_params, [
@@ -386,7 +386,7 @@ public function testGetUpdatesLiveBot()
386386
public function testGetUpdatesLoopLiveBot()
387387
{
388388
// Webhook must NOT be set for this to work!
389-
$this->testUnsetWebhookViaRunLiveBot();
389+
$this->testDeleteWebhookViaRunLiveBot();
390390

391391
// Looping for 5 seconds should be enough to get a result.
392392
$_GET = ['l' => 5];

tests/TelegramBotManager/Tests/ParamsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class ParamsTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
public static $demo_extra_params = [
3030
'webhook' => 'https://php.telegram.bot/manager.php',
31-
'selfcrt' => __DIR__ . '/server.crt',
31+
'certificate' => __DIR__ . '/server.crt',
32+
'max_connections' => 20,
33+
'allowed_updates' => ['message', 'edited_channel_post', 'callback_query'],
3234
'admins' => [1],
3335
'mysql' => [
3436
'host' => '127.0.0.1',

0 commit comments

Comments
 (0)