actengage / laravel-message-gears
MessageGears notification drivers for Laravel.
Installs: 2 395
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/config: ^11.0
- illuminate/notifications: ^11.0
- illuminate/support: ^11.0
Requires (Dev)
- laravel/pint: ^1.8
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^10.0
README
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
Config
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' => '...', ] ]
Laravel Notification
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 = 'test@test.com'; $user->save(); $user->notify(new SendTransactionalCampaign([ 'campaignId' => 'CAMPAIGN_ID' ]));
Submit Transactional Campaign
Manually send a transactional campaign using the service provider.
app('messagegears')->submitTransactionCampaign([ 'campaignId' => 'CAMPAIGN_ID', 'recipient' => [ 'email' => 'test@test.com' ] ]);
Fluent Message Builder
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('test@test.com') ->context('some.nested.context', true); app('messagegears')->submitTransactionalCampaign($message)
Custom Notifications
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); } }