Skip to content

Commit c117c32

Browse files
committed
Merge branch 'staging'
# Conflicts: # pybot/endpoints/slack/actions.py # pybot/endpoints/slack/utils/action_messages.py
2 parents 80cb10f + b7ef16a commit c117c32

21 files changed

Lines changed: 1090 additions & 535 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dist/
1919
downloads/
2020
eggs/
2121
.eggs/
22-
lib/
2322
lib64/
2423
parts/
2524
sdist/

Pipfile.lock

Lines changed: 227 additions & 223 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pybot/__main__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@
1414
from pybot.endpoints.slack.utils import PORT, HOST
1515
from pybot.endpoints.slack.utils import slack_configs
1616

17-
VERSION = "0.1.0"
17+
VERSION = "0.2.0"
1818
logger = logging.getLogger(__name__)
1919

20-
slack_configs = {
21-
'token': os.environ.get('BOT_OATH_TOKEN'),
22-
'verify': os.environ.get('VERIFICATION_TOKEN'),
23-
'bot_id': os.environ.get('SLACK_BOT_ID'),
24-
'bot_user_id': os.environ.get('SLACK_BOT_ID'),
25-
}
26-
2720

2821
def make_sentry_logger():
2922
client = raven.Client(

pybot/endpoints/airtable/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def mentor_request(request: dict, app: SirBot) -> None:
2525
id_fallback = f" [couldn't find user - email provided: {request['email']} ]"
2626
slack_id = await _slack_user_id_from_email(request['email'], slack, fallback=id_fallback)
2727

28-
futures = [app.plugins['airtable'].api.translate_service_id(request['service']),
28+
futures = [airtable.get_name_from_record_id('Services', request['service']),
2929
_get_requested_mentor(request.get('requested_mentor'), slack, airtable),
3030
_get_matching_skillset_mentors(request.get('skillsets'), slack, airtable)]
3131

pybot/endpoints/airtable/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from typing import List, Optional, Tuple
32

43
from sirbot import SirBot
@@ -10,12 +9,13 @@
109
from pybot.endpoints.slack.utils import MENTOR_CHANNEL
1110
from .message_templates.messages import claim_mentee_attachment, mentor_request_text
1211

12+
1313
async def _get_requested_mentor(requested_mentor: Optional[str], slack: SlackAPI,
1414
airtable: AirtableAPI) -> Optional[str]:
1515
try:
1616
if not requested_mentor:
1717
return None
18-
mentor = await airtable.get_mentor_from_record_id(requested_mentor)
18+
mentor = await airtable.get_row_from_record_id('Mentors', requested_mentor)
1919
email = mentor['Email']
2020
slack_user_id = await _slack_user_id_from_email(email, slack)
2121
return f" Requested mentor: <@{slack_user_id}>"

pybot/endpoints/slack/actions.py

Lines changed: 0 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -1,222 +0,0 @@
1-
import logging
2-
from pprint import pprint
3-
4-
from sirbot import SirBot
5-
from slack import methods
6-
from slack.actions import Action
7-
8-
from pybot.endpoints.slack.utils.action_messages import *
9-
from pybot.endpoints.slack.utils import COMMUNITY_CHANNEL, TICKET_CHANNEL
10-
11-
logger = logging.getLogger(__name__)
12-
13-
14-
def create_endpoints(plugin):
15-
plugin.on_action("resource_buttons", resource_buttons, wait=False)
16-
plugin.on_action("greeted", member_greeted, name='greeted', wait=False)
17-
plugin.on_action("greeted", reset_greet, name='reset_greet', wait=False)
18-
plugin.on_action("suggestion", open_suggestion, wait=False)
19-
plugin.on_action("suggestion_modal", post_suggestion, wait=False)
20-
plugin.on_action("claim_mentee", claim_mentee, wait=False)
21-
plugin.on_action("reset_claim_mentee", claim_mentee, wait=False)
22-
plugin.on_action("claimed", claimed, name='claimed', wait=False)
23-
plugin.on_action("claimed", reset_claim, name='reset_claim', wait=False)
24-
plugin.on_action("report_message", open_report_dialog, wait=False)
25-
plugin.on_action("report_dialog", send_report, wait=False)
26-
plugin.on_action("open_ticket", open_ticket, wait=False)
27-
plugin.on_action("ticket_status", ticket_status, wait=False)
28-
29-
30-
async def ticket_status(action: Action, app: SirBot):
31-
"""
32-
Updates the ticket status dropdown. (I don't know why we need to manually
33-
update the message for this..)
34-
"""
35-
slack = app.plugins["slack"].api
36-
37-
response, selected_option = updated_ticket_status(action)
38-
update_message = update_ticket_message(action, selected_option['text'])
39-
40-
await slack.query(methods.CHAT_UPDATE, response)
41-
await slack.query(methods.CHAT_POST_MESSAGE, update_message)
42-
43-
44-
async def open_ticket(action: Action, app: SirBot):
45-
"""
46-
Called when a user submits the ticket dialog. Parses the submission and posts
47-
the new ticket details to the required channel
48-
"""
49-
attachments = ticket_attachments(action)
50-
response = {
51-
'channel': TICKET_CHANNEL,
52-
'attachments': attachments,
53-
'text': 'New Ticket Submission',
54-
}
55-
56-
await app["plugins"]["slack"].api.query(methods.CHAT_POST_MESSAGE, response)
57-
58-
59-
async def send_report(action: Action, app: SirBot):
60-
"""
61-
Called when a user submits the report dialog. Pulls the original message
62-
info from the state and posts the details to the moderators channel
63-
"""
64-
slack_id = action['user']['id']
65-
details = action['submission']['details']
66-
message_details = json.loads(action.action['state'])
67-
68-
response = build_report_message(slack_id, details, message_details)
69-
70-
await app["plugins"]["slack"].api.query(methods.CHAT_POST_MESSAGE, response)
71-
72-
73-
async def open_report_dialog(action: Action, app: SirBot):
74-
"""
75-
Opens the message reporting dialog for the user to provide details.
76-
77-
Adds the message that they're reporting to the dialog's hidden state
78-
to be pulled out when submitted.
79-
"""
80-
trigger_id = action['trigger_id']
81-
response = {
82-
'trigger_id': trigger_id,
83-
'dialog': report_dialog(action),
84-
}
85-
await app.plugins["slack"].api.query(methods.DIALOG_OPEN, response)
86-
87-
88-
async def resource_buttons(action: Action, app: SirBot):
89-
"""
90-
Edits the resource message with the clicked on resource
91-
"""
92-
name = action['actions'][0]['name']
93-
94-
response = base_response(action)
95-
response['text'] = HELP_MENU_RESPONSES[name]
96-
97-
await app.plugins["slack"].api.query(methods.CHAT_UPDATE, response)
98-
99-
100-
async def open_suggestion(action: Action, app: SirBot):
101-
"""
102-
Opens the suggestion modal when the user clicks on the "Are we missing something?" button
103-
"""
104-
trigger_id = action['trigger_id']
105-
response = {
106-
'trigger_id': trigger_id,
107-
'dialog': suggestion_dialog(trigger_id)
108-
}
109-
110-
await app.plugins["slack"].api.query(methods.DIALOG_OPEN, response)
111-
112-
113-
async def post_suggestion(action: Action, app: SirBot):
114-
"""
115-
Posts a suggestion supplied by the suggestion modal to the community channel
116-
"""
117-
suggesting_user = action['user']['id']
118-
suggestion = action['submission']['suggestion']
119-
120-
response = {
121-
'text': new_suggestion_text(suggesting_user, suggestion),
122-
'channel': COMMUNITY_CHANNEL
123-
}
124-
125-
await app.plugins["slack"].api.query(methods.CHAT_POST_MESSAGE, response)
126-
127-
128-
async def member_greeted(action: Action, app: SirBot):
129-
"""
130-
Called when a community member clicks the button saying they greeted the new member
131-
"""
132-
response = base_response(action)
133-
user_id = action['user']['id']
134-
response['attachments'] = greeted_attachment(user_id)
135-
136-
await app.plugins["slack"].api.query(methods.CHAT_UPDATE, response)
137-
138-
139-
async def reset_greet(action: Action, app: SirBot):
140-
"""
141-
Resets the claim greet button back to its initial state and appends the user that hit reset and the time
142-
"""
143-
response = base_response(action)
144-
response['attachments'] = not_greeted_attachment()
145-
response['attachments'][0]['text'] = reset_greet_message(action['user']['id'])
146-
147-
await app.plugins["slack"].api.query(methods.CHAT_UPDATE, response)
148-
149-
150-
async def claimed(action: Action, app: SirBot):
151-
"""
152-
Provides basic "claim" functionality for use-cases that don't have any other effects.
153-
154-
Simply updates the button to allow resets and displays the user and time it was clicked.
155-
"""
156-
response = base_response(action)
157-
user_id = action['user']['id']
158-
159-
attachments = action['original_message']['attachments']
160-
161-
for index, attachment in enumerate(attachments):
162-
if 'callback_id' in attachment and attachment['callback_id'] == 'claimed':
163-
attachments[index] = claimed_attachment(user_id)
164-
response['attachments'] = attachments
165-
166-
await app.plugins['slack'].api.query(methods.CHAT_UPDATE, response)
167-
168-
169-
async def reset_claim(action: Action, app: SirBot):
170-
"""
171-
Provides basic "unclaim" functionality for use-cases that don't have any other effects.
172-
173-
Updates the button back to its initial state
174-
"""
175-
response = base_response(action)
176-
177-
attachments = action['original_message']['attachments']
178-
for index, attachment in enumerate(attachments):
179-
if 'callback_id' in attachment and attachment['callback_id'] == 'claimed':
180-
attachments[index] = not_claimed_attachment()
181-
182-
response['attachments'] = attachments
183-
await app.plugins['slack'].api.query(methods.CHAT_UPDATE, response)
184-
185-
186-
async def claim_mentee(action: Action, app: SirBot):
187-
"""
188-
Called when a mentor clicks on the button to claim a mentor request.
189-
190-
Attempts to update airtable with the new request status and updates the claim
191-
button allowing it to be reset if needed.
192-
"""
193-
try:
194-
update_airtable = True
195-
clicker_id = action['user']['id']
196-
request_record = action['actions'][0]['name']
197-
click_type = action['actions'][0]['value']
198-
199-
response = base_response(action)
200-
201-
user_info = await app.plugins['slack'].api.query(methods.USERS_INFO, dict(user=clicker_id))
202-
clicker_email = user_info['user']['profile']['email']
203-
204-
if click_type == 'mentee_claimed':
205-
mentor_id = await app.plugins['airtable'].api.mentor_id_from_slack_email(clicker_email)
206-
if mentor_id:
207-
attachment = mentee_claimed_attachment(clicker_id, request_record)
208-
else:
209-
update_airtable = False
210-
attachment = action['original_message']['attachments']
211-
attachment[0]['text'] = f":warning: <@{clicker_id}>'s slack Email not found in Mentor table. :warning:"
212-
else:
213-
mentor_id = ''
214-
attachment = mentee_unclaimed_attachment(clicker_id, request_record)
215-
216-
response['attachments'] = attachment
217-
218-
await app.plugins['slack'].api.query(methods.CHAT_UPDATE, response)
219-
if update_airtable:
220-
await app.plugins['airtable'].api.update_request(request_record, mentor_id)
221-
except Exception as ex:
222-
print(ex)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from .general_actions import claimed, reset_claim
2+
from .help_ticket import open_ticket, ticket_status
3+
from .report_message import open_report_dialog, send_report
4+
from .mentor_request import mentor_request_submit, cancel_mentor_request, add_skillset, \
5+
clear_skillsets, open_details_dialog, mentor_details_submit, claim_mentee, set_requested_mentor, set_requested_service, \
6+
set_group
7+
from .new_member import member_greeted, open_suggestion, post_suggestion, reset_greet, resource_buttons
8+
9+
10+
def create_endpoints(plugin):
11+
# simple actions that can be used in multiple scenarios
12+
plugin.on_action("claimed", claimed, name='claimed', wait=False)
13+
plugin.on_action("claimed", reset_claim, name='reset_claim', wait=False)
14+
15+
# new member interactive actions
16+
plugin.on_action("resource_buttons", resource_buttons, wait=False)
17+
plugin.on_action("greeted", member_greeted, name='greeted', wait=False)
18+
plugin.on_action("greeted", reset_greet, name='reset_greet', wait=False)
19+
plugin.on_action("suggestion", open_suggestion, wait=False)
20+
plugin.on_action("suggestion_modal", post_suggestion, wait=False)
21+
22+
# reporting related interactive actions
23+
plugin.on_action("report_message", open_report_dialog, wait=False)
24+
plugin.on_action("report_dialog", send_report, wait=False)
25+
26+
# help ticket/request interactive actions
27+
plugin.on_action("open_ticket", open_ticket, wait=False)
28+
plugin.on_action("ticket_status", ticket_status, wait=False)
29+
30+
# mentorship related interactive actions
31+
plugin.on_action("mentor_request_submit", mentor_request_submit, name='submit', wait=False)
32+
plugin.on_action("mentor_request_submit", cancel_mentor_request, name='cancel', wait=False)
33+
34+
# plugin.on_action("mentor_request_update", mentor_request_update, wait=False)
35+
plugin.on_action("mentor_request_update", add_skillset, name='skillset', wait=False)
36+
plugin.on_action("mentor_request_update", clear_skillsets, name='clearSkills', wait=False)
37+
plugin.on_action("mentor_request_update", open_details_dialog, name='addDetails', wait=False)
38+
plugin.on_action("mentor_request_update", set_requested_mentor, name='mentor', wait=False)
39+
plugin.on_action("mentor_request_update", set_requested_service, name='service', wait=False)
40+
plugin.on_action("mentor_request_update", set_group, name='group', wait=False)
41+
42+
plugin.on_action("mentor_details_submit", mentor_details_submit, wait=False)
43+
plugin.on_action("claim_mentee", claim_mentee, wait=False)
44+
plugin.on_action("reset_claim_mentee", claim_mentee, wait=False)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from sirbot import SirBot
2+
from slack import methods
3+
from slack.actions import Action
4+
5+
from pybot.endpoints.slack.utils.action_messages import claimed_attachment, base_response, not_claimed_attachment
6+
7+
8+
async def claimed(action: Action, app: SirBot):
9+
"""
10+
Provides basic "claim" functionality for use-cases that don't have any other effects.
11+
12+
Simply updates the button to allow resets and displays the user and time it was clicked.
13+
"""
14+
response = base_response(action)
15+
user_id = action['user']['id']
16+
17+
attachments = action['original_message']['attachments']
18+
19+
for index, attachment in enumerate(attachments):
20+
if attachment['callback_id'] == 'claimed':
21+
attachments[index] = claimed_attachment(user_id)
22+
response['attachments'] = attachments
23+
24+
await app.plugins['slack'].api.query(methods.CHAT_UPDATE, response)
25+
26+
27+
async def reset_claim(action: Action, app: SirBot):
28+
"""
29+
Provides basic "unclaim" functionality for use-cases that don't have any other effects.
30+
31+
Updates the button back to its initial state
32+
"""
33+
response = base_response(action)
34+
35+
attachments = action['original_message']['attachments']
36+
for index, attachment in enumerate(attachments):
37+
if attachment['callback_id'] == 'claimed':
38+
attachments[index] = not_claimed_attachment()
39+
40+
response['attachments'] = attachments
41+
await app.plugins['slack'].api.query(methods.CHAT_UPDATE, response)

0 commit comments

Comments
 (0)