Skip to content

Commit c0436d7

Browse files
authored
feat: Allow custom attachement (#123)
1 parent f19cea1 commit c0436d7

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ terraform.rc
3131
# Lambda directories
3232
builds/
3333
__pycache__/
34+
functions/pytest.ini

functions/notify_slack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def notify_slack(subject, message, region):
9191
notification = cloudwatch_notification(message, region)
9292
payload['text'] = "AWS CloudWatch notification - " + message["AlarmName"]
9393
payload['attachments'].append(notification)
94+
elif "attachments" in message or "text" in message:
95+
payload = {**payload, **message}
9496
else:
9597
payload['text'] = "AWS notification"
9698
payload['attachments'].append(default_notification(subject, message))

functions/notify_slack_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,44 @@
9797
"NewStateValue": "ALARM",
9898
}
9999
),
100+
(
101+
{
102+
"attachments": [
103+
{
104+
"mrkdwn_in": ["text"],
105+
"color": "#36a64f",
106+
"pretext": "Optional pre-text that appears above the attachment block",
107+
"author_name": "author_name",
108+
"author_link": "http://flickr.com/bobby/",
109+
"author_icon": "https://placeimg.com/16/16/people",
110+
"title": "title",
111+
"title_link": "https://api.slack.com/",
112+
"text": "Optional `text` that appears within the attachment",
113+
"fields": [
114+
{
115+
"title": "A field's title",
116+
"value": "This field's value",
117+
"short": False
118+
},
119+
{
120+
"title": "A short field's title",
121+
"value": "A short field's value",
122+
"short": True
123+
},
124+
{
125+
"title": "A second short field's title",
126+
"value": "A second short field's value",
127+
"short": True
128+
}
129+
],
130+
"thumb_url": "http://placekitten.com/g/200/200",
131+
"footer": "footer",
132+
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
133+
"ts": 123456789
134+
}
135+
]
136+
}
137+
),
100138
(
101139
{
102140
"Records": [

functions/pytest.ini

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)