Skip to content
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

Closed
5 of 10 tasks
O-Mutt opened this issue Oct 8, 2021 · 4 comments · Fixed by #1185
Closed
5 of 10 tasks

using directMention() documentation doesn't seem to be correct in docs #1148

O-Mutt opened this issue Oct 8, 2021 · 4 comments · Fixed by #1185
Assignees
Labels
area:examples issues related to example or sample code docs M-T: Documentation work only question M-T: User needs support to use the project TypeScript-specific
Milestone

Comments

@O-Mutt
Copy link

O-Mutt commented Oct 8, 2021

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:

  Overload 1 of 2, '(...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'Middleware<SlackEventMiddlewareArgs<"message">>'.
  Overload 2 of 2, '(pattern: string | RegExp, ...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.
    Argument of type 'Middleware<SlackEventMiddlewareArgs<"message">>' is not assignable to parameter of type 'string | RegExp'.
      Type 'Middleware<SlackEventMiddlewareArgs<"message">>' is missing the following properties from type 'RegExp': exec, test, source, global, and 13 more.ts(2769)

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.

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

app.message(
directMention(),
'what is the answer to the ultimate question of life',
({ say }) => {
if (answer) { say(`${answer}, but what is the question?`); }
});

#756

@O-Mutt O-Mutt changed the title using directMention() documentation doesn't seem to be correct using directMention() documentation doesn't seem to be correct in docs Oct 8, 2021
@mwbrooks mwbrooks added area:examples issues related to example or sample code question M-T: User needs support to use the project docs M-T: Documentation work only labels Oct 8, 2021
@mwbrooks
Copy link
Member

mwbrooks commented Oct 8, 2021

Hi @O-Mutt 👋🏻

Thanks for the code sample.

I was able to verify that the following directMention() examples work on my local system, including your code sample. I'm curious, what version of Bolt are you using?

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:

  1. npm install --save @slack/[email protected]
  2. Invite the bot to a channel
  3. Directly mention the bot: @Bolt Local App filter some message by this text

Would you mind confirming that you're using a similar version of Bolt and following similar testing steps?

@O-Mutt
Copy link
Author

O-Mutt commented Oct 8, 2021

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:

npm start

> [email protected] start /Users/o-mutt/source/code-bolt
> ts-node app.ts

/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:692
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/migrations.ts:19:1 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'Middleware<SlackEventMiddlewareArgs<"message">>'.
  Overload 2 of 2, '(pattern: string | RegExp, ...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.
    Argument of type 'Middleware<SlackEventMiddlewareArgs<"message">>' is not assignable to parameter of type 'string | RegExp'.
      Type 'Middleware<SlackEventMiddlewareArgs<"message">>' is missing the following properties from type 'RegExp': exec, test, source, global, and 13 more.

19 app.message(directMention(), 'map all slackIds to slackEmail', mapSlackIdToEmail);
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    at createTSError (/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:692:12)
    at reportTSError (/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:696:19)
    at getOutput (/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:883:36)
    at Object.compile (/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:1185:30)
    at Module.m._compile (/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:1309:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/o-mutt/source/code-bolt/node_modules/ts-node/src/index.ts:1313:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  diagnosticText: '\x1B[96msrc/migrations.ts\x1B[0m:\x1B[93m19\x1B[0m:\x1B[93m1\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2769: \x1B[0mNo overload matches this call.\n' +
    `  Overload 1 of 2, '(...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.\n` +
    `    Argument of type 'string' is not assignable to parameter of type 'Middleware<SlackEventMiddlewareArgs<"message">>'.\n` +
    `  Overload 2 of 2, '(pattern: string | RegExp, ...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.\n` +
    `    Argument of type 'Middleware<SlackEventMiddlewareArgs<"message">>' is not assignable to parameter of type 'string | RegExp'.\n` +
    `      Type 'Middleware<SlackEventMiddlewareArgs<"message">>' is missing the following properties from type 'RegExp': exec, test, source, global, and 13 more.\n` +
    '\n' +
    "\x1B[7m19\x1B[0m app.message(directMention(), 'map all slackIds to slackEmail', mapSlackIdToEmail);\n" +
    '\x1B[7m  \x1B[0m \x1B[91m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\x1B[0m\n' +
    '\n',
  diagnosticCodes: [ 2769 ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `ts-node app.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/o-mutt/.npm/_logs/2021-10-08T18_59_16_149Z-debug.log

I did upgrade to 3.7.0 just now and received the same results.

@M1kep
Copy link
Contributor

M1kep commented Oct 28, 2021

Reproducible in:
package version:3.7.0

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:

TS2769: No overload matches this call.   Overload 1 of 2, '(...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.     Argument of type 'string' is not assignable to parameter of type 'Middleware<SlackEventMiddlewareArgs<"message">>'.   Overload 2 of 2, '(pattern: string | RegExp, ...listeners: Middleware<SlackEventMiddlewareArgs<"message">>[]): void', gave the following error.     Argument of type 'Middleware<SlackEventMiddlewareArgs<"message">>' is not assignable to parameter of type 'string | RegExp'.       Type 'Middleware<SlackEventMiddlewareArgs<"message">>' is missing the following properties from type 'RegExp': exec, test, source, global, and 13 more

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 (Middleware<SlackEventMiddlewareArgs<'message'>>, string, Middleware<SlackEventMiddlewareArgs<'message'>>) does not match any of the overrides.

it looks like the overrides don't support this signature, but the actual implementation does as it's signature is:
...patternsOrMiddleware: (string | RegExp | Middleware<SlackEventMiddlewareArgs<'message'>>)[]

Src Definition of function implementation:
https://github.com/slackapi/bolt-js/blob/main/src/App.ts#L548-L561
Bolt v3.7 App.d.ts:
image

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.

@seratch seratch added this to the 3.9.0 milestone Oct 29, 2021
@seratch
Copy link
Member

seratch commented Oct 29, 2021

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.

M1kep added a commit to M1kep/bolt-js that referenced this issue Oct 29, 2021
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
M1kep added a commit to M1kep/bolt-js that referenced this issue Oct 29, 2021
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
M1kep added a commit to M1kep/bolt-js that referenced this issue Oct 29, 2021
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
M1kep added a commit to M1kep/bolt-js that referenced this issue Nov 1, 2021
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
@seratch seratch modified the milestones: 3.9.0, 3.8.0 Nov 1, 2021
seratch pushed a commit that referenced this issue Nov 2, 2021
…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
@seratch seratch self-assigned this Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:examples issues related to example or sample code docs M-T: Documentation work only question M-T: User needs support to use the project TypeScript-specific
Projects
None yet
4 participants