Skip to content

Commit 75ee8b9

Browse files
authored
Merge pull request #245 from OperationCode/staging
2 parents 847d595 + c941793 commit 75ee8b9

File tree

14 files changed

+125
-24
lines changed

14 files changed

+125
-24
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extending [Pyslacker's](https://pyslackers.com/)
3232
framework.
3333

3434
## Resources
35-
* [Slack Bot Tutorial](https://www.fullstackpython.com/blog/build-first-slack-bot-python.html)
35+
* [Slack Bot Tutorial](https://www.digitalocean.com/community/tutorials/how-to-build-a-slackbot-in-python-on-ubuntu-20-04)
3636
* [Slack Events API Framework](https://github.com/slackapi/python-slack-events-api)
3737
* [sir-bot-a-lot](https://github.com/pyslackers/sir-bot-a-lot-2)
3838

@@ -213,6 +213,13 @@ example:
213213

214214
https://123_random_code_321.ngrok.io/slack/events
215215

216+
Additional setup may needed depending on the type of events pybot is subscribing to.
217+
For example, in order to work on the app's functionality on a `team_join` event, you need to:
218+
219+
* Add `team_join` to workspace event
220+
* Make sure `greetings` channel exists and ensure the app is invited to the channel
221+
* Add necessary OAuth scopes to the app e.g. `users:read`, `chat:write`, etc.
222+
216223
#### Slash Commands
217224

218225
You can follow the instructions (and read helpful relation information) on the

pybot/endpoints/airtable/message_templates/messages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from typing import List
22

33

4-
def mentor_request_text(user_id, service, skillsets, requested_mentor_message=None):
4+
def mentor_request_text(
5+
user_id, service, skillsets, affiliation, requested_mentor_message=None
6+
):
57
if not skillsets:
68
skillsets = "None provided"
79
text = (
810
f"User <@{user_id}> has requested a mentor for {service}\n\n"
9-
f"Requested Skillset(s): {skillsets.replace(',', ', ')}"
11+
f"Requested Skillset(s): {skillsets.replace(',', ', ')}\n\n"
12+
f"Requestor Affiliation: {affiliation}"
1013
)
1114

1215
if requested_mentor_message:
@@ -29,7 +32,7 @@ def claim_mentee_attachment(record: str) -> List[dict]:
2932
"text": "Claim Mentee",
3033
"type": "button",
3134
"style": "primary",
32-
"value": f"mentee_claimed",
35+
"value": "mentee_claimed",
3336
}
3437
],
3538
}

pybot/endpoints/airtable/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def _create_messages(
6565
slack_id,
6666
service_translation,
6767
request.get("skillsets", None),
68+
request.get("affiliation", "None Provided"),
6869
requested_mentor_message,
6970
),
7071
"attachments": claim_mentee_attachment(request["record"]),

pybot/endpoints/api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from slack.io.abc import SlackAPI
77
from slack.methods import Methods
88

9-
from pybot.endpoints.slack.utils import PYBOT_ENV, OPS_CHANNEL
9+
from pybot.endpoints.slack.utils import OPS_CHANNEL, PYBOT_ENV
1010
from pybot.endpoints.slack.utils.action_messages import (
1111
TICKET_OPTIONS,
1212
not_claimed_attachment,

pybot/endpoints/slack/actions/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
)
2121
from .new_member import (
2222
member_greeted,
23+
member_messaged,
2324
open_suggestion,
2425
post_suggestion,
2526
reset_greet,
27+
reset_message,
2628
resource_buttons,
2729
)
2830
from .report_message import open_report_dialog, send_report
@@ -38,6 +40,8 @@ def create_endpoints(plugin: SlackPlugin):
3840
plugin.on_action("resource_buttons", resource_buttons, wait=False)
3941
plugin.on_action("greeted", member_greeted, name="greeted", wait=False)
4042
plugin.on_action("greeted", reset_greet, name="reset_greet", wait=False)
43+
plugin.on_action("messaged", member_messaged, name="messaged", wait=False)
44+
plugin.on_action("messaged", reset_message, name="reset_message", wait=False)
4145
plugin.on_action("suggestion", open_suggestion, wait=False)
4246
plugin.on_action("suggestion_modal", post_suggestion, wait=False)
4347

pybot/endpoints/slack/actions/new_member.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from pybot.endpoints.slack.utils.action_messages import (
77
HELP_MENU_RESPONSES,
88
base_response,
9+
direct_messaged_attachment,
910
greeted_attachment,
1011
new_suggestion_text,
12+
not_direct_messaged_attachment,
1113
not_greeted_attachment,
1214
reset_greet_message,
1315
suggestion_dialog,
@@ -71,3 +73,25 @@ async def reset_greet(action: Action, app: SirBot):
7173
response["attachments"][0]["text"] = reset_greet_message(action["user"]["id"])
7274

7375
await app.plugins["slack"].api.query(methods.CHAT_UPDATE, response)
76+
77+
78+
async def member_messaged(action: Action, app: SirBot):
79+
"""
80+
Called when a outreach team member clicks the button saying they messaged the new member
81+
"""
82+
response = base_response(action)
83+
user_id = action["user"]["id"]
84+
response["attachments"] = direct_messaged_attachment(user_id)
85+
86+
await app.plugins["slack"].api.query(methods.CHAT_UPDATE, response)
87+
88+
89+
async def reset_message(action: Action, app: SirBot):
90+
"""
91+
Resets the claim messaged button back to its initial state and appends the user that hit reset and the time
92+
"""
93+
response = base_response(action)
94+
response["attachments"] = not_direct_messaged_attachment()
95+
response["attachments"][0]["text"] = reset_greet_message(action["user"]["id"])
96+
97+
await app.plugins["slack"].api.query(methods.CHAT_UPDATE, response)

pybot/endpoints/slack/commands.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,16 @@ async def slash_mentor(command: Command, app: SirBot):
4848

4949
@catch_command_slack_error
5050
async def slash_mentor_volunteer(command: Command, app: SirBot) -> None:
51-
airtable = app.plugins["airtable"].api
52-
skillsets = await airtable.get_all_records("Skillsets", "Name")
5351

54-
blocks = mentor_volunteer_blocks(skillsets)
5552
response = {
56-
"text": "Mentor Sign up Form",
57-
"blocks": blocks,
53+
"text": "Please fill up the Mentor Sign up Form here: https://op.co.de/volunteer-signup",
5854
"channel": command["user_id"],
5955
"as_user": True,
6056
}
6157

6258
await app.plugins["slack"].api.query(methods.CHAT_POST_MESSAGE, response)
6359

60+
6461
@catch_command_slack_error
6562
async def slash_report(command: Command, app: SirBot):
6663
"""

pybot/endpoints/slack/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ async def team_join(event: Event, app: SirBot) -> None:
2929
slack_api = app.plugins["slack"].api
3030
user_id = event["user"]["id"]
3131

32-
*user_messages, community_message = build_messages(user_id)
32+
*user_messages, community_message, outreach_team_message = build_messages(user_id)
3333
futures = [
3434
send_user_greetings(user_messages, slack_api),
3535
send_community_notification(community_message, slack_api),
36+
send_community_notification(outreach_team_message, slack_api),
3637
]
3738

3839
logger.info(f"New team join event: {event}")

pybot/endpoints/slack/message_templates/commands.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def mentor_request_blocks(services, skillsets):
7878
{
7979
"type": "section",
8080
"block_id": "comments",
81-
"text": {"type": "mrkdwn", "text": "*Add additional comments* (optional)"},
81+
"text": {"type": "mrkdwn", "text": "*Add comments* (required)"},
8282
"accessory": {
8383
"type": "button",
8484
"action_id": "comments_btn",
@@ -111,6 +111,10 @@ def mentor_request_blocks(services, skillsets):
111111
"text": {"type": "plain_text", "text": "Military Spouse"},
112112
"value": "Military Spouse",
113113
},
114+
{
115+
"text": {"type": "plain_text", "text": "Non Veteran"},
116+
"value": "Non Veteran",
117+
},
114118
],
115119
},
116120
},

pybot/endpoints/slack/message_templates/mentor_request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def affiliation(self, new_affiliation: str) -> None:
8181
self.clear_errors()
8282

8383
def validate_self(self) -> bool:
84-
if not self.service or not self.affiliation:
84+
if not self.service or not self.affiliation or not self.details:
8585
return False
8686
self.clear_errors()
8787
return True
8888

8989
def add_errors(self) -> None:
9090
submit_attachment = {
91-
"text": ":warning: Service and group certification are required. :warning:",
91+
"text": ":warning: Service, group certification and comments are required. :warning:",
9292
"color": "danger",
9393
}
9494
self.attachments = [submit_attachment]
@@ -245,7 +245,7 @@ def mentee_claimed_attachment(self) -> dict:
245245
"actions": [
246246
{
247247
"name": f"{self.record}",
248-
"text": f"Reset claim",
248+
"text": "Reset claim",
249249
"type": "button",
250250
"style": "danger",
251251
"value": "reset_claim_mentee",

0 commit comments

Comments
 (0)