Last active
January 11, 2018 16:40
-
-
Save Elleo/e3884f025c208925de33626433d93d83 to your computer and use it in GitHub Desktop.
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
def add_saved_reply(message, channel, slack_client, cape_client): | |
try: | |
# Split the message up into its component parts | |
message = message.split(".add-saved-reply")[1] | |
question, answer = message.split('|', 1) | |
except Exception as e: | |
# Let the user know the correct formatting if we couldn't parse what they sent | |
slack_client.api_call("chat.postMessage", channel=channel, | |
text="Sorry, I didn't understand that. The usage for " \ | |
".add-saved-reply is: .add-saved-reply " \ | |
"question | answer", | |
as_user=True) | |
return | |
try: | |
# Create a new saved reply | |
cape_client.add_saved_reply(question, answer) | |
slack_client.api_call("chat.postMessage", channel=channel, | |
text="Thanks, I'll remember that!", as_user=True) | |
except CapeException as e: | |
# Inform the user of any errors encountered when adding their saved reply | |
slack_client.api_call("chat.postMessage", channel=channel, | |
text=e.message, as_user=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment