-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack.py
More file actions
38 lines (34 loc) · 958 Bytes
/
slack.py
File metadata and controls
38 lines (34 loc) · 958 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
35
36
37
38
# import libraries
import os
import links
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from dotenv import load_dotenv
# load in dotenv data
load_dotenv()
cat_url = links.get_random_cat()
# grab data from dotenv and assign to variables
slack_token = os.environ.get("SLACK_BOT_TOKEN")
client = WebClient(token=slack_token)
# print text and cat image link to channel
try:
response = client.chat_postMessage(
channel=os.environ.get("SLACK_CHANNEL_ID"),
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Here is the daily cat!*"
},
},
{
"image_url": f"{cat_url}",
"type": "image",
"alt_text": "Daily cat image"
}
]
)
except SlackApiError as e:
# raise error if needed
raise e