Skip to content

Commit 6cd9409

Browse files
authored
Add On-Demand Notifications Info.
1 parent f17a756 commit 6cd9409

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ This package makes it easy to send Telegram notification using [Telegram Bot API
2020
- [Attach a Document](#attach-a-document)
2121
- [Attach a Location](#attach-a-location)
2222
- [Attach a Video](#attach-a-video)
23-
- [Attach a Gif File](#attach-a-gif-file)
23+
- [Attach a GIF File](#attach-a-gif-file)
2424
- [Routing a Message](#routing-a-message)
2525
- [Handling Response](#handling-response)
26+
- [On-Demand Notifications](#on-demand-notifications)
2627
- [Available Message methods](#available-message-methods)
2728
- [Available Location methods](#available-location-methods)
2829
- [Available File methods](#available-file-methods)
@@ -100,10 +101,8 @@ Here's a screenshot preview of the above notification on Telegram Messenger:
100101
```php
101102
public function toTelegram($notifiable)
102103
{
103-
$url = url('/file/' . $this->file->id);
104-
105104
return TelegramFile::create()
106-
->to($notifiable->telegram_user_id)
105+
->to($notifiable->telegram_user_id) // Optional
107106
->content('Awesome *bold* text and [inline URL](http://www.example.com/)')
108107
->file('/storage/archive/6029014.jpg', 'photo'); // local photo
109108

@@ -121,10 +120,8 @@ Preview:
121120
```php
122121
public function toTelegram($notifiable)
123122
{
124-
$url = url('/file/' . $this->file->id);
125-
126123
return TelegramFile::create()
127-
->to($notifiable->telegram_user_id)
124+
->to($notifiable->telegram_user_id) // Optional
128125
->content('Did you know we can set a custom filename too?')
129126
->document('https://file-examples.com/wp-content/uploads/2017/10/file-sample_150kB.pdf', 'sample.pdf');
130127
}
@@ -140,7 +137,6 @@ Preview:
140137
public function toTelegram($notifiable)
141138
{
142139
return TelegramLocation::create()
143-
->to($notifiable->telegram_user_id)
144140
->latitude('40.6892494')
145141
->longitude('-74.0466891');
146142
}
@@ -156,7 +152,6 @@ Preview:
156152
public function toTelegram($notifiable)
157153
{
158154
return TelegramFile::create()
159-
->to($notifiable->telegram_user_id)
160155
->content('Sample *video* notification!')
161156
->video('https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4');
162157
}
@@ -166,7 +161,7 @@ Preview:
166161

167162
![Laravel Telegram Video Notification Example](https://user-images.githubusercontent.com/1915268/66617038-ed742100-ebf0-11e9-865a-bf0245d2cbbb.jpg)
168163

169-
### Attach a Gif File
164+
### Attach a GIF File
170165

171166
```php
172167
public function toTelegram($notifiable)
@@ -186,10 +181,9 @@ Preview:
186181

187182
### Routing a Message
188183

189-
You can either send the notification by providing with the chat id of the recipient to the `to($chatId)` method like shown in the above example or add a `routeNotificationForTelegram()` method in your notifiable model:
184+
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:
190185

191186
```php
192-
...
193187
/**
194188
* Route notifications for the Telegram channel.
195189
*
@@ -199,7 +193,6 @@ public function routeNotificationForTelegram()
199193
{
200194
return $this->telegram_user_id;
201195
}
202-
...
203196
```
204197

205198
### Handling Response
@@ -208,6 +201,17 @@ You can make use of the [notification events](https://laravel.com/docs/5.8/notif
208201

209202
For a complete list of response fields, please refer the Telegram Bot API's [Message object](https://core.telegram.org/bots/api#message) docs.
210203

204+
### On-Demand Notifications
205+
206+
> Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the `Notification::route` method, you may specify ad-hoc notification routing information before sending the notification. For more details, you can check out the [on-demand notifications](https://laravel.com/docs/5.8/notifications#on-demand-notifications) docs.
207+
208+
```php
209+
use NotificationChannels\Telegram\TelegramChannel;
210+
211+
Notification::route(TelegramChannel::class, 'TELEGRAM_CHAT_ID')
212+
->notify(new InvoicePaid($invoice));
213+
```
214+
211215
### Available Message methods
212216

213217
- `to($chatId)`: (integer) Recipient's chat id.

0 commit comments

Comments
 (0)