-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCP-Cloud-Function_main.py
51 lines (47 loc) · 1.41 KB
/
GCP-Cloud-Function_main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
import json
import os
SLACK_TOKEN = os.environ['SLACK_TOKEN']
SLACK_CHANNEL = '#viz-of-the-day'
votd_url = "https://public.tableau.com/s/api/votd"
response = requests.get(votd_url).json()
description = response["nodes"][0]["node"]["description"]
title = response["nodes"][0]["node"]["title"]
image_src = response["nodes"][0]["node"]["field_image"]["src"]
url_path = response["nodes"][0]["node"]["path"]
blocks = [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": '*' + title + '*\n ' + description
}
},
{
"type": "image",
"image_url": image_src,
"alt_text": "inspiration"
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "See the viz",
},
"url": 'https://public.tableau.com' + url_path + '?referrer=slack'
}
]
}
]
def post_votd_to_slack(request):
return requests.post('https://slack.com/api/chat.postMessage', {
'token': SLACK_TOKEN,
'channel': SLACK_CHANNEL,
'blocks': json.dumps(blocks) if blocks else None,
'text': title
}).json()