| Conditions | 4 |
| Paths | 4 |
| Total Lines | 28 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | public function setWebhook(string $url, array $data = []): Response |
||
| 29 | { |
||
| 30 | if ($url === '') { |
||
| 31 | throw new TelegramException('Hook url is empty!'); |
||
| 32 | } |
||
| 33 | |||
| 34 | if (!str_starts_with($url, 'https://')) { |
||
| 35 | throw new TelegramException('Hook url must start with https://'); |
||
| 36 | } |
||
| 37 | |||
| 38 | $data = array_intersect_key($data, array_flip([ |
||
| 39 | 'certificate', |
||
| 40 | 'ip_address', |
||
| 41 | 'max_connections', |
||
| 42 | 'allowed_updates', |
||
| 43 | 'drop_pending_updates', |
||
| 44 | ])); |
||
| 45 | $data['url'] = $url; |
||
| 46 | |||
| 47 | $result = Request::setWebhook($data); |
||
| 48 | |||
| 49 | if (!$result->isOk()) { |
||
| 50 | throw new TelegramException( |
||
| 51 | 'Webhook was not set! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription() |
||
| 52 | ); |
||
| 53 | } |
||
| 54 | |||
| 55 | return $result; |
||
| 56 | } |
||
| 78 | } |