pe / component-messenger
messenger
v1.0.0
2023-04-21 04:36 UTC
Requires
- php: ^7.4
- ext-json: *
- ext-simplexml: *
- psr/http-message: ^1.1
- psr/log: ^1.1
Requires (Dev)
- php-mock/php-mock: ^2.1
- php-mock/php-mock-phpunit: ^2.5
- phpunit/phpunit: ^9.3
README
The following versions of PHP are supported.
- PHP 7.4+
Installation
To install, use composer:
php composer.phar require pe/component-messenger
Usage
This package allow you to send templated messages via various channels and services. There are predefined channels to send a chat, mail, sms and push messages. All you need - create integration (described below).
namespace PE\Component\Messenger; use PE\Component\Messenger\Channel\ChatChannel; use PE\Component\Messenger\Template\ChatTemplate; // Example chat (other types has same api) /* @var $transport TransportInterface */ $transport = '...';// Telegram, Viber, WhatsApp, etc $channel = new ChatChannel($transport); $template = new ChatTemplate('Hello {{name}}', []); $recipient = new Recipient('internalID', ['name' => 'John']); // Send messages and get event collection with results $events = $channel->send($template, $recipient/*, <other recipients>*/); // That's all!
Create integration
For create integration you need implement:
- Factory that implement
PE\Component\Messenger\FactoryInterface
to create instances from DSN - Transport that implement
PE\Component\Messenger\TransportInterface
to send via specific API - (Optionally) Collector that implement
PE\Component\Messenger\CollectorInterface
to handle webhook calls - (Optionally) Validator that implement
PE\Component\Messenger\ValidatorInterface
to check integration successfully configured on remote side
Now you can use transport directly or integrate to integrations list.
For that you need add your factory to PE\Component\Messenger\FactoryMap
,
maybe via some DI container/framework.