Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function routeNotificationForOneSignal()
- `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).
- `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).
- `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).
- `setImageAttachments($imageUrl)`: Allows you to set one Image to all possible Attachments [OneSignal Attachment documentation](https://documentation.onesignal.com/reference#section-attachments).

### Button usage

Expand Down
16 changes: 16 additions & 0 deletions src/OneSignalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ public function button(OneSignalButton $button)
return $this;
}

/**
* Set an image to all possible attachment variables.
* @param string $imageUrl
*
* @return $this
*/
public function setImageAttachments($imageUrl)
{
$this->extraParameters['ios_attachments']['id1'] = $imageUrl;
$this->extraParameters['big_picture'] = $imageUrl;
$this->extraParameters['adm_big_picture'] = $imageUrl;
$this->extraParameters['chrome_big_picture'] = $imageUrl;

return $this;
}

/**
* @return array
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,15 @@ public function it_can_set_a_button()
$this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'buttons.0.text'));
$this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'buttons.0.icon'));
}

/** @test */
public function it_can_set_a_image()
{
$this->message->setImageAttachments('https://url.com/to/image.jpg');

$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'ios_attachments.id1'));
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'big_picture'));
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'adm_big_picture'));
$this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'chrome_big_picture'));
}
}