Skip to content

Commit c941793

Browse files
author
Aaron Suarez
authored
Merge pull request #235 from chynh/add-greetings
add "I will DM" button
2 parents 72f3a74 + bbae870 commit c941793

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ example:
212212

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

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

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

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/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/utils/action_messages.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,49 @@ def not_greeted_attachment():
134134
]
135135

136136

137+
def direct_messaged_attachment(user_id: str) -> List[dict]:
138+
return [
139+
{
140+
"text": f":100:<@{user_id}> has DMed the new user!:100:\n"
141+
f"<!date^{now()}^DMed at {{date_num}} {{time_secs}}|Failed to parse time>",
142+
"fallback": "",
143+
"color": "#3AA3E3",
144+
"callback_id": "messaged",
145+
"attachment_type": "default",
146+
"actions": [
147+
{
148+
"name": "reset_message",
149+
"text": f"Reset DM",
150+
"type": "button",
151+
"style": "danger",
152+
"value": "reset_message",
153+
}
154+
],
155+
}
156+
]
157+
158+
159+
def not_direct_messaged_attachment():
160+
return [
161+
{
162+
"text": "",
163+
"fallback": "Someone should DM them!",
164+
"color": "#3AA3E3",
165+
"callback_id": "messaged",
166+
"attachment_type": "default",
167+
"actions": [
168+
{
169+
"name": "messaged",
170+
"text": "I will DM them!",
171+
"type": "button",
172+
"style": "primary",
173+
"value": "messaged",
174+
}
175+
],
176+
}
177+
]
178+
179+
137180
def not_claimed_attachment():
138181
return {
139182
"text": "",

pybot/endpoints/slack/utils/event_utils.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
BACKEND_USERNAME,
1313
COMMUNITY_CHANNEL,
1414
)
15-
from pybot.endpoints.slack.utils.action_messages import not_greeted_attachment
15+
from pybot.endpoints.slack.utils.action_messages import (
16+
not_direct_messaged_attachment,
17+
not_greeted_attachment,
18+
)
1619
from pybot.endpoints.slack.utils.event_messages import (
1720
base_resources,
1821
external_button_attachments,
@@ -30,7 +33,7 @@ def base_user_message(user_id: str) -> Message:
3033
return message
3134

3235

33-
def build_messages(user_id) -> Tuple[Message, Message, Message, Message]:
36+
def build_messages(user_id) -> Tuple[Message, Message, Message, Message, Message]:
3437
initial_message = base_user_message(user_id)
3538
initial_message["text"] = team_join_initial_message(user_id)
3639

@@ -47,7 +50,21 @@ def build_messages(user_id) -> Tuple[Message, Message, Message, Message]:
4750
community_message["attachments"] = not_greeted_attachment()
4851
community_message["channel"] = COMMUNITY_CHANNEL
4952

50-
return initial_message, second_message, action_menu, community_message
53+
outreach_team_message = Message()
54+
outreach_team_message["text"] = (
55+
f":spiral_note_pad: Outreach Team: Please reach out to <@{user_id}> via DM"
56+
f":spiral_note_pad: "
57+
)
58+
outreach_team_message["attachments"] = not_direct_messaged_attachment()
59+
outreach_team_message["channel"] = COMMUNITY_CHANNEL
60+
61+
return (
62+
initial_message,
63+
second_message,
64+
action_menu,
65+
community_message,
66+
outreach_team_message,
67+
)
5168

5269

5370
async def send_user_greetings(

0 commit comments

Comments
 (0)