-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,51 +9,50 @@ | |
import google_sheets | ||
|
||
|
||
# event.data['text'] contains the text of the slash command. | ||
def on_slack_slash_command(event): | ||
"""Entry point for the "/reserveroom <room> <title>" Slack slash command.""" | ||
slack = slack_client("slack_conn") | ||
channel_id = event.data.channel_id | ||
|
||
channel_id = event.data["channel_id"] | ||
rooms = google_sheets.get_room_list() | ||
|
||
txt = event.data["text"] | ||
words = txt.split(maxsplit=1) | ||
if len(words) != 2: | ||
slack.chat_postMessage( | ||
channel=channel_id, | ||
text="Bad input. Please use the following format: /createmeeting <room> <event>", | ||
) | ||
cmd_text = event.data.text.split(maxsplit=1) | ||
if len(cmd_text) < 2: | ||
error = "Error: please use the following format: `/reserveroom <room> <title>`" | ||
slack.chat_postMessage(channel=channel_id, text=error) | ||
return | ||
if words[0] not in rooms: | ||
slack.chat_postMessage(channel=channel_id, text=f"Room {words[0]} not found") | ||
|
||
room, title = cmd_text | ||
if room not in google_sheets.get_room_list(): | ||
error = f"Error: `{room}` not found in the list of rooms" | ||
slack.chat_postMessage(channel=channel_id, text=error) | ||
return | ||
|
||
user = event.data.user_id # TODO: Convert to name. | ||
|
||
now = datetime.now(UTC) | ||
in_5_minutes = now + timedelta(minutes=5) | ||
in_30_minutes = now + timedelta(minutes=30) | ||
|
||
event = { | ||
"summary": words[1], | ||
"description": words[1], | ||
"summary": title, | ||
"description": f"Reserved via Slack by {user}", | ||
"start": {"dateTime": in_5_minutes.isoformat()}, | ||
"end": {"dateTime": in_30_minutes.isoformat()}, | ||
"reminders": {"useDefault": False}, | ||
# TODO: Add the requester. | ||
# "attendees": [ | ||
# {"email": "[email protected]"}, | ||
# {"email": "[email protected]"}, | ||
# ], | ||
} | ||
res = _create_calendar_event(words[0], event) | ||
|
||
slack.chat_postMessage( | ||
channel=channel_id, text=f"Meeting request to {words[0]} was sent" | ||
) | ||
# TODO: Handle errors. | ||
_create_calendar_event(room, event) | ||
slack.chat_postMessage(channel=channel_id, text=f"Scheduled meeting in `{room}`") | ||
|
||
|
||
# It better to have this as activity to save the creation of multiple activities when creating a insert event | ||
# It's better to mark this as a single activity, to minimize the creation of | ||
# multiple overly-granular activities during this Google Calendar API call. | ||
@autokitteh.activity | ||
def _create_calendar_event(calendarId, event): | ||
def _create_calendar_event(room, event): | ||
gcal = google_calendar_client("calendar_conn").events() | ||
event = gcal.insert(calendarId=calendarId, body=event).execute() | ||
return event | ||
return gcal.insert(calendarId=room, body=event).execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters