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

SlackEventMiddlewareArgs<"app_home_opened"> Type Missing client: WebClient #1244

Closed
5 of 10 tasks
zaclittleberry opened this issue Dec 13, 2021 · 3 comments
Closed
5 of 10 tasks
Labels
auto-triage-stale question M-T: User needs support to use the project TypeScript-specific

Comments

@zaclittleberry
Copy link

Description

When trying to use the listeners for app.event("app_home_opened", I can't access client from the middleware args because it is missing from the typing. (If I console.log the args as an object I can see client). The views.publish example code references using client from the middleware args: https://api.slack.com/methods/views.publish/code

Other examples from slack reference using app.client.views.publish, which is accessible, but results in a not_authd error from the web api. This might be because I have split my receiver initialization and my app installation (since I am incorporating bolt into an existing express api).

Ultimately, I would just like for client: WebClient to be added to the type.

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: 3.8.1

node version: v14.16.1

OS version(s):

Steps to reproduce:

  1. Use @slack/bolt with typescript
  2. implement the app.event("app_home_opened" listener.
  3. try and access client from the listener args and see a typescript error

Expected result:

client should be accessible and be of type WebClient

Actual result:

client not part of the declared type.

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

@seratch seratch added question M-T: User needs support to use the project TypeScript-specific labels Dec 14, 2021
@seratch
Copy link
Member

seratch commented Dec 14, 2021

Hi @zaclittleberry, thanks for asking the question!

To define your listener functions outside the app.event method arguments, you can go withe either of the following two approaches. I would recommend the first one in favor of simplicity:

const handler: Middleware<SlackEventMiddlewareArgs<'app_home_opened'>> = async ({ client }) => {
  await client.auth.test();
};

app.event("app_home_opened", handler);

const handler2 = async ({ client }: SlackEventMiddlewareArgs<'app_home_opened'> & AllMiddlewareArgs): Promise<void> => {
  await client.auth.test();
};

app.event("app_home_opened", handler2);

Other examples from slack reference using app.client.views.publish, which is accessible, but results in a not_authd error from the web api. This might be because I have split my receiver initialization and my app installation (since I am incorporating bolt into an existing express api).

This sounds like a bit different issue. If your web API call receives not_authed error code in a response, that means that your API call does not have any access token for the call (if the token is invalid, you'll see invalid_auth instead).

If you don't use the client: WebClient in a listener argument list (the client as listener argument always holds a valid token resolved by authorize function), your code needs to manually set a valid token either when instantiating a WebClient instance or when performing an API call like client.views.publish({ token: 'valid-token', view: ... }).

I hope this helps!

@github-actions
Copy link

👋 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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-stale question M-T: User needs support to use the project TypeScript-specific
Projects
None yet
Development

No branches or pull requests

2 participants