question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Returning a promise from `requestListener` so we know when processing is done

See original GitHub issue

Description

Hooking bolt into next.js and got it working with:

import { App, HTTPReceiver, GenericMessageEvent } from '@slack/bolt'
import { NextApiRequest, NextApiResponse } from 'next';

const receiver = new HTTPReceiver({
  endpoints: ['/api/slack/events'],
  signingSecret: process.env.SIGNING_SECRET,
  processBeforeResponse: true
})

// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({
  token: process.env.ACCESS_TOKEN,
  receiver,
  ignoreSelf: true
});

app.message('hi', async ({ message, say }) => {
  const msg = message as GenericMessageEvent
  await say(`:wave: <@${msg.user}>`)
})

export default receiver.requestListener;

export const config = {
  api: {
    bodyParser: false,
  }
}

Next.js will complain that:

API resolved without sending a response for /api/slack/events, this may result in stalled requests.

From here: https://github.com/vercel/next.js/issues/10439#issuecomment-583214126 we need to return a promise so it knows when to kill the function on it’s end.

Instead of wrapping in an async closure, can we just return a promise?

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I’ve read and understood the Contributing guidelines and have done my best effort to follow them.
  • I’ve read and agree to the Code of Conduct.
  • I’ve searched for any related issues and avoided creating a duplicate issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
aoberoicommented, Jan 14, 2021

I got a Next.js app working without the warning. Got it deployed to Vercel as well.

I split things up a bit so that the pages/api/slack/[...all].js file just sets up the HTTP receiver.

Then in lib/bolt.js i did all the normal Bolt things.

What do you think?

0reactions
github-actions[bot]commented, Nov 29, 2021

👋 It looks like this issue has been open for 30 days with no activity. We’ll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I wait for a promise to finish before returning the ...
I have a simple JS function which queries a Parse database. It's supposed to return the array of results, but obviously due to...
Read more >
Node.js v19.3.0 Documentation
Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will...
Read more >
Using promises - JavaScript - MDN Web Docs
Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function. Imagine a function, ...
Read more >
Node js http request await - viviamaviaggia.it
The await operator can be placed before a Promise and makes Javascript to wait ... Below is how you can make In a...
Read more >
How To Create a Web Server in Node.js with the HTTP Module
In this tutorial, you will learn how to build web servers using the http ... and quit, or if we stop the Node.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found