https://serverless-stack.com/ logo
#help
Title
# help
k

Kevin Lenell

10/26/2021, 1:18 AM
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

thdxr

10/26/2021, 1:19 AM
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

Kevin Lenell

10/26/2021, 1:59 AM
So what makes it friendly/ recommended with serverless framework but not serverless stack?
t

thdxr

10/26/2021, 2:00 AM
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

Kevin Lenell

10/26/2021, 2:15 AM
I’d assume so, just don’t know how similar the API’s between Framework and SST are.
t

thdxr

10/26/2021, 2:15 AM
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

Kevin Lenell

10/26/2021, 2:23 AM
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

thdxr

10/26/2021, 2:41 AM
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

Frank

10/26/2021, 1:13 PM
@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

thdxr

10/26/2021, 1:16 PM
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

Frank

10/26/2021, 1:22 PM
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
4 Views