Custom Delivery Methods

A custom email method can be created in Python.

Create a file named push_method.py, where method is the name of the communication method you want to create. For example, push_gchat.py would be a good name for a system that sends messages via Google Chat.

This file should be placed in the integrations folder of the reportlist addon. This is found at <ARDI install directory>/web/addons/reportlist

Your script will be called with a single parameter - the path to a JSON file that contains all of the information about the delivery.

JSON Content

The content of the file will look like this…

{
    "files": [
        [
            ".../Test Report (2024-12-08).pdf",
            "Optrix Test Reports (2024-12-08).pdf"
        ]
    ],
    "options": {
        "sitename": "Site Name",
        "sitecode": "",
        "timezone": "Australia\/Sydney",
        "server": "localhost",
         ...
        "apikey": "myserverapikeyishere",        
        "title": "Test Report",
        "bundle": "testing",
        "reporturl": "http://myserver/s/op/reportlist/",
        "bundleurl": "http://mysite/s/op/reportlist/?folder=:testing"
    },
    "to": [
        {
            "name": "Daily",
            "skip": [],
            "contentcode": "full",
            "path": ".../Test Report (2024-12-08).pdf",
            "style": "sharepoint",
            "attachments": [
                [
                    {
                    "name": "Test Report (2024-12-08).pdf",
                    "path": "..../Test Report (2024-12-08).pdf",
                    "contentype": "application/pdf"
                ]
            ]
        }
    ]
}

The Destinations section will include each of the named destinations from the reporting system. Each of those also include an array of 'attachments', containing the full path (trimmed in the example above) and the target file-name of each of the files to be transmitted.

The Options section gives access to any of the user-configured settings, plus some details about the transmission as a whole (such as the title of the email, HTML link back to the report system etc.).

Example Code

You'll find a basic framework for a delivery method below…

import os
import json
import traceback
import base64
 
#Get the content of the file sent to us
pth = os.path.dirname(__file__) + "/content.json"
f = open(pth,'r')
content = f.read()
f.close()
 
content = json.loads(content)
 
#Extract all of the options & libraries we need, such as the from address
messages = content['messages']
fromaddress = content["options"]["smtpfrom"]
 
#TODO: Connect to the target system & authenticate
 
failures = None
 
try:
    #Setup email object    
 
    #For every message to be sent...
    for msg in messages:
        try:
            toaddress = msg['to']
 
            #Create and Send The Message Here
            #msg['title'] contains the subject line,
            #msg['content'] contains plain-text content for the message,
            #msg['richcontent'] contains HTML content for the message,
            #msg['attachments'] contains the list of attachments.
            #   each attachment has a 'name', 'path' and 'contenttype'
 
           #TODO: Actually send the message here.
 
        except:
            if failures is None:
                failures = "Failed To Send"
            else:
                failures += " / Failed To Send"           
 
except Exception as ex:
    failures = "Unable to Connect"
 
 
if failures is None:
    print("----")
    print("SUCCESS")
else:
    print("----")
    print("FAILURE:" + failures)

Basically, you'll need to fill in the two 'TODO' sections - connecting to the destination and transmitting the individual emails. Note that

Setting Up a UI

If this method is going to be re-used across many locations, you can create a UI to help users enter in any required details (ie. authentication, API keys etc.).

Along-side your .py file, you can also create a .json file that contains details about the UI you'd like to create.

{
	"name": "Friendly Name for Destination",
	"type": "publish or push",
	"parameters": [
		{
			"name": "property_name_without_spaces",
			"type": "string|number|path",
			"title": "Human-Readable Title",
			"desc": "A Brief Description of the Parameter"
		}
	],
	"destination": "Description of the Destination",
	"requires": ["required_python_package"]
}

The web interface will let a user fill in settings for each entry in parameters. Each parameter has a title (displayed to the user), a description (displayed to the user), a type (string, number or path), and a name (a unique key for the value).

You can access these parameters in your push script from the content[“options”] dictionary. For example, if your method has a 'name' of 'sendingfrom', you'd access it with…

fromaddress = content["options"]["sendingfrom"]