Downloads
Stars
Version
This is an API wrapper for MessageGears specifically for Laravel. This package providers a fluent syntax for sending MessageGears requests and notifications in Laravel.
composer require actengage/laravel-message-gears
Define the MessageGears config in the config/services.php
file. Any value here is considered the global default and can be overriden on a per-request basis.
// config/services.php
return [
'messagesgears' => [
'api_key' => '...',
'account_id' => '...',
'campaign_id' => '...',
]
]
Using the default notification is simple. Instantiate the notification and pass the parameters. Any parameters will override global or defaults values.
use Actengage\MessageGears\Notifications\SendTransactionalCampaign;
$user = new User();
$user->email = '[email protected]';
$user->save();
$user->notify(new SendTransactionalCampaign([
'campaignId' => 'CAMPAIGN_ID'
]));
Manually send a transactional campaign using the service provider.
app('messagegears')->submitTransactionCampaign([
'campaignId' => 'CAMPAIGN_ID',
'recipient' => [
'email' => '[email protected]'
]
]);
You can also instantiate the fluent message builder and send the message directly.
use Actengage\MessageGears\TransactionalCampaignSubmit;
$message = (new TransactionalCampaignSubmit)
->accountId(1)
->apiKey('API_KEY')
->to('[email protected]')
->context('some.nested.context', true);
app('messagegears')->submitTransactionalCampaign($message)
This is an example of notification. The toTransactionalCampaign
campaign must return an instance of Actengage\MessageGears\TransactionalCampaignSubmit
.
<?php
namespace Actengage\MessageGears\Notifications;
use Illuminate\Notifications\Notification;
use Actengage\MessageGears\TransactionalCampaignChannel;
use Actengage\MessageGears\Messages\TransactionalCampaignSubmit;
class SendTransactionalCampaign extends Notification
{
/**
* The notification params.
*
* @var array $params
*/
public $params;
/**
* The notification constructor.
*
* @param array $params
* @return void
*/
public function __construct(array $params = [])
{
$this->params = $params;
}
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return [TransactionalCampaignChannel::class];
}
/**
* Cast the notification as a transactional campaign message.
*
* @param array $params
* @return \Actengage\MessageGears\TransactionalCampaignSubmit
*/
public function toTransactionalCampaign($notifiable)
{
return new TransactionalCampaignSubmit($this->params);
}
}