Alerts

Import the alerts resource module and instantiate the client

[ ]:
from peak.resources import alerts

alert_client: alerts.Alert = alerts.get_client()

List all existing email(s) and iterate over them

[ ]:
email_list_iterator = alert_client.list_emails()
email_list_iterated = next(email_list_iterator)

"""
The list would be a dictionary with the following structure:

{
  "emailCount": 1,
  "emails": [
    {
      "createdAt": "2020-01-01T00:00:00.000Z",
      "createdBy": "someone@peak.ai",
      "id": 1,
      "status": "Delivered",
      "subject": "Hello from SDK!",
      "templateName": "your_template_name",
    }
  ],
  "pageCount": 1,
  "pageNumber": 1,
  "pageSize": 25
}

"""

Sending a new email

[ ]:
"""
Consider the HTML template:

<html>
<head>
    <title>Peak Email</title>
</head>
<body>
    <h1>Hello {{name}}!</h1>
    <p>Thank you for your interest in {{company}}.</p>
    <p>Best regards,</p>
    <p>Your friends at Peak</p>
</body>
</html>

The templateParameters should be a dictionary with the keys matching the placeholders in the template.
"""

body = {
    "recipients": ["person1@peak.ai"],
    "cc": ["person2@peak.ai"],
    "bcc": ["person3@peak.ai"],
    "subject": "Hello from SDK!",
    "templateName": "your_template_name",
    "templateParameters": {
        "name": "John Doe",
        "company": "Peak",
    },
}

response = alert_client.send_email(body=body)

Describe an existing email

[ ]:
email_record = alert_client.describe_email(email_id=response["emailId"])

"""
The email_record will be a dictionary with the following structure:

{
  "createdAt": "2020-01-01T00:00:00.000Z",
  "createdBy": "someone@peak.ai",
  "deliveredAt": "2024-01-01T00:00:01.000Z",
  "id": 1,
  "recipients": {
    "cc": [],
    "to": ["person1@peak.ai"],
    "bcc": []
  },
  "status": "Delivered",
  "statusDetails": [
    {
      "email": "person1@peak.ai",
      "status": "Delivered",
      "description": "The email was successfully delivered."
    }
  ],
  "subject": "Hello from SDK!",
  "templateName": "your_template_name"
}
"""

List all existing template(s) and iterate over them

[ ]:
templatete_list_iterator = alert_client.list_templates()
template_list_iterated = next(templatete_list_iterator)

"""
The list would be a dictionary with the following structure:

{
    "templateCount": 1,
    "templates": [
        {
            "id": 1,
            "createdAt": "2021-09-01T12:00:00Z",
            "createdBy": "platform@peak.ai",
            "name": "test_template",
            "scope": "custom"
        }
    ],
    "pageCount": 1,
    "pageNumber": 1,
    "pageSize": 25
}

"""

Describe an existing template

[ ]:
template_details = alert_client.describe_template(template_name=response["templateName"])

"""
The email_record will be a dictionary with the following structure:

{
    "id": 1,
    "createdAt": "2021-09-01T12:00:00Z",
    "createdBy": "platform@peak.ai",
    "name": "test_template",
    "subject": "Important Account Update Information",
    "body": "<h1>Hello</h1><p>Your account has been updated.</p>",
    "scope": "custom"
}

"""