1 | <?php |
||
11 | class Send extends AbstractApi |
||
12 | { |
||
13 | const SENDER_ACTION_TYPING_ON = 'typing_on'; |
||
14 | const SENDER_ACTION_TYPING_OFF = 'typing_off'; |
||
15 | const SENDER_ACTION_MARK_SEEN = 'mark_seen'; |
||
16 | |||
17 | const NOTIFICATION_TYPE_REGULAR = 'REGULAR'; |
||
18 | const NOTIFICATION_TYPE_SILENT_PUSH = 'SILENT_PUSH'; |
||
19 | const NOTIFICATION_TYPE_NO_PUSH = 'NO_PUSH'; |
||
20 | |||
21 | const TAG_SHIPPING_UPDATE = 'SHIPPING_UPDATE'; |
||
22 | const TAG_RESERVATION_UPDATE = 'RESERVATION_UPDATE'; |
||
23 | const TAG_ISSUE_RESOLUTION = 'ISSUE_RESOLUTION'; |
||
24 | const TAG_APPOINTMENT_UPDATE = 'APPOINTMENT_UPDATE'; |
||
25 | const TAG_GAME_EVENT = 'GAME_EVENT'; |
||
26 | const TAG_TRANSPORTATION_UPDATE = 'TRANSPORTATION_UPDATE'; |
||
27 | const TAG_FEATURE_FUNCTIONALITY_UPDATE = 'FEATURE_FUNCTIONALITY_UPDATE'; |
||
28 | const TAG_TICKET_UPDATE = 'TICKET_UPDATE'; |
||
29 | |||
30 | /** |
||
31 | * @var null|\Kerox\Messenger\Api\Send |
||
32 | */ |
||
33 | private static $_instance; |
||
34 | |||
35 | /** |
||
36 | * Send constructor. |
||
37 | * |
||
38 | * @param string $pageToken |
||
39 | * @param \GuzzleHttp\ClientInterface $client |
||
40 | */ |
||
41 | 10 | public function __construct(string $pageToken, ClientInterface $client) |
|
42 | { |
||
43 | 10 | parent::__construct($pageToken, $client); |
|
44 | 10 | } |
|
45 | |||
46 | /** |
||
47 | * @param string $pageToken |
||
48 | * @param \GuzzleHttp\ClientInterface $client |
||
49 | * |
||
50 | * @return \Kerox\Messenger\Api\Send |
||
51 | */ |
||
52 | 1 | public static function getInstance(string $pageToken, ClientInterface $client): Send |
|
60 | |||
61 | /** |
||
62 | * @param string $recipient |
||
63 | * @param string|\Kerox\Messenger\Model\Message $message |
||
64 | * @param string $notificationType |
||
65 | * @param string|null $tag |
||
66 | * |
||
67 | * @return \Kerox\Messenger\Response\SendResponse |
||
68 | */ |
||
69 | 6 | public function message(string $recipient, $message, string $notificationType = self::NOTIFICATION_TYPE_REGULAR, $tag = null): SendResponse |
|
70 | { |
||
71 | 6 | $message = $this->isValidMessage($message); |
|
72 | 5 | $this->isValidNotificationType($notificationType); |
|
73 | |||
74 | 4 | if ($tag !== null) { |
|
75 | 1 | $this->isValidTag($tag); |
|
76 | } |
||
77 | |||
78 | 3 | $request = new SendRequest($this->pageToken, $message, $recipient, $notificationType, $tag); |
|
79 | 3 | $response = $this->client->post('me/messages', $request->build()); |
|
80 | |||
81 | 3 | return new SendResponse($response); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $recipient |
||
86 | * @param string $action |
||
87 | * @param string $notificationType |
||
88 | * |
||
89 | * @return \Kerox\Messenger\Response\SendResponse |
||
90 | */ |
||
91 | 2 | public function action(string $recipient, string $action, string $notificationType = self::NOTIFICATION_TYPE_REGULAR): SendResponse |
|
101 | |||
102 | /** |
||
103 | * @param \Kerox\Messenger\Model\Message\Attachment $attachment |
||
104 | * |
||
105 | * @return \Kerox\Messenger\Response\SendResponse |
||
106 | */ |
||
107 | 1 | public function attachment(Attachment $attachment): SendResponse |
|
116 | |||
117 | /** |
||
118 | * @param $message |
||
119 | * |
||
120 | * @throws \InvalidArgumentException |
||
121 | * |
||
122 | * @return \Kerox\Messenger\Model\Message |
||
123 | */ |
||
124 | 7 | private function isValidMessage($message): Message |
|
136 | |||
137 | /** |
||
138 | * @param string $notificationType |
||
139 | * |
||
140 | * @throws \InvalidArgumentException |
||
141 | */ |
||
142 | 6 | private function isValidNotificationType(string $notificationType) |
|
149 | |||
150 | /** |
||
151 | * @return array |
||
152 | */ |
||
153 | 6 | private function getAllowedNotificationType(): array |
|
161 | |||
162 | /** |
||
163 | * @param string $action |
||
164 | * |
||
165 | * @throws \InvalidArgumentException |
||
166 | */ |
||
167 | 2 | private function isValidAction(string $action) |
|
174 | |||
175 | /** |
||
176 | * @return array |
||
177 | */ |
||
178 | 2 | private function getAllowedSenderAction(): array |
|
186 | |||
187 | /** |
||
188 | * @param string $tag |
||
189 | * |
||
190 | * @throws \InvalidArgumentException |
||
191 | */ |
||
192 | 1 | private function isValidTag(string $tag) |
|
199 | |||
200 | /** |
||
201 | * @return array |
||
202 | */ |
||
203 | 1 | private function getAllowedTag(): array |
|
216 | } |
||
217 |