bolt-js icon indicating copy to clipboard operation
bolt-js copied to clipboard

Cannot respond to incoming message events with `say` using the Bun runtime

Open taciturnaxolotl opened this issue 1 year ago • 1 comments

@slack/bolt version

^3.18.0

Your App and Receiver Configuration

const app = new App({
    token: process.env.SLACK_BOT_TOKEN,
    signingSecret: process.env.SLACK_SIGNING_SECRET,
    appToken: process.env.SLACK_APP_TOKEN,
    socketMode: true,
    logLevel: LogLevel.DEBUG,
});

Node.js runtime version

Using Bun: 1.1.8

Steps to reproduce:

  1. Create a new App
  2. Add events via the web interface
  3. Try to listen for events via app.message:
// 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(`Hey there!`);
});

Expected result:

I would expect it to respond to events containing hello with "Hey there!"

Actual result:

The DEBUG log logs that an event was received but the app.message code doesn't fire:

[DEBUG]  socket-mode:SocketModeClient:0 Received a message on the WebSocket: {"envelope_id":"4bf59009-f23b-4dcf-a55c-a2caf38c1a97","payload":{"token":"dVGyeNoTdbYo7MJJgnBE2DVP","team_id":"T0266FRGM","context_team_id":"T0266FRGM","context_enterprise_id":null,"api_app_id":"A074HKE3KLZ","event":{"user":"U062UG485EE","type":"message","ts":"1716219579.949599","client_msg_id":"90676a02-8d5a-4bb8-9c3f-6c0e5eabfdfc","text":"hello","team":"T0266FRGM","blocks":[{"type":"rich_text","block_id":"ZL1yL","elements":[{"type":"rich_text_section","elements":[{"type":"text","text":"hello"}]}]}],"channel":"C07423VT8DT","event_ts":"1716219579.949599","channel_type":"channel"},"type":"event_callback","event_id":"Ev074MENGTND","event_time":1716219579,"authorizations":[{"enterprise_id":null,"team_id":"T0266FRGM","user_id":"U073QCVUCQP","is_bot":true,"is_enterprise_install":false}],"is_ext_shared_channel":false,"event_context":"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDI2NkZSR00iLCJhaWQiOiJBMDc0SEtFM0tMWiIsImNpZCI6IkMwNzQyM1ZUOERUIn0"},"type":"events_api","accepts_response_payload":false,"retry_attempt":0,"retry_reason":""}
[DEBUG]  socket-mode:SocketModeClient:0 Calling ack() - type: events_api, envelope_id: 4bf59009-f23b-4dcf-a55c-a2caf38c1a97, data: undefined
[DEBUG]  socket-mode:SocketModeClient:0 send() method was called in state: connected, state hierarchy: connected,ready
[DEBUG]  socket-mode:SocketModeClient:0 Sending a WebSocket message: {"envelope_id":"4bf59009-f23b-4dcf-a55c-a2caf38c1a97","payload":{}

taciturnaxolotl avatar May 20 '24 15:05 taciturnaxolotl

Hey @kcoderhtml! 👋 Thanks for writing in! It's neat to see some bun use with @slack/bolt!

I'm not immediately sure of what causes this, but I believe it's something related to the bun runtime 🤔 When testing this with bun I find the same debug logs without a message being sent to channel, but node responds in channel as expected.

This isn't ideal (it'd be better if it worked) but makes sense to me since @slack/bolt is backed by @slack/web-api which is a part of the slackapi/node-slack-sdk. For that reason I don't believe a fix will be prioritized at this time (larger changes seem to be required) but perhaps the unofficial but well-maintained slack-edge can offer the bun support?

In any case let's leave this issue open for a while in case other discoveries are made or if other troubles are existing with say!

zimeg avatar May 20 '24 22:05 zimeg

Thank you! I ended up getting it to work by changing to a fixed URL via ngrok however it now creates an error every time an event is received but still manages to execute the events normally and works otherwise fine.

[ERROR]  bolt-app 20 |     ErrorCode["UnknownError"] = "slack_bolt_unknown_error";
21 |     ErrorCode["WorkflowStepInitializationError"] = "slack_bolt_workflow_step_initialization_error";
22 | })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
23 | class UnknownError extends Error {
24 |     constructor(original) {
25 |         super(original.message);
             ^
error: JSGlobalProxy is not a constructor
 code: "slack_bolt_unknown_error"

      at new UnknownError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:25:9)
      at asCodedError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:35:12)
      at handleError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/App.js:612:35)

[ERROR]   An unhandled error occurred while Bolt processed an event
[ERROR]  bolt-app 20 |     ErrorCode["UnknownError"] = "slack_bolt_unknown_error";
21 |     ErrorCode["WorkflowStepInitializationError"] = "slack_bolt_workflow_step_initialization_error";
22 | })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
23 | class UnknownError extends Error {
24 |     constructor(original) {
25 |         super(original.message);
             ^
error: JSGlobalProxy is not a constructor
 code: "slack_bolt_unknown_error"

      at new UnknownError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:25:9)
      at asCodedError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:35:12)
      at handleError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/App.js:612:35)

[ERROR]   An unhandled error occurred while Bolt processed an event

taciturnaxolotl avatar May 20 '24 22:05 taciturnaxolotl

While developing slack-edge, I found that Socket Mode with Bun's built-in WebSocket implementation doesn't work. Thus, there is no workaround for it.

I am not sure about the JSGlobalProxy error with Request URL settings. Nonetheless, @slack/bolt is specifically designed only for Node.js usage. Therefore, it's not surprising to see such unexpected errors with Bun. If you're thinking of building a production-grade app, I don't recommend using @slack/bolt with Bun. Instead, consider going with either @slack/bolt + Node.js or slack-edge + Node.js/Bun/Deno + Request URL.

seratch avatar May 20 '24 23:05 seratch

Thank you! I ended up getting it to work by changing to a fixed URL via ngrok however it now creates an error every time an event is received but still manages to execute the events normally and works otherwise fine.

[ERROR]  bolt-app 20 |     ErrorCode["UnknownError"] = "slack_bolt_unknown_error";
21 |     ErrorCode["WorkflowStepInitializationError"] = "slack_bolt_workflow_step_initialization_error";
22 | })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
23 | class UnknownError extends Error {
24 |     constructor(original) {
25 |         super(original.message);
             ^
error: JSGlobalProxy is not a constructor
 code: "slack_bolt_unknown_error"

      at new UnknownError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:25:9)
      at asCodedError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:35:12)
      at handleError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/App.js:612:35)

[ERROR]   An unhandled error occurred while Bolt processed an event
[ERROR]  bolt-app 20 |     ErrorCode["UnknownError"] = "slack_bolt_unknown_error";
21 |     ErrorCode["WorkflowStepInitializationError"] = "slack_bolt_workflow_step_initialization_error";
22 | })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
23 | class UnknownError extends Error {
24 |     constructor(original) {
25 |         super(original.message);
             ^
error: JSGlobalProxy is not a constructor
 code: "slack_bolt_unknown_error"

      at new UnknownError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:25:9)
      at asCodedError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/errors.js:35:12)
      at handleError (/home/kierank/Documents/Projects/the-old-man/node_modules/@slack/bolt/dist/App.js:612:35)

[ERROR]   An unhandled error occurred while Bolt processed an event

This error would happen if some code did new globalThis or new global.

Most likely, somewhere the this value is (incorrectly) set to globalThis and then some other code calls new this. If a dependency is using vm that could also be related.

Either way though, this is a bug in Bun and not in @slack/bolt. Feel free to open an issue in Bun's github repository.

Jarred-Sumner avatar May 25 '24 08:05 Jarred-Sumner

👋 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. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar Jul 01 '24 00:07 github-actions[bot]