Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slack's Interactive Messages endpoint reports a Content-Type of `application/x-www-form-urlencoded` but responds with something like looks like `payload=%7B%22actions%22%3A%5B%7B%22...`, which is encoded JSON inside the payload parameter, which takes the API Gateway VTL templates for a loop.
## The `substring(8)` returns the input with everything after "payload=" which is the only parameter passed in,
## everything else is encoded JSON inside that parameter.
#set ($encodedJSON = $input.body.substring(8))
$util.urlDecode(${encodedJSON})
@willdages

This comment has been minimized.

Copy link
Owner Author

willdages commented Aug 27, 2016

This isn't the most elegant mapping template ever, but it's what I used to get this payload transformed into JSON for an AWS Lambda function. Add this as an Integration Request Body Mapping Template in API Gateway, for the Content Type application/x-www-form-urlencoded.

@cookstaar

This comment has been minimized.

Copy link

cookstaar commented Jul 12, 2017

Holy crap. Wasted hours on this before I found this gist. Thank you.

@tom335

This comment has been minimized.

Copy link

tom335 commented Nov 24, 2017

Thanks, dude... really useful. Do you know why is that? I'm thinking about the reasons for this kind of decision from Slack's team.

@mjzuppe

This comment has been minimized.

Copy link

mjzuppe commented Mar 10, 2018

Thanks a million for posting this. I'd also add for anyone else struggling that I had to delete and rebuild the API with this template for it to work.

@cgjerow

This comment has been minimized.

Copy link

cgjerow commented May 18, 2018

EDIT: I was making a novice mistake and hadn't deployed the API changes.

I added this mapping template but am still receiving the same error. First time using API Gateway + Lambda, so if there are any gotchas I could be missing in the setup, like needing to publish changes to the API Gateway or something please let me know.

@StJohn3D

This comment has been minimized.

Copy link

StJohn3D commented Jul 7, 2018

Thanks a million. I had a body mapping I got from another site that was working for slash commands but wasn't working for interactions. Slack should really just send json

@YAMABASS80

This comment has been minimized.

Copy link

YAMABASS80 commented Dec 6, 2018

You are my savior! Thanks!

@DanielBlei

This comment has been minimized.

Copy link

DanielBlei commented Dec 17, 2019

Saved my day. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.