|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace TgBotApi\BotApiBase\Type; |
|
6
|
|
|
|
|
7
|
|
|
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class LoginUrlType |
|
11
|
|
|
*This object represents a parameter of the inline keyboard button used to automatically authorize a user. |
|
12
|
|
|
* Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram. |
|
13
|
|
|
* All the user needs to do is tap/click a button. |
|
14
|
|
|
* |
|
15
|
|
|
* @see https://core.telegram.org/bots/api#loginurl |
|
16
|
|
|
*/ |
|
17
|
|
|
class LoginUrlType |
|
18
|
|
|
{ |
|
19
|
|
|
use FillFromArrayTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. |
|
23
|
|
|
* If the user refuses to provide authorization data, |
|
24
|
|
|
* the original URL without information about the user will be opened. |
|
25
|
|
|
* The data added is the same as described in Receiving authorization data. |
|
26
|
|
|
* |
|
27
|
|
|
* NOTE: You must always check the hash of the received data to verify the authentication |
|
28
|
|
|
* and the integrity of the data as described in Checking authorization. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
public $url; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Optional. Username of a bot, which will be used for user authorization. See Setting up a bot for more details. |
|
36
|
|
|
* If not specified, the current bot's username will be assumed. |
|
37
|
|
|
* The url's domain must be the same as the domain linked with the bot. |
|
38
|
|
|
* See Linking your domain to the bot for more details. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string | null |
|
41
|
|
|
*/ |
|
42
|
|
|
public $forwardText; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Optional. New text of the button in forwarded messages. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string | null |
|
48
|
|
|
*/ |
|
49
|
|
|
public $botUsername; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Optional. Pass True to request the permission for your bot to send messages to the user. |
|
53
|
|
|
* |
|
54
|
|
|
* @var bool | null |
|
55
|
|
|
*/ |
|
56
|
|
|
public $requestWriteAccess; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $url |
|
60
|
|
|
* @param array|null $data |
|
61
|
|
|
* |
|
62
|
|
|
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException |
|
63
|
|
|
* |
|
64
|
|
|
* @return LoginUrlType |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function create(string $url, array $data = null): LoginUrlType |
|
67
|
|
|
{ |
|
68
|
|
|
$instance = new static(); |
|
69
|
|
|
$instance->url = $url; |
|
70
|
|
|
if ($data) { |
|
71
|
|
|
$instance->fill($data); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $instance; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|