Skip to content

Commit

Permalink
Explore using Jinja for templating (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay authored Aug 24, 2021
1 parent bc72eb5 commit 17ba907
Show file tree
Hide file tree
Showing 12 changed files with 1,004 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.d/376.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for using Jinja2 in e-mail templates. Contributed by H-Shay.
8 changes: 8 additions & 0 deletions matrix_is_test/res/is-test/invite_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"token": "{{ token }}",
"room_alias": "{{ room_alias }}",
"room_avatar_url": "{{ room_avatar_url }}",
"room_name": "{{ room_name }}",
"sender_display_name": "{{ sender_display_name }}",
"sender_avatar_url": "{{ sender_avatar_url }}"
}
1 change: 1 addition & 0 deletions matrix_is_test/res/is-test/verification_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<<{{ token }}>>>
146 changes: 146 additions & 0 deletions res/matrix-org/invite_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
Date: {{ date|safe }}
From: {{ from|safe }}
To: {{ to|safe }}
Message-ID: {{ messageid|safe }}
Subject: {{ subject_header_value|safe }}
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="{{ multipart_boundary|safe }}"

--{{ multipart_boundary|safe }}
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

Hi,

{{ sender_display_name|safe }} {{ bracketed_verified_sender|safe }}has invited you into a room
{{ bracketed_room_name|safe }}on Matrix. To join the conversation, either pick a
Matrix client from https://matrix.org/docs/projects/try-matrix-now.html or use
the single-click link below to join via Element (requires Chrome, Firefox,
Safari, iOS or Android)


{{ web_client_location }}/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fmatrix.org%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}


About Matrix:

Matrix.org is an open standard for interoperable, decentralised, real-time communication
over IP, supporting group chat, file transfer, voice and video calling, integrations to
other apps, bridges to other communication systems and much more. It can be used to power
Instant Messaging, VoIP/WebRTC signalling, Internet of Things communication - or anywhere
you need a standard HTTP API for publishing and subscribing to data whilst tracking the
conversation history.

Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.

Thanks,

Matrix

--{{ multipart_boundary|safe }}
Content-Type: text/html; charset=UTF-8
Content-Disposition: inline

<!doctype html>
<html lang="en">
<head>
<style type="text/css">
body {
margin: 0px;
}
pre, code {
word-break: break-word;
white-space: pre-wrap;
}
#page {
font-family: 'Open Sans', Helvetica, Arial, Sans-Serif;
font-color: #454545;
font-size: 12pt;
width: 100%%;
padding: 20px;
}
.low-contrast {
color: #666666
}
#inner {
width: 640px;
}
.header {
width: 100%%;
height: 87px;
color: #454545;
border-bottom: 4px solid #e5e5e5;
}
.logo {
text-align: right;
margin-left: 20px;
}
</style>
</head>
<body>
<table id="page">
<tr>
<td> </td>
<td id="inner">
<table class="header">
<tr>
<td>
</td>
<td class="logo">
<img src="http://matrix.org/img/matrix-120x51.png" width="120" height="51" alt="[matrix]"/>
</td>
</tr>
</table>

<p>Hi,</p>

<p>{{ sender_display_name }} <span class="low-contrast">{{ bracketed_verified_sender }}</span> has invited you into a room {{ bracketed_room_name }} on
Matrix. To join the conversation, either <a href="https://matrix.org/docs/projects/try-matrix-now.html">pick a Matrix client</a> or use the single-click
link below to join via Element (requires
<a href="https://www.google.com/chrome">Chrome</a>,
<a href="https://www.getfirefox.com">Firefox</a> or
<a href="https://www.apple.com/safari">Safari</a> on the web,
or iOS or Android on mobile.)</p>
</p>

<p>
<a
href="https://app.element.io/#/room/{{ room_id|urlencode }}?email={{ to|urlencode }}&signurl=https%3A%2F%2Fmatrix.org%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3D{{ token|urlencode }}%26private_key%3D{{ ephemeral_private_key|urlencode }}&room_name={{ room_name|urlencode }}&room_avatar_url={{ room_avatar_url|urlencode }}&inviter_name={{ sender_display_name|urlencode }}&guest_access_token={{ guest_access_token|urlencode }}&guest_user_id={{ guest_user_id|urlencode }}">Join the conversation.</a>
</p>

<br>
<p>About Matrix:</p>

<p>Matrix.org is an open standard for interoperable, decentralised, real-time communication
over IP, supporting group chat, file transfer, voice and video calling, integrations to
other apps, bridges to other communication systems and much more. It can be used to power
Instant Messaging, VoIP/WebRTC signalling, Internet of Things communication - or anywhere
you need a standard HTTP API for publishing and subscribing to data whilst tracking the
conversation history.</p>

<p>Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.</p>

<p>Thanks,</p>

<p>Matrix</p>
</td>
<td> </td>
</tr>
</table>
</body>
</html>

--{{ multipart_boundary|safe }}--
88 changes: 88 additions & 0 deletions res/matrix-org/verification_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Date: {{ date|safe }}
From: {{ from|safe }}
To: {{ to|safe }}
Message-ID: {{ messageid|safe }}
Subject: Confirm your email address for Matrix
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="{{ multipart_boundary|safe }}"

--{{ multipart_boundary|safe }}
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

Hello,

We have received a request to use this email address with a matrix.org identity
server. If this was you who made this request, you may use the following link
to complete the verification of your email address:

{{ link|safe }}

If your client requires a code, the code is {{ token|safe }}

If you aren't aware of making such a request, please disregard this email.


About Matrix:

Matrix is an open standard for interoperable, decentralised, real-time communication
over IP. It can be used to power Instant Messaging, VoIP/WebRTC signalling, Internet
of Things communication - or anywhere you need a standard HTTP API for publishing and
subscribing to data whilst tracking the conversation history.

Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.

--{{ multipart_boundary|safe }}
Content-Type: text/html; charset=UTF-8
Content-Disposition: inline

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body {
font-family: "Myriad Pro", "Myriad", Helvetica, Arial, sans-serif;
font-size: 12pt;
margin: 0px;
}
</style>
</head>
<body>
<p>Hello,</p>

<p>We have received a request to use this email address with a matrix.org
identity server. If this was you who made this request, you may use the
following link to complete the verification of your email address:</p>

<p><a href="{{ link }}">Complete email verification</a></p>

<p>...or copy this link into your web browser:</p>

<p>{{ link }}</p>

<p>If your client requires a code, the code is {{ token }}</p>

<p>If you aren't aware of making such a request, please disregard this
email.</p>

<br>
<p>About Matrix:</p>

<p>Matrix is an open standard for interoperable, decentralised, real-time communication
over IP. It can be used to power Instant Messaging, VoIP/WebRTC signalling, Internet
of Things communication - or anywhere you need a standard HTTP API for publishing and
subscribing to data whilst tracking the conversation history.</p>

<p>Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.</p>

</body>
</html>

--{{ multipart_boundary|safe }}--
Loading

0 comments on commit 17ba907

Please sign in to comment.