-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
34 lines (27 loc) · 840 Bytes
/
lambda_function.py
File metadata and controls
34 lines (27 loc) · 840 Bytes
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
31
32
33
34
import json
import os
import urllib.request
def lambda_handler(event, context):
slack_url = os.environ.get("SLACK_URL")
try:
body = json.loads(event['body'])
issue_url = body['issue']['html_url']
message = {
"text": f"Issue created: {issue_url}"
}
req = urllib.request.Request(
slack_url,
data=json.dumps(message).encode("utf-8"),
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req) as res:
print(res.read().decode("utf-8"))
return {
"statusCode": 200,
"body": json.dumps({"message": "Posted to Slack"})
}
except Exception as e:
return {
"statusCode": 500,
"body": json.dumps({"error": str(e)})
}