-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.py
30 lines (26 loc) · 960 Bytes
/
notification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import boto3
import json
class SnsNotification:
def __init__(self, region, sns_arn, channel, username='lambda', icon_url=None):
self.sns = boto3.client('sns', region_name=region)
self.sns_arn = sns_arn
self.payload = {
"channel": channel,
"username": username
}
if icon_url:
self.payload['icon_url'] = icon_url
def send(self, message, channel=None, username=None, icon_url=None):
self.payload['text'] = message
if channel:
self.payload['channel'] = channel
if username:
self.payload['username'] = username
if icon_url:
self.payload['icon_url'] = icon_url
response = self.sns.publish(
TopicArn=self.sns_arn,
Message=json.dumps({"default": json.dumps(self.payload)}),
MessageStructure='json'
)
print(str(response))