Skip to content

Commit 9c0d8d5

Browse files
committed
Add view file support for notification content.
Closes #82.
1 parent cfa3d1f commit 9c0d8d5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/TelegramFile.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace NotificationChannels\Telegram;
44

5+
use Illuminate\Support\Facades\View;
56
use JsonSerializable;
67
use NotificationChannels\Telegram\Traits\HasSharedLogic;
8+
use Psr\Http\Message\StreamInterface;
79

810
/**
911
* Class TelegramFile.
@@ -55,9 +57,9 @@ public function content(string $content): self
5557
*
5658
* Generic method to attach files of any type based on API.
5759
*
58-
* @param string $file
59-
* @param string $type
60-
* @param string|null $filename
60+
* @param string|resource|StreamInterface $file
61+
* @param string $type
62+
* @param string|null $filename
6163
*
6264
* @return $this
6365
*/
@@ -69,7 +71,7 @@ public function file($file, string $type, string $filename = null): self
6971

7072
if ($filename !== null || $isLocalFile) {
7173
$this->payload['file'] = [
72-
'filename' => $filename,
74+
'filename' => $filename,
7375
'name' => $type,
7476
'contents' => $isLocalFile ? fopen($file, 'rb') : $file,
7577
];
@@ -182,6 +184,21 @@ public function videoNote(string $file): self
182184
return $this->file($file, 'video_note');
183185
}
184186

187+
/**
188+
* Attach a view file as the content for the notification.
189+
* Supports Laravel blade template.
190+
*
191+
* @param string $view
192+
* @param array $data
193+
* @param array $mergeData
194+
*
195+
* @return $this
196+
*/
197+
public function view(string $view, array $data = [], array $mergeData = []): self
198+
{
199+
return $this->content(View::make($view, $data, $mergeData)->render());
200+
}
201+
185202
/**
186203
* Determine there is a file.
187204
*

src/TelegramMessage.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace NotificationChannels\Telegram;
44

5+
use Illuminate\Support\Facades\View;
56
use JsonSerializable;
67
use NotificationChannels\Telegram\Traits\HasSharedLogic;
78

@@ -46,4 +47,19 @@ public function content(string $content): self
4647

4748
return $this;
4849
}
50+
51+
/**
52+
* Attach a view file as the content for the notification.
53+
* Supports Laravel blade template.
54+
*
55+
* @param string $view
56+
* @param array $data
57+
* @param array $mergeData
58+
*
59+
* @return $this
60+
*/
61+
public function view(string $view, array $data = [], array $mergeData = []): self
62+
{
63+
return $this->content(View::make($view, $data, $mergeData)->render());
64+
}
4965
}

0 commit comments

Comments
 (0)