Completed
Push — master ( 0a6e40...a44d55 )
by Camilo
06:48
created

SetWebhook::getLocalFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Methods;
6
7
use Generator;
8
use Psr\Log\LoggerInterface;
9
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
10
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
11
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse;
12
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
13
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
14
15
/**
16
 * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update
17
 * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of
18
 * an unsuccessful request, we will give up after a reasonable amount of attempts. Returns true.
19
 *
20
 * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL,
21
 * e.g. https://www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
22
 *
23
 * Notes
24
 * <ul>
25
 *  <li>You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.</li>
26
 *  <li>To use a self-signed certificate, you need to upload your public key certificate using certificate parameter.
27
 *      Please upload as InputFile, sending a String will not work.</li>
28
 *  <li>Ports currently supported for Webhooks: 443, 80, 88, 8443.</li>
29
 * </ul>
30
 *
31
 * Objects defined as-is January 2017
32
 *
33
 * @see https://core.telegram.org/bots/api#setwebhook
34
 */
35
class SetWebhook extends TelegramMethods
36
{
37
    /**
38
     * Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration
39
     * @var string
40
     */
41
    public $url;
42
43
    /**
44
     * Optional. Upload your public key certificate so that the root certificate in use can be checked. See our
45
     * self-signed guide for details.
46
     * @see https://core.telegram.org/bots/self-signed
47
     * @var InputFile
48
     */
49
    public $certificate;
50
51
    /**
52
     * Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to
53
     * 40. Use lower values to limit the load on your bot‘s server, and higher values to increase your bot’s
54
     * throughput
55
     * @var int
56
     */
57
    public $max_connections = 40;
58
59
    /**
60
     * List the types of updates you want your bot to receive. For example, specify
61
     * [“message”, “edited_channel_post”, “callback_query”]
62
     * to only receive updates of these types. See Update for a complete list of available update types. Specify an
63
     * empty list to receive all updates regardless of type (default). If not specified, the previous setting will be
64
     * used.
65
     *
66
     * Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted
67
     * updates may be received for a short period of time.
68
     * @see Update
69
     * @var string[]
70
     */
71
    public $allowed_updates = [];
72
73 2
    public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
74
    {
75 2
        return new ResultBoolean($data->getResultBoolean(), $logger);
76
    }
77
78 3
    public function getMandatoryFields(): array
79
    {
80
        return [
81 3
            'url',
82
        ];
83
    }
84
85 3
    public function hasLocalFiles(): bool
86
    {
87 3
        return $this->certificate instanceof InputFile;
88
    }
89
90
    public function getLocalFiles(): Generator
91
    {
92
        yield 'certificate' => $this->certificate;
93
    }
94
}
95