mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Use phtml instead of translation files for webhook email
This commit is contained in:
parent
e91a652feb
commit
7393bfc244
4 changed files with 39 additions and 280 deletions
21
app/config/locale/templates/email-webhook.phtml
Normal file
21
app/config/locale/templates/email-webhook.phtml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Hi <strong><?php echo $this->getParam('user') ?></strong>,
|
||||
<br /><br />
|
||||
Your webhook <strong><?php echo $this->getParam('webhook') ?></strong> on project <strong><?php echo $this->getParam('project') ?></strong> has been paused after <?php echo $this->getParam('attempts') ?> consecutive failures. <br /><br />
|
||||
<p>Webhook URL: <strong><?php echo $this->getParam('url') ?></strong></p>
|
||||
<p>Error: <strong><?php echo $this->getParam('error') ?></strong></p> <br />To restore the functionality of your webhook, please take the following steps:<br /><br />
|
||||
1. Debug the webhook to identify and resolve the issue:
|
||||
<ul>
|
||||
<li>Examine the logs of both Appwrite Console and your webhook server to identify the issue</li>
|
||||
<li>Investigate potential network issues and use webhook testing tools to verify expected behaviour</li>
|
||||
<li>Ensure the webhook URL is reachable and configured to accept incoming POST requests</li>
|
||||
<li>Confirm that the webhook doesn't return error status codes such as 400 or 500</li>
|
||||
</ul>
|
||||
2. Re-enable the webhook from the project settings page
|
||||
|
||||
<table border="0" cellspacing="0" cellpadding="0" style="padding-top: 10px; padding-bottom: 10px; display: inline-block; margin-top: 32px">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 8px; background-color: #FD366E;">
|
||||
<a rel="noopener" target="_blank" href="<?php echo $this->getParam('redirect') ?>" style="font-size: 14px; font-family: Inter; color: #ffffff; text-decoration: none; border-radius: 8px; padding: 9px 14px; border: 1px solid #FD366E; display: inline-block;">View webhook settings</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=DM+Sans:wght@500;600&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style>
|
||||
.main a {
|
||||
color: currentColor;
|
||||
}
|
||||
.main {
|
||||
padding: 32px;
|
||||
line-height: 1.5;
|
||||
color: #616b7c;
|
||||
font-size: 15px;
|
||||
font-weight: 400;
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-spacing: 0;
|
||||
}
|
||||
table,
|
||||
tr,
|
||||
th,
|
||||
td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
td {
|
||||
vertical-align: top;
|
||||
}
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
margin-bottom: 0px;
|
||||
margin-top: 0px;
|
||||
color: #373b4d;
|
||||
}
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #373b4d;
|
||||
}
|
||||
h3,
|
||||
td h3 {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #373b4d;
|
||||
line-height: 21px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
h4 {
|
||||
font-family: "DM Sans", sans-serif;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
color: #4f5769;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
hr {
|
||||
border: none;
|
||||
border-top: 1px solid #e8e9f0;
|
||||
}
|
||||
.main a.button {
|
||||
display: inline-block;
|
||||
background: #fd366e;
|
||||
color: #ffffff;
|
||||
border-radius: 8px;
|
||||
height: 48px;
|
||||
padding: 12px 20px;
|
||||
box-sizing: border-box;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
border-color: #fd366e;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
margin-right: 24px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.main a.button:hover,
|
||||
.main a.button:focus {
|
||||
opacity: 0.8;
|
||||
}
|
||||
.main a.button.is-reverse {
|
||||
background: #fff;
|
||||
color: #fd366e;
|
||||
}
|
||||
.fs12 {
|
||||
font-size: 12px;
|
||||
}
|
||||
.ta-right {
|
||||
text-align: right !important;
|
||||
}
|
||||
.ta-left {
|
||||
text-align: left !important;
|
||||
}
|
||||
.ff-dmsans {
|
||||
font-family: "DM Sans", sans-serif !important;
|
||||
}
|
||||
.ff-inter {
|
||||
font-family: "Inter", sans-serif !important;
|
||||
}
|
||||
.w500 {
|
||||
font-weight: 500 !important;
|
||||
}
|
||||
.w400 {
|
||||
font-weight: 400 !important;
|
||||
}
|
||||
.w600 {
|
||||
font-weight: 600 !important;
|
||||
}
|
||||
.tc-accent {
|
||||
color: #da1a5b;
|
||||
}
|
||||
.pt-16 {
|
||||
padding-top: 16px !important;
|
||||
}
|
||||
.pt-32 {
|
||||
padding-top: 32px !important;
|
||||
}
|
||||
.divider {
|
||||
padding-top: 32px;
|
||||
border-bottom: solid 1px #d8d8db;
|
||||
}
|
||||
.social-icon {
|
||||
border-radius: 6px;
|
||||
background: rgba(216, 216, 219, 0.1);
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.social-icon > img {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
.button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main" style="max-width: 650px; margin: 0 auto">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img
|
||||
height="32px"
|
||||
src="https://appwrite.io/assets/logotype/white.png"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table style="margin-top: 32px">
|
||||
<tr>
|
||||
<td>
|
||||
<h1>{{subject}}</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table style="margin-top: 40px">
|
||||
<tr>
|
||||
<td>{{message}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table border="0" cellspacing="0" cellpadding="0" style="padding-top: 10px; padding-bottom: 10px; display: inline-block; margin-top: 32px">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 8px; background-color: #FD366E;">
|
||||
<a rel="noopener" target="_blank" href="{{redirect}}" style="font-size: 14px; font-family: Inter; color: #ffffff; text-decoration: none; border-radius: 8px; padding: 9px 14px; border: 1px solid #FD366E; display: inline-block;">{{buttonText}}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>{{optionUrl}}</p>
|
||||
<a href="{{redirect}}" target="_blank" style="font-size: 12px; line-height: 100%;">{{redirect}}</a>
|
||||
|
||||
<table
|
||||
style="
|
||||
padding-top: 32px;
|
||||
margin-top: 32px;
|
||||
border-top: solid 1px #e8e9f0;
|
||||
"
|
||||
>
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table style="width: auto; margin: 0 auto">
|
||||
<tr>
|
||||
<td style="padding-left: 4px; padding-right: 4px">
|
||||
<a
|
||||
href="https://twitter.com/appwrite"
|
||||
class="social-icon"
|
||||
title="Twitter"
|
||||
>
|
||||
<img src="https://appwrite.io/email/x.png" height="24" width="24" />
|
||||
</a>
|
||||
</td>
|
||||
<td style="padding-left: 4px; padding-right: 4px">
|
||||
<a
|
||||
href="https://appwrite.io/discord"
|
||||
class="social-icon"
|
||||
>
|
||||
<img src="https://appwrite.io/email/discord.png" height="24" width="24" />
|
||||
</a>
|
||||
</td>
|
||||
<td style="padding-left: 4px; padding-right: 4px">
|
||||
<a
|
||||
href="https://github.com/appwrite/appwrite"
|
||||
class="social-icon"
|
||||
>
|
||||
<img src="https://appwrite.io/email/github.png" height="24" width="24" />
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table style="width: auto; margin: 0 auto; margin-top: 60px">
|
||||
<tr>
|
||||
<td><a href="https://appwrite.io/terms">Terms</a></td>
|
||||
<td style="color: #e8e9f0">
|
||||
<div style="margin: 0 8px">|</div>
|
||||
</td>
|
||||
<td><a href="https://appwrite.io/privacy">Privacy</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p style="text-align: center" align="center">
|
||||
© 2023 Appwrite | 251 Little Falls Drive, Wilmington 19808,
|
||||
Delaware, United States
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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 <strong>{{user}}</strong>,<br><br>Your webhook <strong>{{webhook}}</strong> on project <strong>{{project}}</strong> has been paused after {{attempts}} consecutive failures. <br><br>Webhook URL: <strong>{{url}}</strong><br>Error: <strong>{{error}}</strong> <br><br>To restore the functionality of your webhook, please take the following steps:<br>1. Debug the webhook to identify and resolve the issue.<br>2. Re-enable the webhook from the project settings page.<br><br>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",
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue