1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TgBotApi\BotApiBase; |
6
|
|
|
|
7
|
|
|
use TgBotApi\BotApiBase\Exception\NormalizationException; |
8
|
|
|
use TgBotApi\BotApiBase\Exception\ResponseException; |
9
|
|
|
use TgBotApi\BotApiBase\Helper\AddMethodTrait; |
10
|
|
|
use TgBotApi\BotApiBase\Helper\AnswerMethodTrait; |
11
|
|
|
use TgBotApi\BotApiBase\Helper\CreateMethodTrait; |
12
|
|
|
use TgBotApi\BotApiBase\Helper\DeleteMethodTrait; |
13
|
|
|
use TgBotApi\BotApiBase\Helper\EditMethodTrait; |
14
|
|
|
use TgBotApi\BotApiBase\Helper\ExportMethodTrait; |
15
|
|
|
use TgBotApi\BotApiBase\Helper\ForwardMethodTrait; |
16
|
|
|
use TgBotApi\BotApiBase\Helper\GetMethodTrait; |
17
|
|
|
use TgBotApi\BotApiBase\Helper\KickMethodTrait; |
18
|
|
|
use TgBotApi\BotApiBase\Helper\LeaveMethodTrait; |
19
|
|
|
use TgBotApi\BotApiBase\Helper\PinMethodTrait; |
20
|
|
|
use TgBotApi\BotApiBase\Helper\PromoteMethodTrait; |
21
|
|
|
use TgBotApi\BotApiBase\Helper\RestrictMethodTrait; |
22
|
|
|
use TgBotApi\BotApiBase\Helper\SendMethodTrait; |
23
|
|
|
use TgBotApi\BotApiBase\Helper\SetMethodTrait; |
24
|
|
|
use TgBotApi\BotApiBase\Helper\StopMethodTrait; |
25
|
|
|
use TgBotApi\BotApiBase\Helper\UnbanMethodTrait; |
26
|
|
|
use TgBotApi\BotApiBase\Helper\UnpinMethodTrait; |
27
|
|
|
use TgBotApi\BotApiBase\Helper\UploadMethodTrait; |
28
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\SendMessageInterface; |
29
|
|
|
use TgBotApi\BotApiBase\Type\FileType; |
30
|
|
|
use TgBotApi\BotApiBase\Type\MessageType; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class BotApiHelper. |
34
|
|
|
* \ */ |
35
|
|
|
class BotApiHelper implements BotApiInterface |
36
|
|
|
{ |
37
|
|
|
use AddMethodTrait; |
38
|
|
|
use AnswerMethodTrait; |
39
|
|
|
use CreateMethodTrait; |
40
|
|
|
use DeleteMethodTrait; |
41
|
|
|
use EditMethodTrait; |
42
|
|
|
use ExportMethodTrait; |
43
|
|
|
use ForwardMethodTrait; |
44
|
|
|
use GetMethodTrait; |
45
|
|
|
use KickMethodTrait; |
46
|
|
|
use LeaveMethodTrait; |
47
|
|
|
use PinMethodTrait; |
48
|
|
|
use PromoteMethodTrait; |
49
|
|
|
use RestrictMethodTrait; |
50
|
|
|
use SendMethodTrait; |
51
|
|
|
use SetMethodTrait; |
52
|
|
|
use StopMethodTrait; |
53
|
|
|
use UnbanMethodTrait; |
54
|
|
|
use UnpinMethodTrait; |
55
|
|
|
use UploadMethodTrait; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var BotApiInterface |
59
|
|
|
*/ |
60
|
|
|
private $botApi; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* BotApiHelper constructor. |
64
|
|
|
* |
65
|
|
|
* @param BotApiInterface $botApi |
66
|
|
|
*/ |
67
|
47 |
|
public function __construct(BotApiInterface $botApi) |
68
|
|
|
{ |
69
|
47 |
|
$this->botApi = $botApi; |
70
|
47 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param $method |
74
|
|
|
* @param null $type |
|
|
|
|
75
|
|
|
* |
76
|
|
|
* @throws \TgBotApi\BotApiBase\Exception\NormalizationException |
77
|
|
|
* @throws \TgBotApi\BotApiBase\Exception\ResponseException |
78
|
|
|
* |
79
|
|
|
* @return mixed |
80
|
|
|
*/ |
81
|
44 |
|
public function call($method, $type = null) |
82
|
|
|
{ |
83
|
44 |
|
return $this->botApi->call($method, $type); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param FileType $file |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
1 |
|
public function getAbsoluteFilePath(FileType $file): string |
92
|
|
|
{ |
93
|
1 |
|
return \sprintf( |
94
|
1 |
|
'%s/file/bot%s/%s', |
95
|
1 |
|
$this->botApi->getendPoint(), |
96
|
1 |
|
$this->botApi->getBotKey(), |
97
|
1 |
|
$file->filePath |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param SendMessageInterface $method |
103
|
|
|
* |
104
|
|
|
* @throws ResponseException |
105
|
|
|
* @throws NormalizationException |
106
|
|
|
* |
107
|
|
|
* @return MessageType |
108
|
|
|
*/ |
109
|
14 |
|
public function send(SendMessageInterface $method): MessageType |
110
|
|
|
{ |
111
|
14 |
|
return $this->botApi->call($method, MessageType::class); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
1 |
|
public function getBotKey(): string |
118
|
|
|
{ |
119
|
1 |
|
return $this->botApi->getBotKey(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
1 |
|
public function getEndPoint(): string |
126
|
|
|
{ |
127
|
1 |
|
return $this->botApi->getEndPoint(); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|