aws-lambdaaws-api-gatewayslackslack-commands

Slack Slash Command and API Gateway Integration


I have set up a Slack slash command which triggers an API Gateway which in turn execute my AWS Lambda.

The slash command works for now, but I am not able to retrieve the event in my AWS lambda.

I have followed this link on how to integrate my API gateway to accept non-json payload from slash command but now when i am sending a slash command such as /helloworld trigger the event of the AWS lambda is returned as such:

{'postBody': 'token=CGH9VQ5Gop...&team_id=...&team_domain=...&channel_id=...&channel_name=...&user_id=U01R5QXP61Z&...}

This is the code of my AWS Lambda as simple as that:

def lambda_handler(event, context):

    return str(event)

Can someone please help?


Solution

  • So, using an Integration Method you have a bunch of additional information coming - All the JSON information from the API gateway, plus all json information from the slack webhook. Given what I see in your response, it looks like channel information and such from Slack is being returned.

    Since what you seem to want to return is just whatever you put in trigger then you would need to know what Key that is under in the json the slack webhook is sending.

    If you cant find the schema of that json in the Slack API documentation, then you can just log the event and check it out in cloudwatch to see what the heck is showing up. You can then manipulate that json just like you would any json object in code and get the various keys you want out of it.