I’m trying to build a Slack Bot using the @slack/bolt node.js library on AWS Lambda
I followed the instructions on Slack documentation, but I’m having trouble with the AWSLambdaReceiver (I guess)
I created the project using SAM with the Hello-World template
This is my app.mjs
import pkg from '@slack/bolt';
const { App, AwsLambdaReceiver } = pkg;
const awsLambdaReceiver = new AwsLambdaReceiver({
signingSecret: MY_SIGNING_SECRET
});
const app = new App({
token: MY_TOKEN,
receiver: awsLambdaReceiver,
});
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
// say() sends a message to the channel where the event was triggered
await say({
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Hey there <@${message.user}>!`
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me"
},
"action_id": "button_click"
}
}
],
text: `Hey there <@${message.user}>!`
});
});
app.action('button_click', async ({ body, ack, say }) => {
// Acknowledge the action
await ack();
await say(`<@${body.user.id}> clicked the button`);
});
export const lambdaHandler = async (event, context, callback) => {
const handler = await awsLambdaReceiver.start();
return handler(event, context, callback);
}
This is my template.yaml
file
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
slack-bot-lambda
Sample SAM Template for slack-bot-lambda
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs18.x
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello/slack/events
Method: post
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Ar
The error I’m getting on AWS Lambda when I try to run is:
{
"errorType": "TypeError",
"errorMessage": "Wrong arguments",
"trace": [
"TypeError: Wrong arguments",
" at RAPIDClient.postInvocationResponse (file:///var/runtime/index.mjs:434:27)",
" at complete (file:///var/runtime/index.mjs:811:16)",
" at done (file:///var/runtime/index.mjs:835:11)",
" at succeed (file:///var/runtime/index.mjs:839:9)",
" at file:///var/runtime/index.mjs:872:20"
]
}
And
{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Cannot convert undefined or null to object","reason":{"errorType":"TypeError","errorMessage":"Cannot convert undefined or null to object","stack":["TypeError: Cannot convert undefined or null to object"," at Function.keys (<anonymous>)"," at AwsLambdaReceiver.getHeaderValue (/var/task/node_modules/@slack/bolt/dist/receivers/AwsLambdaReceiver.js:186:43)"
I’m assuming the error is on the return handler(event, context, callback)
but I don’t know much I could do.
Appreciate your help. Thanks!
I tried checking if any of the handler parameters was null, but apparently none of them were null
1