def turbot_lambda(event, context):
"""Top-level entry point for our lambda function.
- Currently only calls into the rot() function but may become more
- sophisticated later on."""
+ This parses the request and arguments and farms out to supporting
+ functions to implement all supported slash commands."""
body = parse_qs(event['body'])
- result = rot(body['text'][0])
+ command = body['command'][0]
+ args = body['text'][0]
+
+ if (command == "/rotlambda" or command == "/rot"):
+ return rot_slash_command(args)
+
+ error = "Command {} not implemented.".format(command)
+
+ print("Error: {}".format(error))
+
+ return {
+ 'statusCode': 404,
+ 'body': error
+ }
+
+def rot_slash_command(args):
+ """Implementation of the /rot command
+
+ The args string should be as follows:
+
+ [count|*] String to be rotated
+
+ That is, the first word of the string is an optional number (or
+ the character '*'). If this is a number it indicates an amount to
+ rotate each character in the string. If the count is '*' or is not
+ present, then the string will be rotated through all possible 25
+ values.
+
+ The result of the rotation is returned (with Slack formatting) in
+ the body of the response so that Slack will provide it as a reply
+ to the user who submitted the slash command."""
return {
'statusCode': 200,
- 'body': result
+ 'body': rot(args)
}