Skip to content

Instantly share code, notes, and snippets.

@Elleo
Last active January 11, 2018 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elleo/e3884f025c208925de33626433d93d83 to your computer and use it in GitHub Desktop.
Save Elleo/e3884f025c208925de33626433d93d83 to your computer and use it in GitHub Desktop.
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