diff --git a/.gitignore b/.gitignore index 3151de5ad..ac88830b4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ debug/ app/sdks dev/yasd_init.php .phpunit.result.cache +Makefile diff --git a/app/workers/messaging.php b/app/workers/messaging.php index 0ed9853e4..e958d5ece 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -97,16 +97,67 @@ class MessagingV1 extends Worker // call function passing needed credentials returns required provider. $messageId = $this->args['messageId']; - $message = - $this - ->getConsoleDB() - ->getDocument('messages', $messageId); + $messageRecord = + $this + ->getConsoleDB() + ->getDocument('messages', $messageId); - // Contrust Message Object according to each provider type. - // Send the message using respective adapter + $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 + ]; + } } diff --git a/composer.lock b/composer.lock index 55e84a6e7..f2b39d841 100644 --- a/composer.lock +++ b/composer.lock @@ -1557,19 +1557,20 @@ }, { "name": "utopia-php/database", - "version": "0.42.2", + "version": "0.42.3", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "bc5ceb30c85fb685b0b5704d2f74886d813ebd41" + "reference": "ab0e2f8ad46884f69b354cd8ee84a1a75fee26d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/bc5ceb30c85fb685b0b5704d2f74886d813ebd41", - "reference": "bc5ceb30c85fb685b0b5704d2f74886d813ebd41", + "url": "https://api.github.com/repos/utopia-php/database/zipball/ab0e2f8ad46884f69b354cd8ee84a1a75fee26d1", + "reference": "ab0e2f8ad46884f69b354cd8ee84a1a75fee26d1", "shasum": "" }, "require": { + "ext-mbstring": "*", "ext-pdo": "*", "php": ">=8.0", "utopia-php/cache": "0.8.*", @@ -1607,9 +1608,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.42.2" + "source": "https://github.com/utopia-php/database/tree/0.42.3" }, - "time": "2023-08-17T19:04:37+00:00" + "time": "2023-08-22T02:15:28+00:00" }, { "name": "utopia-php/domains",