slackapi/bolt-js

`context.matches.groups` becomes undefined after a Web API call

Closed this issue ยท 8 comments

(Filling out the following with as much detail as you can provide will help us solve your issue sooner.)

Reproducible in:

The Slack SDK version

3.13.1

Node.js runtime version

14.17.1

Steps to reproduce:

app.message(/\b(?<greeting>hi+|he+llo+|he+y+)\b.*/i, async({message, context, say}) => {
	const user = await app.client.users.info({'user': message.user});
	const greeting = context.matches.groups['greeting'];
}

Expected result - Actual result:

After the app.client call, context.matches.groups becomes undefined but should contain {greeting: "hello"} if the user type hello.

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. ๐Ÿ™‡

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Hey @dylan-kim ๐Ÿ‘‹ I'm not getting undefined when I run this same snippet ๐Ÿค” Instead greeting contains a "hello" as expected.

The regex looks alright but maybe something strange is happening here... Could you share the output of context.matches? I'm finding the following:

[
  'hello',
  'hello',
  index: 0,
  input: 'hello',
  groups: [Object: null prototype] { greeting: 'hello' }
]

I'm also not sure if this behavior might be caused by mixing and matching of Bolt and Node versions being used. I also tested this with @slack/bolt@3.13.1 but on Node v20.11.0. I don't think any changes were made to context.matches since this release of Bolt either.

Hello @zimeg ! Thanks for looking into it.

I am puzzled also ๐Ÿ˜… The output you showed is exactly what I have before the client call and then after I am getting this:
image

Hmm that's super strange... I don't immediately know why this is happening but have a few things I'm interested in trying.

Is it possible to upgrade to Node 18 or later? This seems to work alright in both 18 and 20, but I haven't checked if 14 has different behavior with regex in an async context. I would be surprised if it does though since capture groups have been supported for a while...

Can you also try using the client provided in the function arguments? I tested with both app.client and client with the same results, but perhaps something is going on here?

I'm also curious if capturing the regex matches in a variable before the API call, then printing after, prevents this undefined overwriting behavior from happening.

Please let me know if you have any luck with any of these!

Just saving quick docs reference for myself - https://slack.dev/bolt-js/concepts#message-listening

Thanks @zimeg for your quick answer. I have tried using client provided in the function argument and also with node v18.17.0 and there is still this overwriting behavior.

I did not dig a lot but I also tried to replace the Slack client call by some other external service call and I am getting also the same issue. So I guess it is not an issue with bolt-js itself, but maybe something strange in our own codebase..

๐Ÿ‘‹ 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.

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.