Skip to content

Commit

Permalink
(OperationCode#110) Adds an update method to communicate military status
Browse files Browse the repository at this point in the history
When an update is recv'd from the backend about military status, this
will send a message about what channel to join (which can be swapped
or enhanced with a call to channels.invite).
  • Loading branch information
brownnrl committed Oct 2, 2019
1 parent 6e78e06 commit 1992112
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pybot/endpoints/api/slack_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
handle_slack_invite_error,
production_only,
)

from pybot.endpoints.slack.utils.event_utils import (
base_user_message,
send_user_greetings,
)

from pybot.endpoints.slack.utils.event_messages import (
identify_military_spouse,
identify_military_ad,
)

from pybot.plugins import APIPlugin
from pybot.plugins.api.request import SlackApiRequest

Expand All @@ -18,6 +29,7 @@
def create_endpoints(plugin: APIPlugin):
plugin.on_get("verify", verify, wait=True)
plugin.on_get("invite", invite, wait=True)
plugin.on_get("update", update, wait=True)


async def verify(request: SlackApiRequest, app: SirBot) -> dict:
Expand All @@ -36,6 +48,31 @@ async def verify(request: SlackApiRequest, app: SirBot) -> dict:
return {"exists": False}


async def update(request: SlackApiRequest, app: SirBot) -> dict:
"""
Verifies whether a user exists in the configured slack group with
the given email
:return: The user's slack id and displayName if they exist
"""
slack = app.plugins["slack"].api
slack_id = request.query["slack_id"]
military_status = request.query["military_status"]
if military_status not in ('current', 'spouse'):
return
user_message = base_user_message(slack_id)

if military_status == 'current':
user_message['text'] = identify_military_ad(slack_id)
elif military_status == 'spouse':
user_message['text'] = identify_military_spouse(slack_id)

send_user_greetings([user_message], slack)

return {"success": "true"}



@production_only
async def invite(request: SlackApiRequest, app: SirBot):
"""
Expand Down
15 changes: 15 additions & 0 deletions pybot/endpoints/slack/utils/event_messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from typing import List

def identify_military_spouse(user_id: str) -> str:
return (
f"Hi <@{user_id}> !\n\n",
"As a military spouse, we recommend joining #milspouses,",
"a shared community with MilSpouse Coders (https://www.milspousecoders.org)",
"You can share with other spouses of military service members finding",
"fulfilling careers in technology."
)

def identify_military_ad(user_id: str) -> str:
return (
f"Hi <@{user_id}> !\n\n",
"As a currently serving active duty member, consider joining #active-duty where",
"other active duty folks congregate and meet each other."
)

def team_join_initial_message(user_id: str) -> str:
return (
Expand Down

0 comments on commit 1992112

Please sign in to comment.