@@ -12,6 +12,11 @@ class FcmMessage implements Message
1212{
1313 use Macroable;
1414
15+ /**
16+ * Extra android notification options (channel_id, sound, color, etc.).
17+ */
18+ protected ?array $ androidNotification = null ;
19+
1520 /**
1621 * Create a new message instance.
1722 */
@@ -57,7 +62,7 @@ public function token(?string $token): self
5762 }
5863
5964 /**
60- * Set the message topic.s
65+ * Set the message topic.
6166 */
6267 public function topic (?string $ topic ): self
6368 {
@@ -95,7 +100,7 @@ public function data(?array $data): self
95100 */
96101 public function custom (?array $ custom ): self
97102 {
98- $ this ->custom = $ custom ;
103+ $ this ->custom = $ custom ?? [] ;
99104
100105 return $ this ;
101106 }
@@ -120,9 +125,26 @@ public function usingClient(Messaging $client): self
120125 return $ this ;
121126 }
122127
128+ /**
129+ * Helper to define android.notification options.
130+ *
131+ * Example:
132+ * ->androidNotification([
133+ * 'channel_id' => 'alertas-operativas',
134+ * 'sound' => 'default',
135+ * ])
136+ */
137+ public function androidNotification (array $ options ): self
138+ {
139+ $ this ->androidNotification = $ options ;
140+
141+ return $ this ;
142+ }
143+
123144 public function toArray ()
124145 {
125- return array_filter ([
146+ // payload base
147+ $ payload = array_filter ([
126148 'name ' => $ this ->name ,
127149 'data ' => $ this ->data ,
128150 'token ' => $ this ->token ,
@@ -131,6 +153,17 @@ public function toArray()
131153 'notification ' => $ this ->notification ?->toArray(),
132154 ...$ this ->custom ,
133155 ]);
156+
157+ // si usamos el helper, lo metemos en android.notification
158+ if (! empty ($ this ->androidNotification )) {
159+ $ payload ['android ' ] = $ payload ['android ' ] ?? [];
160+ $ payload ['android ' ]['notification ' ] = array_merge (
161+ $ payload ['android ' ]['notification ' ] ?? [],
162+ $ this ->androidNotification
163+ );
164+ }
165+
166+ return $ payload ;
134167 }
135168
136169 /**
0 commit comments