Skip to content

Commit

Permalink
Merge pull request #67 from TeskaLabs/Enhancement/Wrapper-configuration
Browse files Browse the repository at this point in the history
Enhancement: Wrapper must be configurable.
  • Loading branch information
mithunbharadwaj authored Apr 8, 2024
2 parents cf69adc + 3f03263 commit 555b2e4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@

- Loading external templates for content wrapping in iris

#### 08.04.2024

- Markdown wrapper configuration.


### Bugfix

Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,24 @@ subject=Mail from ASAB Iris
- `starttls`: `yes`/`no` for STARTTLS, depends on the SMTP server.
- `subject`: The default subject line, if not provided by a caller or a template.


## Email Markdown Wrapper Configuration

**Configuration**

```ini
[email]
markdown_wrapper=/Templates/Email/body_wrapper.html
```

- `markdown_wrapper`: Specifies the path to the HTML template for wrapping email content.
If this configuration is not provided, or if the value is left empty, the markdown_wrapper will default to None. In such cases, Markdown-formatted emails will be sent without any additional HTML wrapping. This means the emails will consist solely of the content converted from Markdown to HTML, without any extra styling or structure provided by a wrapper template.

### 🚨 2. Sending Slack messages

**Overview**

- Send messages to a Slack via HTTP REST API or thru Kafka Topic
- Send messages to a Slack via HTTP REST API or through Kafka Topic
- Apply Jinja2 templates.
- Trigger them through a web handler or an Apache Kafka message - flexibility is key!

Expand Down
18 changes: 15 additions & 3 deletions asabiris/orchestration/sendemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Classes:
SendEmailOrchestrator: Orchestrates the sending of emails.
"""

import asab
import os
import re
import datetime
Expand Down Expand Up @@ -46,6 +46,12 @@ def __init__(self, app):

self.SmtpService = app.get_service("SmtpService")

# Check if 'email' section exists and 'markdown_wrapper' is neither None nor empty
if 'email' in asab.Config and asab.Config.get("email", "markdown_wrapper"):
self.MarkdownWrapper = asab.Config.get("email", "markdown_wrapper")
else:
self.MarkdownWrapper = None


async def send_email(
self,
Expand Down Expand Up @@ -112,9 +118,15 @@ async def _render_template(self, template: str, params: Dict, body_template_wrap
body, subject = find_subject_in_md(jinja_output)
html_body = self.MarkdownToHTMLService.format(body)

if body_template_wrapper is not None:
# Determine the appropriate wrapper to use.
# First preference is given to body_template_wrapper if it's provided and not empty.
# If body_template_wrapper is None or empty, fallback to the class's MarkdownWrapper.
wrapper_to_use = body_template_wrapper if body_template_wrapper not in [None, ''] else self.MarkdownWrapper

# Apply the wrapper if it exists and is not empty
if wrapper_to_use not in [None, '']:
html_body_param = {"content": html_body}
html_body = await self.JinjaService.format(body_template_wrapper, html_body_param)
html_body = await self.JinjaService.format(wrapper_to_use, html_body_param)

return html_body, subject

Expand Down
4 changes: 4 additions & 0 deletions qa.md
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,10 @@ EXPECTED RESPONSE:
{"type":"email", "to": ["Shivashankar <[email protected]>"], "from": "[email protected]", "body":{"template":"/Templates/Export.md", "params":{"name": "I am testing a template", "error": "None" }}}
'MARKDOWN-WRAPPER'
{"type":"email", "markdown_wrapper":"/Templates/Email/body_wrapper.html", "to": ["Shivashankar <[email protected]>"], "from": "[email protected]", "body":{"template":"/Templates/Email/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
'Missing from'
{"type":"email", "to": ["Shivashankar <[email protected]>"], "body":{"template":"/Templates/Email/message.md", "params":{"name": "I am testing a template", "error": "None" }}}
Expand Down

0 comments on commit 555b2e4

Please sign in to comment.