-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetWebhookMethod.php
64 lines (58 loc) · 2.16 KB
/
SetWebhookMethod.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Kolirt\Telegram\Core\Methods\Updates;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\PendingRequest;
/**
* @see https://core.telegram.org/bots/api#setwebhook
*/
trait SetWebhookMethod
{
/**
* Use this method to specify a URL and receive incoming updates
* via an outgoing webhook. Whenever there is an update for the bot,
* we will send an HTTPS POST request to the specified URL, containing
* a JSON-serialized Update. In case of an unsuccessful request, we
* will give up after a reasonable amount of attempts. Returns True on success.
*
* If you'd like to make sure that the webhook was set by you, you can specify
* secret data in the parameter secret_token. If specified, the request will
* contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.
*
* @param string $url
* @param string|null $ip_address
* @param int|null $max_connections
* @param array|null $allowed_updates
* @param bool|null $drop_pending_updates
* @param string|null $secret_token
*
* @return SetWebhookResponse
*
* @throws ConnectionException
* @throws GuzzleException
*/
public function setWebhook(
string $url,
// InputFileType|null $certificate = null,
string|null $ip_address = null,
int|null $max_connections = null,
array $allowed_updates = null,
bool|null $drop_pending_updates = null,
string|null $secret_token = null,
): SetWebhookResponse
{
/**
* @var PendingRequest $this ->client
*/
$response = $this->client->post('setWebhook', request_params([
'url' => $url,
// 'certificate' => $certificate,
'ip_address' => $ip_address,
'max_connections' => $max_connections,
'allowed_updates' => $allowed_updates,
'drop_pending_updates' => $drop_pending_updates,
'secret_token' => $secret_token
]))->getBody();
return new SetWebhookResponse(json_decode($response, true));
}
}