Skip to content

Commit f260c81

Browse files
committed
Docs update and fixes
1 parent e936594 commit f260c81

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This package makes it easy to send Telegram notification using [Telegram Bot API
2727
- [Attach a Venue](#attach-a-venue)
2828
- [Attach a Video](#attach-a-video)
2929
- [Attach a GIF File](#attach-a-gif-file)
30+
- [Attach a Sticker](#attach-a-sticker)
3031
- [Routing a Message](#routing-a-message)
3132
- [Handling Response](#handling-response)
3233
- [Exception Handling](#exception-handling)
@@ -318,13 +319,17 @@ Preview:
318319
public function toTelegram($notifiable)
319320
{
320321
return TelegramVenue::create()
321-
->latitude('40.6892494')
322-
->longitude('-74.0466891')
323-
->title('Sample Venue')
324-
->address('123 Main St.');
322+
->latitude('38.8951')
323+
->longitude('-77.0364')
324+
->title('Grand Palace')
325+
->address('Bangkok, Thailand');
325326
}
326327
```
327328

329+
Preview:
330+
331+
![Laravel Telegram Venue Notification Example](https://github.com/user-attachments/assets/96e762a6-c4b5-4d8d-8c2d-9d32adb754d0)
332+
328333
### Attach a Video
329334

330335
```php
@@ -358,6 +363,20 @@ Preview:
358363

359364
![Laravel Telegram Gif Notification Example](https://user-images.githubusercontent.com/1915268/66617071-109ed080-ebf1-11e9-989b-b237f2b9502d.jpg)
360365

366+
### Attach a Sticker
367+
368+
```php
369+
public function toTelegram($notifiable)
370+
{
371+
return TelegramFile::create()
372+
->sticker(storage_path('telegram/AnimatedSticker.tgs'));
373+
}
374+
```
375+
376+
Preview:
377+
378+
![Laravel Telegram Sticker Notification Example](https://github.com/user-attachments/assets/5206aac7-022c-4288-ae26-3a117f117fe0)
379+
361380
### Routing a Message
362381

363382
You can either send the notification by providing with the chat ID of the recipient to the `to($chatId)` method like shown in the previous examples or add a `routeNotificationForTelegram()` method in your notifiable model:

src/Exceptions/CouldNotSendNotification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function telegramRespondedWithAnError(ClientException $exception):
2525

2626
$statusCode = $exception->getResponse()->getStatusCode();
2727

28-
$result = json_decode($exception->getResponse()->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR);
28+
$result = json_decode($exception->getResponse()->getBody()->getContents());
2929
$description = $result->description ?? 'no description given';
3030

3131
return new self("Telegram responded with an error `{$statusCode} - {$description}`", 0, $exception);

src/Telegram.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
*/
1515
class Telegram
1616
{
17-
/** @var string Telegram Bot API Base URI */
18-
protected string $apiBaseUri;
17+
/** Default Telegram Bot API Base URI.*/
18+
protected const API_BASE_URI = 'https://api.telegram.org';
1919

2020
public function __construct(
2121
protected ?string $token = null,
2222
protected HttpClient $http = new HttpClient,
23-
string $apiBaseUri = 'https://api.telegram.org'
23+
protected ?string $apiBaseUri = null
2424
) {
25-
$this->setApiBaseUri($apiBaseUri);
25+
$this->setApiBaseUri($apiBaseUri ?? static::API_BASE_URI);
2626
}
2727

2828
/**

src/TelegramFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function file(mixed $file, FileType|string $type, ?string $filename = nul
6969
$typeValue = $this->type->value;
7070

7171
// Handle file URLs or Telegram file IDs
72-
if (is_string($file) && !$this->isReadableFile($file)) {
72+
if (is_string($file) && !$this->isReadableFile($file) && $filename === null) {
7373
if (!filter_var($file, FILTER_VALIDATE_URL) && !preg_match('/^[a-zA-Z0-9_-]+$/', $file)) {
7474
throw CouldNotSendNotification::invalidFileIdentifier($file);
7575
}

0 commit comments

Comments
 (0)