-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlackWrapper.py
60 lines (53 loc) · 1.8 KB
/
SlackWrapper.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
52
53
54
55
56
57
58
59
60
import sys
from slack_sdk import WebClient
import json
class SlackWrapper:
def __init__(self, api_key):
self.client = WebClient(token=api_key)
self.members = {}
for member in self.client.users_list()["members"]:
try:
self.members[member["profile"]["email"]] = member["id"]
except:
pass
def send_message(self, first_name, last_name, block):
try:
print("first name")
self.client.chat_postMessage(
channel=f"@{self.members[first_name+' '+last_name]}", blocks=block
)
return None
except:
print("firstinit_lastname")
print(f"@{first_name[0]}{last_name}")
self.client.chat_postMessage(
channel=f"@{self.members[first_name[0]+last_name]}",
blocks=block,
)
return None
def send_verification_message(self, first_name, last_name, verification_number):
verification_block = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": (
f"*FalconTrack Code*: {verification_number}"
),
},
}
]
print(first_name, last_name, verification_number)
self.send_message(first_name, last_name, verification_block)
def send_generic_message(self, first_name, last_name, message):
generic_text_block = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": (message),
},
},
{"type": "divider"},
]
self.send_message(first_name, last_name, generic_text_block)