Skip to content

Commit 66d34b3

Browse files
authored
Merge pull request #42 from laravel-notification-channels/feature-add-set-Image
Add setImageAttachments Method
2 parents ad69bcd + d972fb2 commit 66d34b3

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function routeNotificationForOneSignal()
123123
- `button(OneSignalButton $button)`: Allows you to add buttons to the notification (Supported by iOS 8.0 and Android 4.1+ devices. Icon only works for Android).
124124
- `setData($key, $value)`: Allows you to set additional data for the message payload. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference).
125125
- `setParameter($key, $value)`: Allows you to set additional parameters for the message payload that are available for the REST API. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference).
126+
- `setImageAttachments($imageUrl)`: Allows you to set one Image to all possible Attachments [OneSignal Attachment documentation](https://documentation.onesignal.com/reference#section-attachments).
126127

127128
### Button usage
128129

src/OneSignalMessage.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ public function button(OneSignalButton $button)
162162
return $this;
163163
}
164164

165+
/**
166+
* Set an image to all possible attachment variables.
167+
* @param string $imageUrl
168+
*
169+
* @return $this
170+
*/
171+
public function setImageAttachments($imageUrl)
172+
{
173+
$this->extraParameters['ios_attachments']['id1'] = $imageUrl;
174+
$this->extraParameters['big_picture'] = $imageUrl;
175+
$this->extraParameters['adm_big_picture'] = $imageUrl;
176+
$this->extraParameters['chrome_big_picture'] = $imageUrl;
177+
178+
return $this;
179+
}
180+
165181
/**
166182
* @return array
167183
*/

tests/MessageTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,15 @@ public function it_can_set_a_button()
108108
$this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'buttons.0.text'));
109109
$this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'buttons.0.icon'));
110110
}
111+
112+
/** @test */
113+
public function it_can_set_a_image()
114+
{
115+
$this->message->setImageAttachments('https://url.com/to/image.jpg');
116+
117+
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'ios_attachments.id1'));
118+
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'big_picture'));
119+
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'adm_big_picture'));
120+
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'chrome_big_picture'));
121+
}
111122
}

0 commit comments

Comments
 (0)