Hermes Util

A set of utility functions shared across all resources.

meerkat_hermes.util.delete_subscriber(subscriber_id)

Delete a subscriber from the database. At the moment, if a user wishes to change information, they need to delete themselves and then re-add themselves with the new information.

Parameters:subscriber_id (str) –
Returns:The amazon dynamodb response.
meerkat_hermes.util.error(args)

Notify the developers of an error in the system. Error notifications can be posted to slack and sent out via email and text. These messages are not subject to the rate limiting that normal published messages are subject to.

Parameters:
  • message (str) – Required. The e-mail message.
  • subject (str) – Optional. Defaults to “Meerkat Error”.
  • medium ([str]) – Optional. A list of the following mediums: ‘email’, ‘sms’, ‘slack’. Defaults to [‘slack’,’email’].
  • sms-message (str) – Optional. The sms version of the message. Defaults to the same as ‘message’
  • html-message (str) – Optional. The html version of the message. Defaults to the same as ‘message’
Returns:

The amazon SES response.

meerkat_hermes.util.get_date()

Function to retreive a current timestamp.

Returns:The current date and time as a string.
meerkat_hermes.util.id_valid(messageID)

Checks whether or not the given messageID has already been logged.

Returns:True for a valid message ID, False for one that has already been logged.
meerkat_hermes.util.limit_exceeded()

Each time the method is called, the time of calling is recorded. It then checks whether more than the allowed threshold number of calls has been made in the past hour.

Returns:True if more than the allowed threshold number of calls has been made. False otherwise.
meerkat_hermes.util.log_message(messageID, details)

Logs that a message has been sent in the relavent dynamodb table.

Parameters:
  • messageID (str) – Required. The unique message ID to be logged (Str) Will fail if the messageID already exists.
  • details (dict) – Required. A dictionary containing any further details you wish to store. Typically: destinations, message, time and medium and optionally topics.
Returns:

The Amazon DynamoDB response.

meerkat_hermes.util.notify(args)

Notify the developers of some change in the system. Notifications are automatically sent to slack. These messages are not subject to the rate limiting that normal published messages are subject to.

Parameters:
  • message (str) – Required. The e-mail message.
  • subject (str) – Optional. Defaults to “Meerkat Notification”.
  • medium ([str]) – Optional. A list of the following mediums: ‘email’, ‘sms’, ‘slack’. Defaults to [‘slack’].
  • sms-message (str) – Optional. The sms version of the message. Defaults to the same as ‘message’
  • html-message (str) – Optional. The html version of the message. Defaults to the same as ‘message’
Returns:

The amazon SES response.

meerkat_hermes.util.publish(args)

Publishes a message to a given topic set. All subscribers with subscriptions to any of those topics are to receive the message.

Arguments are passed in the request data.

Parameters:args (dictionary) – Should contiain the following key/value pairs: id (str): Required. If another message with the same ID has been logged, this one won’t send. Returns a 400 Bad Request error if this is the case. message (str): Required. The message. topics ([str]): Required. The topics the message fits into (determines destination address/es). Accepts array of multiple topics. medium ([str]): The medium by which to publish the message (‘email’, ‘sms’, etc…) Defaults to email. Accepts array of multiple mediums. sms-message (str): The sms version of the message. Defaults to the same as ‘message’ html-message (str): The html version of the message. Defaults to the same as ‘message’ subject (str): The e-mail subject. Defaults to “”. from (str): The address from which to send the message. Deafults to an emro address stored in the config.
Returns:An array of amazon SES and nexmo responses for each message sent.
meerkat_hermes.util.replace_keywords(message, subscriber)
meerkat_hermes.util.send_email(destination, subject, message, html, sender)

Sends an email using Amazon SES.

Parameters:
  • destination ([str]) – Required. The email address to send to.
  • subject (str) – Required. The email subject.
  • message (str) – Required. The message to be sent.
  • html (str) – The html version of the message to be sent. Defaults to the same as ‘message’.
  • sender (str) – The sender’s address. Must be an AWS SES verified email address. Defaults to the config file SENDER value.
Returns:

The Amazon SES response. If email fails, returns a response look-a-like object that contains the failiure error message.

meerkat_hermes.util.send_gcm(destination, message)

Sends a notification to a tablet running the Collect app using a GCM subscription id

Parameters:
  • destination ([str]) – Required. The GCM subscriber ID or topic to send
  • message (str) – Required. The message to be sent.
Returns:

The Google Cloud Messaging server response.

meerkat_hermes.util.send_sms(destination, message)

Sends an sms message using AWS SNS.

Parameters:
  • destination (str) – Required. The sms number to send to.
  • message (str) – Required. The message to be sent.
Returns:

The AWS response.

meerkat_hermes.util.slack(channel, message, subject='')

Sends a notification to meerkat slack server. Channel is ‘#deploy’ only if in live deployment, otherwise sent privately to the developer via slackbot.

Parameters:
  • channel (str) – Required. The channel or username to which the message
  • be posted. (should) –
  • message (str) – Required. The message to post to slack.
  • subject (str) – Optional. Placed in bold and seperated by a pipe.

return “sent”

meerkat_hermes.util.subscribe(first_name, last_name, email, country, topics, sms='', slack='', verified=False)

Subscribes a user. Factored out of the resources so it can be called easily from python code.

Parameters:
  • first_name (str) – Required. The subscriber’s first name.
  • last_name (str) – Required. The subscriber’s last name.
  • email (str) – Required. The subscriber’s email address.
  • country (str) – Required. The country that the subscriber has signed up to.
  • sms (str) – The subscribers phone number for sms.
  • slack (str) – The slack username or channel.
  • topics ([str]) – Required. The ID’s for the topics to which the subscriber wishes to subscribe.
  • verified (bool) – Are their contact details verified? Defaults to False.