Skip to content

Commit d704757

Browse files
committed
Refactor mentor request form to use slack "blocks"
1 parent 249b847 commit d704757

6 files changed

Lines changed: 300 additions & 122 deletions

File tree

pybot/endpoints/slack/actions/__init__.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from sirbot.plugins.slack import SlackPlugin
2+
13
from .general_actions import claimed, reset_claim
24
from .help_ticket import open_ticket, ticket_status
35
from .mentor_request import (
@@ -23,7 +25,7 @@
2325
from .report_message import open_report_dialog, send_report
2426

2527

26-
def create_endpoints(plugin):
28+
def create_endpoints(plugin: SlackPlugin):
2729
# simple actions that can be used in multiple scenarios
2830
plugin.on_action("claimed", claimed, name="claimed", wait=False)
2931
plugin.on_action("claimed", reset_claim, name="reset_claim", wait=False)
@@ -44,31 +46,27 @@ def create_endpoints(plugin):
4446
plugin.on_action("ticket_status", ticket_status, wait=False)
4547

4648
# mentorship related interactive actions
47-
plugin.on_action(
48-
"mentor_request_submit", mentor_request_submit, name="submit", wait=False
49-
)
50-
plugin.on_action(
51-
"mentor_request_submit", cancel_mentor_request, name="cancel", wait=False
52-
)
53-
54-
plugin.on_action("mentor_request_update", add_skillset, name="skillset", wait=False)
55-
plugin.on_action(
56-
"mentor_request_update", clear_skillsets, name="clearSkills", wait=False
57-
)
58-
plugin.on_action(
59-
"mentor_request_update", clear_mentor, name="clearMentor", wait=False
49+
plugin.on_block(
50+
"mentor_service",
51+
set_requested_service,
52+
wait=False,
53+
action_id="mentor_service_select",
6054
)
61-
plugin.on_action(
62-
"mentor_request_update", open_details_dialog, name="addDetails", wait=False
55+
plugin.on_block("skillset", add_skillset, action_id="skillset_select", wait=False)
56+
plugin.on_block(
57+
"clear_skillsets", clear_skillsets, action_id="clear_skillsets_btn", wait=False
6358
)
64-
plugin.on_action(
65-
"mentor_request_update", set_requested_mentor, name="mentor", wait=False
59+
plugin.on_block("mentor", set_requested_mentor, action_id="mentor_select", wait=False)
60+
plugin.on_block("comments", open_details_dialog, action_id="comments_btn", wait=False)
61+
plugin.on_block("mentor_details_submit", mentor_details_submit, wait=False)
62+
plugin.on_block("affiliation", set_group, action_id="affiliation_select", wait=False)
63+
plugin.on_block(
64+
"submission", mentor_request_submit, action_id="submit_btn", wait=False
6665
)
67-
plugin.on_action(
68-
"mentor_request_update", set_requested_service, name="service", wait=False
66+
plugin.on_block(
67+
"submission", cancel_mentor_request, action_id="cancel_btn", wait=False
6968
)
70-
plugin.on_action("mentor_request_update", set_group, name="group", wait=False)
7169

72-
plugin.on_action("mentor_details_submit", mentor_details_submit, wait=False)
70+
# mentorship claims
7371
plugin.on_action("claim_mentee", claim_mentee, wait=False)
7472
plugin.on_action("reset_claim_mentee", claim_mentee, wait=False)

pybot/endpoints/slack/actions/mentor_request.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async def mentor_request_submit(action: Action, app: SirBot):
2020
request = MentorRequest(action)
2121

2222
if not request.validate_self():
23+
request.add_errors()
2324
await request.update_message(slack)
2425
return
2526

@@ -36,8 +37,9 @@ async def mentor_request_submit(action: Action, app: SirBot):
3637

3738

3839
async def cancel_mentor_request(action: Action, app: SirBot):
39-
response = {"ts": action["message_ts"], "channel": action["channel"]["id"]}
40-
await app.plugins["slack"].api.query(methods.CHAT_DELETE, response)
40+
slack = app.plugins["slack"].api
41+
request = MentorRequest(action)
42+
await request.delete_self(slack)
4143

4244

4345
async def mentor_details_submit(action: Action, app: SirBot):
@@ -50,7 +52,7 @@ async def mentor_details_submit(action: Action, app: SirBot):
5052
search = {"inclusive": True, "channel": channel, "oldest": ts, "latest": ts}
5153

5254
history = await slack.query(methods.IM_HISTORY, search)
53-
request["original_message"] = history["messages"][0]
55+
request["message"] = history["messages"][0]
5456
request.details = action["submission"]["details"]
5557

5658
await request.update_message(slack)
@@ -80,9 +82,8 @@ async def clear_mentor(action: Action, app: SirBot):
8082

8183

8284
async def set_group(action: Action, app: SirBot):
83-
group = MentorRequest.selected_option(action)
8485
request = MentorRequest(action)
85-
request.certify_group = group
86+
request.affiliation = request.selected_option
8687

8788
slack = app.plugins["slack"].api
8889
await request.update_message(slack)
@@ -91,26 +92,24 @@ async def set_group(action: Action, app: SirBot):
9192
async def set_requested_service(action: Action, app: SirBot):
9293
request = MentorRequest(action)
9394

94-
service = MentorRequest.selected_option(action)
95-
request.service = service
95+
request.service = request.selected_option
9696

9797
slack = app.plugins["slack"].api
9898
await request.update_message(slack)
9999

100100

101101
async def set_requested_mentor(action: Action, app: SirBot):
102-
mentor = MentorRequest.selected_option(action)
103102
request = MentorRequest(action)
104-
request.mentor = mentor
103+
request.mentor = request.selected_option
105104

106105
slack = app.plugins["slack"].api
107106
await request.update_message(slack)
108107

109108

110109
async def add_skillset(action: Action, app: SirBot):
111-
selected_skill = MentorRequest.selected_option(action)
112110
request = MentorRequest(action)
113-
request.add_skillset(selected_skill)
111+
selected_skill = request.selected_option
112+
request.add_skillset(selected_skill["value"])
114113

115114
slack = app.plugins["slack"].api
116115
await request.update_message(slack)

pybot/endpoints/slack/commands.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pybot.endpoints.slack.message_templates.commands import (
88
mentor_request_attachments,
99
ticket_dialog,
10-
)
10+
new_mentor_request_attachment)
1111
from pybot.endpoints.slack.utils import MODERATOR_CHANNEL
1212
from pybot.endpoints.slack.utils.action_messages import not_claimed_attachment
1313
from pybot.endpoints.slack.utils.command_utils import get_slash_repeat_messages
@@ -35,15 +35,14 @@ async def slash_mentor(command: Command, app: SirBot):
3535
mentors = await airtable.get_all_records("Mentors", "Full Name")
3636
skillsets = await airtable.get_all_records("Skillsets", "Name")
3737

38-
dialog = mentor_request_attachments(services, mentors, skillsets)
38+
blocks = new_mentor_request_attachment(services, mentors, skillsets)
3939

4040
response = {
41-
"attachments": dialog,
41+
"text": "Mentor Request Form",
42+
"blocks": blocks,
4243
"channel": command["user_id"],
4344
"as_user": True,
44-
"text": "Thank you for signing up for a 30 minute mentoring session. Please fill out the form below:",
4545
}
46-
4746
await app.plugins["slack"].api.query(methods.CHAT_POST_MESSAGE, response)
4847

4948

pybot/endpoints/slack/message_templates/commands.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,129 @@ def mentor_request_attachments(services, mentors, skillsets):
129129
],
130130
},
131131
]
132+
133+
134+
def new_mentor_request_attachment(services, mentors, skillsets):
135+
return [
136+
{
137+
"type": "section",
138+
"text": {"type": "mrkdwn", "text": "👨‍🏫 Mentor Request Form 👩‍🏫"},
139+
},
140+
{"type": "divider"},
141+
{
142+
"type": "section",
143+
"block_id": "mentor_service",
144+
"text": {"type": "mrkdwn", "text": "*Service (Required)*"},
145+
"accessory": {
146+
"action_id": "mentor_service_select",
147+
"type": "static_select",
148+
"placeholder": {"type": "plain_text", "text": "Service"},
149+
"options": [
150+
{"text": {"type": "plain_text", "text": service}, "value": service}
151+
for service in services
152+
],
153+
},
154+
},
155+
{
156+
"type": "section",
157+
"block_id": "skillset",
158+
"text": {"type": "mrkdwn", "text": "*Mentor Skillsets*\n"},
159+
"accessory": {
160+
"type": "static_select",
161+
"action_id": "skillset_select",
162+
"placeholder": {"type": "plain_text", "text": "Skillset"},
163+
"options": [
164+
{
165+
"text": {"type": "plain_text", "text": skillset},
166+
"value": skillset,
167+
}
168+
for skillset in skillsets
169+
],
170+
},
171+
},
172+
{
173+
"type": "section",
174+
"block_id": "clear_skillsets",
175+
"text": {"type": "mrkdwn", "text": "*Selected Skillsets*"},
176+
"accessory": {
177+
"type": "button",
178+
"action_id": "clear_skillsets_btn",
179+
"text": {"type": "plain_text", "text": "Reset Skillsets"},
180+
"value": "reset_skillsets",
181+
},
182+
},
183+
{
184+
"type": "section",
185+
"block_id": "mentor",
186+
"text": {"type": "mrkdwn", "text": "*Select a specific mentor*"},
187+
"accessory": {
188+
"type": "static_select",
189+
"action_id": "mentor_select",
190+
"placeholder": {"type": "plain_text", "text": "Mentor"},
191+
"options": [
192+
{"text": {"type": "plain_text", "text": mentor}, "value": mentor}
193+
for mentor in mentors
194+
],
195+
},
196+
},
197+
{
198+
"type": "section",
199+
"block_id": "comments",
200+
"text": {"type": "mrkdwn", "text": "*Add additional comments*"},
201+
"accessory": {
202+
"type": "button",
203+
"action_id": "comments_btn",
204+
"text": {"type": "plain_text", "text": "Add details"},
205+
"value": "addDetails",
206+
},
207+
"fields": [{"type": "plain_text", "text": " "}],
208+
},
209+
{
210+
"type": "section",
211+
"block_id": "affiliation",
212+
"text": {
213+
"type": "mrkdwn",
214+
"text": "*I certify that I am a member of the following group (Required)*",
215+
},
216+
"accessory": {
217+
"type": "static_select",
218+
"action_id": "affiliation_select",
219+
"placeholder": {"type": "plain_text", "text": "Military affiliation"},
220+
"options": [
221+
{
222+
"text": {"type": "plain_text", "text": "Veteran"},
223+
"value": "Veteran",
224+
},
225+
{
226+
"text": {"type": "plain_text", "text": "Active Duty"},
227+
"value": "Active Duty",
228+
},
229+
{
230+
"text": {"type": "plain_text", "text": "Military Spouse"},
231+
"value": "Military Spouse",
232+
},
233+
],
234+
},
235+
},
236+
{"type": "divider"},
237+
{
238+
"type": "actions",
239+
"block_id": "submission",
240+
"elements": [
241+
{
242+
"type": "button",
243+
"action_id": "submit_btn",
244+
"text": {"type": "plain_text", "text": "Submit"},
245+
"style": "primary",
246+
"value": "submit",
247+
},
248+
{
249+
"type": "button",
250+
"action_id": "cancel_btn",
251+
"text": {"type": "plain_text", "text": "Cancel"},
252+
"style": "danger",
253+
"value": "cancel",
254+
},
255+
],
256+
},
257+
]

0 commit comments

Comments
 (0)