-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
263 lines (245 loc) · 10.3 KB
/
main.py
File metadata and controls
263 lines (245 loc) · 10.3 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import logging
import os
from flask import Request
import functions_framework
# from fastapi import FastAPI, Request
from slack_bolt import App
from slack_bolt.adapter.google_cloud_functions import SlackRequestHandler
# from slack_bolt.adapter.fastapi import SlackRequestHandler
# from slack_bolt.adapter.socket_mode import SocketModeHandler
app = App(token=os.environ.get("SLACK_BOT_TOKEN"), signing_secret=os.environ.get("SLACK_SIGNING_SECRET"))
logging.basicConfig(level=logging.DEBUG)
@app.message("hello")
def message_hello(message, say):
say(
blocks=[
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Hey there <@{message['user']}>!"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "Click Me"},
"action_id": "button_click",
},
}
],
text=f"Hey there <@{message['user']}>!",
)
@app.action("button_click")
def action_button_click(body, ack, say):
ack()
say(f"<@{body['user']['id']}> clicked the button")
@app.command("/summary")
def command_summary(body, ack, say, logger, client, command):
ack()
logger.debug(body)
client.views_open(
# Pass a valid trigger_id within 3 seconds of receiving it
trigger_id=body["trigger_id"],
# View payload
view={
"type": "modal",
# View identifier
"callback_id": "summary-modal",
"private_metadata": command["channel_id"],
"submit": {"type": "plain_text", "text": "Submit", "emoji": True},
"close": {"type": "plain_text", "text": "Cancel", "emoji": True},
"title": {"type": "plain_text", "text": "Deployment Summary", "emoji": True},
"blocks": [
{
"type": "input",
"block_id": "athena_updated_text_input",
"element": {
"type": "plain_text_input",
"action_id": "athena_updated_text_input-action",
"placeholder": {"type": "plain_text", "text": "KYCCentral Dev"},
},
"label": {"type": "plain_text", "text": "Athena updated", "emoji": True},
},
{
"type": "input",
"block_id": "from_version_text_input",
"element": {
"type": "plain_text_input",
"action_id": "from_version_text_input-action",
"placeholder": {
"type": "plain_text",
"text": "vX.X.X",
},
},
"label": {"type": "plain_text", "text": "From version", "emoji": True},
},
{
"type": "input",
"block_id": "to_version_text_input",
"element": {
"type": "plain_text_input",
"action_id": "to_version_text_input-action",
"placeholder": {
"type": "plain_text",
"text": "vX.X.X",
},
},
"label": {"type": "plain_text", "text": "To version", "emoji": True},
},
{"type": "divider"},
{
"type": "input",
"block_id": "migrations_text_input",
"element": {
"type": "rich_text_input",
"action_id": "migrations_text_input-action",
"initial_value": {
"type": "rich_text",
"elements": [
{"type": "rich_text_section", "elements": [{"type": "text", "text": "None"}]}
],
},
},
"label": {"type": "plain_text", "text": "Migrations", "emoji": True},
},
{
"type": "input",
"block_id": "pip_installs_text_input",
"element": {
"type": "rich_text_input",
"action_id": "pip_installs_text_input-action",
"initial_value": {
"type": "rich_text",
"elements": [
{"type": "rich_text_section", "elements": [{"type": "text", "text": "None"}]}
],
},
},
"label": {"type": "plain_text", "text": "Pip installs", "emoji": True},
},
{
"type": "input",
"block_id": "other_notes_text_input",
"element": {
"type": "rich_text_input",
"action_id": "other_notes_text_input-action",
"initial_value": {
"type": "rich_text",
"elements": [
{"type": "rich_text_section", "elements": [{"type": "text", "text": "None"}]}
],
},
},
"label": {"type": "plain_text", "text": "Other notes", "emoji": True},
},
{"type": "divider"},
{
"type": "input",
"block_id": "release_note_file_input",
"label": {"type": "plain_text", "text": "Upload Release Notes"},
"element": {
"type": "file_input",
"action_id": "release_note_file_input_action",
"filetypes": ["pdf"],
"max_files": 1,
},
},
{
"type": "input",
"block_id": "checklist_note_file_input",
"label": {"type": "plain_text", "text": "Upload Deployment Checklist"},
"element": {
"type": "file_input",
"action_id": "checklist_note_file_input_action",
"filetypes": ["pdf"],
"max_files": 1,
},
},
],
},
)
@app.view("summary-modal")
def handle_summary_submission(ack, body, logger, client):
ack()
logger.debug(body)
channel_id = body["view"]["private_metadata"]
state_values = body["view"]["state"]["values"]
athena_updated = state_values["athena_updated_text_input"]["athena_updated_text_input-action"]["value"]
from_ver = state_values["from_version_text_input"]["from_version_text_input-action"]["value"]
to_ver = state_values["to_version_text_input"]["to_version_text_input-action"]["value"]
migrations = state_values["migrations_text_input"]["migrations_text_input-action"]["rich_text_value"]
pip_install = state_values["pip_installs_text_input"]["pip_installs_text_input-action"]["rich_text_value"]
other_notes = state_values["other_notes_text_input"]["other_notes_text_input-action"]["rich_text_value"]
release_notes = state_values["release_note_file_input"]["release_note_file_input_action"]["files"][0]
checklist = state_values["checklist_note_file_input"]["checklist_note_file_input_action"]["files"][0]
logger.debug(f"\n{from_ver}\n {to_ver}\n {migrations}")
# res = requests.get(
# release_notes["url_private"],
# headers={"Authorization": f"Bearer {os.environ.get('SLACK_BOT_TOKEN')}"},
# )
# file_bytes = res.content
#
# client.files_upload_v2(
# channel=channel_id,
# title=release_notes["name"],
# filename=release_notes["name"],
# file=file_bytes,
# )
client.chat_postMessage(
channel=channel_id,
text="Athena Deployment",
blocks=[
{
"type": "header",
"text": {"type": "plain_text", "text": ":owl: Athena Deployment :owl:"},
},
{
"type": "context",
"elements": [{"text": f"*{athena_updated}* | {from_ver} to {to_ver}", "type": "mrkdwn"}],
},
{"type": "divider"},
{"type": "section", "text": {"type": "mrkdwn", "text": "*Migrations:*"}},
migrations,
{"type": "section", "text": {"type": "mrkdwn", "text": "*Python packages installed:*"}},
pip_install,
{"type": "section", "text": {"type": "mrkdwn", "text": "*Other notes:*"}},
other_notes,
{"type": "divider"},
],
attachments=[
{
"color": "#c80d0d",
"blocks": [
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Release notes:*"},
{
"type": "mrkdwn",
"text": f"<{release_notes['permalink']}|{release_notes['name']}>",
},
],
},
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Deployment checklist:*"},
{
"type": "mrkdwn",
"text": f"<{checklist['permalink']}|{checklist['name']}>",
},
],
},
],
}
],
)
# fastapi_app = FastAPI()
handler = SlackRequestHandler(app)
# @fastapi_app.post("/summary/events")
# async def slack_deployment_summary(req: Request):
# return await handler.handle(req)
@functions_framework.http
def slack_deployment_summary(req: Request):
return handler.handle(req)
# if __name__ == "__main__":
# import uvicorn
# uvicorn.run(fastapi_app, host="0.0.0.0", port=int(os.environ.get("PORT", 3000)))
# app.start(port=int(os.environ.get("PORT", 3000)))
# SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()