diff --git a/app/config/locale/templates/email-webhook.phtml b/app/config/locale/templates/email-webhook.phtml new file mode 100644 index 0000000000..fa58339ab8 --- /dev/null +++ b/app/config/locale/templates/email-webhook.phtml @@ -0,0 +1,21 @@ +Hi getParam('user') ?>, +

+Your webhook getParam('webhook') ?> on project getParam('project') ?> has been paused after getParam('attempts') ?> consecutive failures.

+

Webhook URL: getParam('url') ?>

+

Error: getParam('error') ?>


To restore the functionality of your webhook, please take the following steps:

+1. Debug the webhook to identify and resolve the issue: + +2. Re-enable the webhook from the project settings page + + + + + +
+ View webhook settings +
\ No newline at end of file diff --git a/app/config/locale/templates/email-webhook.tpl b/app/config/locale/templates/email-webhook.tpl deleted file mode 100644 index c4104fb009..0000000000 --- a/app/config/locale/templates/email-webhook.tpl +++ /dev/null @@ -1,245 +0,0 @@ - - - - - - - - -
- - - - -
- -
- - - - - -
-

{{subject}}

-
- - - - - -
{{message}}
- - - - - -
- {{buttonText}} -
- -

{{optionUrl}}

- {{redirect}} - - - - - -
- - - - - - - -
- - - - - -
- - - - - - -
Terms -
|
-
Privacy
-

- © 2023 Appwrite | 251 Little Falls Drive, Wilmington 19808, - Delaware, United States -

-
- - \ No newline at end of file diff --git a/app/config/locale/translations/en.json b/app/config/locale/translations/en.json index f9dcf9f81a..681c88ae94 100644 --- a/app/config/locale/translations/en.json +++ b/app/config/locale/translations/en.json @@ -33,10 +33,6 @@ "emails.certificate.footer": "Your previous certificate will be valid for 30 days since the first failure. We highly recommend investigating this case, otherwise your domain will end up without a valid SSL communication.", "emails.certificate.thanks": "Thanks", "emails.certificate.signature": "{{project}} team", - "emails.webhook.subject": "Your webhook has been paused", - "emails.webhook.body": "Hello {{user}},

Your webhook {{webhook}} on project {{project}} has been paused after {{attempts}} consecutive failures.

Webhook URL: {{url}}
Error: {{error}}

To restore the functionality of your webhook, please take the following steps:
1. Debug the webhook to identify and resolve the issue.
2. Re-enable the webhook from the project settings page.

If you need any assistance, please reach out to our team on Discord or using email support.", - "emails.webhook.buttonText": "View webhook settings", - "emails.webhook.optionUrl": "If the button above doesn't show, use the following link:", "locale.country.unknown": "Unknown", "countries.af": "Afghanistan", "countries.ao": "Angola", diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 6180032266..84602f1d8a 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Mail; use Appwrite\Template\Template; +use Appwrite\Utopia\View; use Exception; use Utopia\App; use Utopia\Database\Document; @@ -152,46 +153,32 @@ class Webhooks extends Action $webhook->setAttribute('logs', $logs); if ($attempts >= self::MAX_FAILED_ATTEMPTS) { - $webhook->setAttribute('enabled', false); - - // send an email to user - $locale = new Locale(App::getEnv('_APP_LOCALE', 'en')); - - if (!$locale->getText('emails.sender') || !$locale->getText("emails.webhook.hello") || !$locale->getText("emails.webhook.subject") || !$locale->getText("emails.webhook.body") || !$locale->getText("emails.webhook.footer") || !$locale->getText("emails.webhook.thanks") || !$locale->getText("emails.webhook.signature")) { - $locale->setDefault('en'); - } - - $subject = $locale->getText("emails.webhook.subject"); - $protocol = App::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; $hostname = App::getEnv('_APP_DOMAIN'); $projectId = $project->getId(); $webhookId = $webhook->getId(); - $message = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-webhook.tpl'); - $message - ->setParam('{{subject}}', $subject) - ->setParam('{{message}}', $locale->getText("emails.webhook.body")) - ->setParam('{{redirect}}', $protocol . '://' . $hostname . "/console/project-$projectId/settings/webhooks/$webhookId") - ->setParam('{{buttonText}}', $locale->getText("emails.webhook.buttonText")) - ->setParam('{{optionUrl}}', $locale->getText("emails.webhook.optionUrl")); - $body = $message->render(); + $template = __DIR__ . '/../../../../app/config/locale/templates/email-webhook.phtml'; + $template = new View($template); - $emailVariables = [ - 'subject' => $subject, - 'user' => $user->getAttribute('name'), - 'project' => $project->getAttribute('name'), - 'link' => $protocol . '://' . $hostname . "/console/project-$projectId/settings/webhooks/$webhookId", - 'webhook' => $webhook->getAttribute('name'), - 'attempts' => $attempts, - 'url' => $webhook->getAttribute('url'), - 'error' => $curlError ?? \mb_strcut($responseBody, 0, 10000), - ]; + $template->setParam('user', $user->getAttribute('name')); + $template->setParam('webhook', $webhook->getAttribute('name')); + $template->setParam('project', $project->getAttribute('name')); + $template->setParam('url', $webhook->getAttribute('url')); + $template->setParam('error', $curlError ?? 'The server returned ' . $statusCode . ' status code'); + $template->setParam('redirect', $protocol . '://' . $hostname . "/console/project-$projectId/settings/webhooks/$webhookId"); + $template->setParam('attempts', $attempts); + + $subject = 'Your webhook has been paused'; + $body = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'); + + $body + ->setParam('{{subject}}', $subject) + ->setParam('{{body}}', $template->render()); $queueForMails ->setSubject($subject) - ->setBody($body) - ->setVariables($emailVariables) + ->setBody($body->render()) ->setRecipient($user->getAttribute('email')) ->trigger(); }