| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace ElkenGit\EknotifierPHP;
- use Carbon\Carbon;
- /**
- * Class EmailNotifier to provide Email Notifier integration for EKNotifier Service.
- */
- class EknotifierEmail extends EknotifierCommon
- {
- /**
- * Instantiate EknotifierEmail Class.
- *
- * @param string|null $url
- * @param string|null $applicationCode
- * @param string|null $applicationPassword
- * @throws \Exception
- */
- public function __construct(string $url = null, string $applicationCode = null, string $applicationPassword = null)
- {
- parent::__construct($url, $applicationCode, $applicationPassword);
- }
- /**
- * Send email to the eknotifier service.
- *
- * @param array $emails
- * @param string $subject
- * @param string $text
- * @param int $userId
- * @return bool
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function sendEmail(array $emails, string $subject, string $text): bool
- {
- $token = $this->getAuthToken();
- $request = [
- 'name' => $this->applicationCode . ' EMAIL ' . (count($emails) > 1 ? '[multiple]' : $emails[0]['email']),
- 'send_at' => Carbon::now()->format('Y-m-d H:i:s'),
- 'recipients' => []
- ];
- foreach ($emails as $recipient) {
- $request['recipients'][] = [
- 'application_user_id' => $recipient['user_id'] ?? 0,
- 'delivery_destination' => $recipient['email'],
- 'delivery_type' => 'EMAIL',
- 'subject' => $subject,
- 'body' => $text
- ];
- }
- $response = $this->postAPI('notification/send', $request, $token);
- return $response->getStatusCode() === 200;
- }
- }
|