-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using directMention() documentation doesn't seem to be correct in docs #1148
Comments
Hi @O-Mutt 👋🏻 Thanks for the code sample. I was able to verify that the following const { App, directMention } = require('@slack/bolt');
// ...
app.message(directMention(), 'tell a joke', async ({ message, say }) => {
await say(`Here's a joke for you, <@${message.user}>:`);
await say(`What's Beethoven's favorite fruit?`);
await say(`Bah-Nah-Nah-Nah!`)
});
app.message(directMention(), /filter .*/, async ({ message, say }) => {
await say(`Filtering the message for you, <@${message.user}>`)
});
app.message(directMention(), /filter some message by .* text/, async ({ message, say }) => {
await say(`Filtering some message for you, <@${message.user}>`)
}); My steps for testing were:
Would you mind confirming that you're using a similar version of Bolt and following similar testing steps? |
Hey! thanks for the quick reply. The version i initially tested with was 3.6.0, sorry i neglected to mention that in the initial bug report. FWIW it may be typings related, here is a ts failure:
I did upgrade to 3.7.0 just now and received the same results. |
Reproducible in: node version: v16.9.1 Typescript Version: 4.4.3 OS version(s): macOS Monterey - 12.0.1 (21A559) app.message(directMention(), 'tell a joke', async ({ message, say }) => {
await say('TestJoke!');
}); Error:
Below is what I think is going on: It looks like the two overrides are: message(...listeners: Middleware<SlackEventMiddlewareArgs<'message'>>[]): void;
message(pattern: string | RegExp, ...listeners: Middleware<SlackEventMiddlewareArgs<'message'>>[]): void; The error is stating that signature of it looks like the overrides don't support this signature, but the actual implementation does as it's signature is: Src Definition of function implementation: By moving the the RegEx or String as the first argument, I was able to workaround this as it now fulfills the second override: app.message('test string', directMention(), async ({ say }) => {
await say('Test');
}); The only, tiny, "downside" to this that I can think of, is that technically you are doing the matchMessage(Called for matching the RegEx or String) check on every message instead of the directMention exiting early, as the string match is evaluated first, then the directMention, then your custom handler. |
Thank you for reporting the issue. It seems that this issue can arise only when using bolt-js in TypeScript. This should be improved in future releases. |
To open this method up to TypeScript users a required either removing the two existing overloads, or creating new overloads. Hopefully by providing additional overloads as well as inline documentation, this can provide assistance as well as control Fixes slackapi#1148
To open this method up to TypeScript users a required either removing the two existing overloads, or creating new overloads. Hopefully by providing additional overloads as well as inline documentation, this can provide assistance as well as control Fixes slackapi#1148
To open this method up to TypeScript users a required either removing the two existing overloads, or creating new overloads. Hopefully by providing additional overloads as well as inline documentation, this can provide assistance as well as control Fixes slackapi#1148
To open this method up to TypeScript users a required either removing the two existing overloads, or creating new overloads. Hopefully by providing additional overloads as well as inline documentation, this can provide assistance as well as control Fixes slackapi#1148
…o compile the examples in documents (#1185) To open this method up to TypeScript users a required either removing the two existing overloads, or creating new overloads. Hopefully by providing additional overloads as well as inline documentation, this can provide assistance as well as control -- Fixes #1148
Description
using directMention() middleware doesn't seem to function as the docs suggest.
app.message(directMention(), /filter some message by .* text/, ({ say }) => mapSlackIdToEmail);
produces an error:
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version:
node version:
OS version(s):
Steps to reproduce:
Expected result:
What you expected to happen
Actual result:
What actually happened
Attachments:
https://github.com/andrewdietrich/bolt-js/pull/1/files
bolt-js/examples/hubot-example/script.js
Lines 108 to 113 in 522e70b
#756
The text was updated successfully, but these errors were encountered: