Looking into using Serverless to more easily build...
# help
k
Looking into using Serverless to more easily build Slackbots with Bolt. It seems like The bolt guide specifies using Serverless Framework. Would Serverless Stack be similar to use here? What would I need to do differently? https://slack.dev/bolt-js/deployments/aws-lambda#set-up-serverless-framework
t
I just started looking into Slack apps, I don't think Bolt is friendly with serverless
actually maybe I'm wrong let me look into this further
Ah they have a lambda receiver - interesting
I'm going to be digging into this deeper this week so I'll be able to tell you more then
k
So what makes it friendly/ recommended with serverless framework but not serverless stack?
t
When I was looking into it yesterday it seemed not friendly to serverless in general but I didn't see that it worked with serverless framework. Which means it'll work with SST
k
I’d assume so, just don’t know how similar the API’s between Framework and SST are.
t
From what I see it looks pretty easy! Should be able to just initialize a single sst.Function
best part is you don't need to do the ngrok stuff that's in their docs since we expose a real api url
k
Okay. What’s the best route for learning SST for primarily Lambda? The gigantic real world guide is massively overkill and I’d need far more time for that.
t
I'd suggest maybe poking through the examples folder and setting up a hello world
From there you can try and build something and ask here when you get stuck
f
@Kevin Lenell just to chime in here… you can play around with this example to get familiar with SST. It’s similar to the example Slack example, and shouldn’t take more than 30min to set it up.
t
I setup bolt in my example project last night
You should bootstrap a new SST project and then you can create a REST api like this in the stack
Copy code
const rest = new sst.Api(this, "rest", {
      routes: {
        "POST /slack": "services/rest/slack.handler",
      },
    })

    this.addOutputs({
      AppSync: appsync.url,
      Rest: rest.url,
    })
Then the handler it points to just needs to have this
Copy code
import { APIGatewayProxyHandlerV2 } from "aws-lambda"
import { App, AwsLambdaReceiver } from "@slack/bolt"

const awsLambdaReceiver = new AwsLambdaReceiver({
  signingSecret: "<>",
})

// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({...})

app.event("message", async (event) => {...})

export const handler: APIGatewayProxyHandlerV2 = async (
  event,
  context,
  callback
) => {
  const handler = (await app.start()) as any
  return handler(event, context, callback)
}
pretty easy!
I did find the typing with the bolt library to be pretty bad so let me know if you get stuck anywhere. Lots of missing fields in the types + incorrect types returned in some places
Depending on how complex what you want to do is, you might not even want to use bolt and just handle the webhook directly
f
Yeah, and like @thdxr mentioned, you don’t need ngrok. Just run npm/yarn start, and paste the deployed API url (append it with
/slack/events
) into as the Request URL