Skip to content

Instantly share code, notes, and snippets.

@bpodgursky
Created January 27, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpodgursky/81aab9de6be9b63f5f11193c6ccb03b8 to your computer and use it in GitHub Desktop.
Save bpodgursky/81aab9de6be9b63f5f11193c6ccb03b8 to your computer and use it in GitHub Desktop.
CCPA Slack message generator
from cloudwright_base import *
def message_template(name, email, license_link, value):
return """
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*CCPA Data Request*\n*Name*: """+name+"""\n *Email*: """+email+""""
},
"accessory": {
"type": "image",
"image_url": \""""+license_link+"""\",
"alt_text": "alt text for image"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Approve or reject this request"
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Approve",
"emoji": true
},
"value": \""""+value+"""\"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Reject",
"emoji": true
},
"value": \""""+value+"""\"
}
]
}
]
"""
from helpers import message_template
# This application takes external CCPA data export requests and formats them
# as Slack messages. Approval or disapproval message will be sent from slack
# to a separate application which generates the full report
# We'll accept from our CCPA compliance solution three fields:
# - the name of the data requester
# - the email address of the requester
# - a link to a driver's license photo, to validate identity
name = CloudWright.inputs.get('ccpa_name')
email = CloudWright.inputs.get('ccpa_email')
license_link = CloudWright.inputs.get('ccpa_license_link')
# We'll use the Slack module to ask for approval or rejection
slack = CloudWright.get_module("slack")
# The export generator will use this data to generate the report
value = base64.b64encode(json.dumps({
'name': name,
'email': email,
'license_link': license_link
}).encode()).decode()
# We'll format our message using fancy Slack interaction boxes, and send
# the request to a particular channel
msg = message_template(name, email, license_link, value)
slack.chat_postMessage(channel='bots', blocks=msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment