2
2
3
3
namespace NotificationChannels \Telegram ;
4
4
5
- use Illuminate \Support \Facades \View ;
6
5
use JsonSerializable ;
7
- use NotificationChannels \ Telegram \ Traits \ HasSharedLogic ;
6
+ use Illuminate \ Support \ Facades \ View ;
8
7
use Psr \Http \Message \StreamInterface ;
8
+ use NotificationChannels \Telegram \Traits \HasSharedLogic ;
9
9
10
10
/**
11
11
* Class TelegramFile.
@@ -18,7 +18,7 @@ class TelegramFile implements JsonSerializable
18
18
public $ type = 'document ' ;
19
19
20
20
/**
21
- * @param string $content
21
+ * @param string $content
22
22
*
23
23
* @return self
24
24
*/
@@ -30,7 +30,7 @@ public static function create(string $content = ''): self
30
30
/**
31
31
* Message constructor.
32
32
*
33
- * @param string $content
33
+ * @param string $content
34
34
*/
35
35
public function __construct (string $ content = '' )
36
36
{
@@ -41,7 +41,7 @@ public function __construct(string $content = '')
41
41
/**
42
42
* Notification message (Supports Markdown).
43
43
*
44
- * @param string $content
44
+ * @param string $content
45
45
*
46
46
* @return $this
47
47
*/
@@ -57,26 +57,29 @@ public function content(string $content): self
57
57
*
58
58
* Generic method to attach files of any type based on API.
59
59
*
60
- * @param string|resource|StreamInterface $file
61
- * @param string $type
62
- * @param string|null $filename
60
+ * @param string|resource|StreamInterface $file
61
+ * @param string $type
62
+ * @param string|null $filename
63
63
*
64
64
* @return $this
65
65
*/
66
66
public function file ($ file , string $ type , string $ filename = null ): self
67
67
{
68
68
$ this ->type = $ type ;
69
69
70
- $ isLocalFile = $ this ->isReadableFile ($ file );
71
-
72
- if ($ filename !== null || $ isLocalFile ) {
73
- $ this ->payload ['file ' ] = [
74
- 'filename ' => $ filename ,
75
- 'name ' => $ type ,
76
- 'contents ' => $ isLocalFile ? fopen ($ file , 'rb ' ) : $ file ,
77
- ];
78
- } else {
70
+ if (is_string ($ file ) && !$ this ->isReadableFile ($ file )) {
79
71
$ this ->payload [$ type ] = $ file ;
72
+
73
+ return $ this ;
74
+ }
75
+
76
+ $ this ->payload ['file ' ] = [
77
+ 'name ' => $ type ,
78
+ 'contents ' => is_resource ($ file ) ? $ file : fopen ($ file , 'rb ' ),
79
+ ];
80
+
81
+ if ($ filename !== null ) {
82
+ $ this ->payload ['file ' ]['filename ' ] = $ filename ;
80
83
}
81
84
82
85
return $ this ;
@@ -87,7 +90,7 @@ public function file($file, string $type, string $filename = null): self
87
90
*
88
91
* Use this method to send photos.
89
92
*
90
- * @param string $file
93
+ * @param string $file
91
94
*
92
95
* @return $this
93
96
*/
@@ -102,7 +105,7 @@ public function photo(string $file): self
102
105
* Use this method to send audio files, if you want Telegram clients to display them in the music player.
103
106
* Your audio must be in the .mp3 format.
104
107
*
105
- * @param string $file
108
+ * @param string $file
106
109
*
107
110
* @return $this
108
111
*/
@@ -116,8 +119,8 @@ public function audio(string $file): self
116
119
*
117
120
* Use this method to send general files.
118
121
*
119
- * @param string $file
120
- * @param string|null $filename
122
+ * @param string $file
123
+ * @param string|null $filename
121
124
*
122
125
* @return $this
123
126
*/
@@ -131,7 +134,7 @@ public function document(string $file, string $filename = null): self
131
134
*
132
135
* Use this method to send video files, Telegram clients support mp4 videos.
133
136
*
134
- * @param string $file
137
+ * @param string $file
135
138
*
136
139
* @return $this
137
140
*/
@@ -145,7 +148,7 @@ public function video(string $file): self
145
148
*
146
149
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
147
150
*
148
- * @param string $file
151
+ * @param string $file
149
152
*
150
153
* @return $this
151
154
*/
@@ -160,7 +163,7 @@ public function animation(string $file): self
160
163
* Use this method to send audio files, if you want Telegram clients to display the file as a playable voice
161
164
* message. For this to work, your audio must be in an .ogg file encoded with OPUS.
162
165
*
163
- * @param string $file
166
+ * @param string $file
164
167
*
165
168
* @return $this
166
169
*/
@@ -175,7 +178,7 @@ public function voice(string $file): self
175
178
* Telegram clients support rounded square mp4 videos of up to 1 minute long.
176
179
* Use this method to send video messages.
177
180
*
178
- * @param string $file
181
+ * @param string $file
179
182
*
180
183
* @return $this
181
184
*/
@@ -188,9 +191,9 @@ public function videoNote(string $file): self
188
191
* Attach a view file as the content for the notification.
189
192
* Supports Laravel blade template.
190
193
*
191
- * @param string $view
192
- * @param array $data
193
- * @param array $mergeData
194
+ * @param string $view
195
+ * @param array $data
196
+ * @param array $mergeData
194
197
*
195
198
* @return $this
196
199
*/
@@ -237,7 +240,7 @@ public function toMultipart(): array
237
240
/**
238
241
* Determine if it's a regular and readable file.
239
242
*
240
- * @param string $file
243
+ * @param string $file
241
244
*
242
245
* @return bool
243
246
*/
0 commit comments