Alerting & messaging can be used to inform the right person at the right time with the right data. For example you could send out alerts to Slack or MS Teams when stock levels drop below a threshold, or you could send out weekly emails with personalized PDF or Excel reports to each store manager in a large retail company.

Related info per connector:

Slack - Getting started in Peliqan

Microsoft Teams - Getting started in Peliqan

Postmark - Getting started in Peliqan

Send a message to Slack

You can use the Slack connector to send messages and alerts to Slack users and Slack channels. Example:

message = {
    "text": "Stock levels are below threshold !",
    "channel": "logistics",
    "username": "Peliqan bot"
}

conn = pq.connect('Slack')
result = conn.add('message', message)
st.json(result) # for debugging only, see result of sending message to Slack

Send out emails

You can sign up for a free account on Postmark, and use the Postmark connector in Peliqan to both receive and send out emails.

Send an email

email = {
    "from": "[email protected]",
    "to": "[email protected]",
    "subject": "Here is your weekly report",
    "text": "We are happy to provide you with this report !",
    "html": "We are <b>happy</b> to provide you with this report !"
}

conn = pq.connect('Postmark')
result = conn.add('email', email)
st.json(result) # for debugging only, see result of sending email to Postmark

Send email with data

Example sending an email with the result of an SQL SELECT query, on a table in the Peliqan data warehouse:

import json

dbconn = pq.dbconnect(pq.DW_NAME)
query = "SELECT id, name FROM my_schema.my_table"
df = dbconn.fetch(pq.DW_NAME, query = query, df = True)

# more info: <https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html>
html = df.to_html(col_space = 50, border = 0, justify = "left")

email = {
    "from": "[email protected]",
    "to": "[email protected]",
    "subject": "Your data",
    "html": "Here is your data: <br><br>" + json.dumps(html).strip('"')
}

conn = pq.connect('Postmark')
result = conn.add('email', email)
st.json(result) # for debugging only, see result of sending email to Postmark

Send email with text file as attachment

import base64

text_file_content = "This will be in the attached text file."

email = {
    "from": "[email protected]",
    "to": "[email protected]",
    "subject": "Test email with attachment",
    "text": "See Text file attached.",
    "html": "See Text file attached.",
    "attachment_name": "my_file.txt",
    "attachment_content_base64": base64.b64encode(text_file_content.encode("ascii")).decode("ascii"),
    "attachment_contenttype": "text/plain"
}

conn = pq.connect('Postmark')
result = conn.add('email_with_attachment', email)
st.json(result) # for debugging only, see result of sending email to Postmark

Send email with CSV file as attachment

Example where we store the result of SQL SELECT query in a CSV file and send this file as an email attachment: