Hey all, I'm trying to create a serverless slack bot in AWS Lambda. I managed to get the app to send a message to a user in Slack with an interactive button, which sends a post back to the app when clicked. The problem is that the body of this message (the one from the button click) has the body of the JSON all garbled. Here is a reduced version of the garble:
'body': 'cGF5bG9hZD0lN0IlMjJ0eXBlJTIyJTNBJTIyYmxvY2tfYWN0aW9...
The rest of the JSON object looks normal.
On the other hand, the button object I'm sending to slack is this one:
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": True,
"text": "Yes"
},
"style": "primary",
"value": "click_me_123"
},
What am I missing? Appreciate all the help I can get!
Hi @tinoargentino
API Gateway's payload can be base64-encoded: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-workflow.html
Here is the code in Bolt for Python for dealing with this. https://github.com/slackapi/bolt-python/blob/v0.9.4b0/slack_bolt/adapter/aws_lambda/handler.py#L74-L83
You can do the same in your plain handler function.
OMG.... unbelievable!!! and on a Friday night!!! I can't thank you enough @seratch !!! I wish I would have asked you before spending 5 hours on google searching how to do this!!!
Is this standard procedure? I feel like I went through all of the documentation and somehow missed this detail! If so please would you tell me where, so I know what to look for in the future?
I'm glad to know that it was helpful to you!
When I created a Slack app built upon AWS API Gateway + Lambda for the first time, I was also a bit confused with this. As far as I know, there is no clear guide for this in AWS's official documents apart from the one I've shared in my previous comment.
As Slack sends requests with Content-Type: application/x-www-form-urlencoded header for interactivity features, request body data is always base64-encoded on their end.
Let me close this issue now. Enjoy your Friday hack night! 馃槃
Most helpful comment
Hi @tinoargentino
API Gateway's payload can be base64-encoded: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-workflow.html
Here is the code in Bolt for Python for dealing with this. https://github.com/slackapi/bolt-python/blob/v0.9.4b0/slack_bolt/adapter/aws_lambda/handler.py#L74-L83
You can do the same in your plain handler function.