getAttribute('credentials'); return match ($record->getAttribute('provider')) { 'twilio' => new Twilio($credentials['accountSid'], $credentials['authToken']), 'text-magic' => new TextMagic($credentials['username'], $credentials['apiKey']), 'telesign' => new Telesign($credentials['username'], $credentials['password']), 'msg91' => new Msg91($credentials['senderId'], $credentials['authKey']), 'vonage' => new Vonage($credentials['apiKey'], $credentials['apiSecret']), default => null }; } public function push($record): ?PushAdapter { $credentials = $record->getAttribute('credentials'); return match ($record->getAttribute('provider')) { 'apns' => new APNS( $credentials['authKey'], $credentials['authKeyId'], $credentials['teamId'], $credentials['bundleId'], $credentials['endpoint'] ), 'fcm' => new FCM($credentials['serverKey']), default => null }; } public function email($record): ?EmailAdapter { $credentials = $record->getAttribute('credentials'); return match ($record->getAttribute('provider')) { 'mailgun' => new Mailgun($credentials['apiKey'], $credentials['domain']), 'sendgrid' => new SendGrid($credentials['apiKey']), default => null }; } public function init(): void { } public function run(): void { $providerId = $this->args['providerId']; $providerRecord = $this ->getConsoleDB() ->getDocument('providers', $providerId); $provider = match ($providerRecord->getAttribute('type')) {//stubbbbbbed. 'sms' => $this->sms($providerRecord), 'push' => $this->push($providerRecord), 'email' => $this->email($providerRecord), default => null }; // Query for the provider // switch on provider name // call function passing needed credentials returns required provider. $messageId = $this->args['messageId']; $messageRecord = $this ->getConsoleDB() ->getDocument('messages', $messageId); $message = match ($providerRecord->getAttribute('type')) { 'sms' => $this->buildSMSMessage($messageRecord->getArrayCopy()), 'push' => $this->buildPushMessage($messageRecord->getArrayCopy()), 'email' => $this->buildEmailMessage($messageRecord->getArrayCopy()), default => null }; $provider->send($message); } public function shutdown(): void { } private function buildEmailMessage($data): array { $from = $data['from']; $to = $data['to']; $subject = $data['subject']; $body = $data['content']; return [ 'from' => $from, 'to' => $to, 'subject' => $subject, 'body' => $body, ]; return $message; } private function buildSMSMessage($data): array { $from = $data['from']; $to = $data['to']; $body = $data['content']; return [ 'from' => $from, 'to' => $to, 'body' => $body ]; } private function buildPushMessage($data): array { $to = $data['to']; $title = $data['title']; $body = $data['body']; $data = $data['data']; return [ 'to' => $to, 'title' => $title, 'body' => $body, 'data' => $data ]; } }