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

[Feature] Expose the WebClient to make other REST API calls #282

Open
bneigher opened this issue Jan 27, 2023 · 10 comments
Open

[Feature] Expose the WebClient to make other REST API calls #282

bneigher opened this issue Jan 27, 2023 · 10 comments

Comments

@bneigher
Copy link
Contributor

Hello, just wondering if it's possible to add a getter to the SlackService to allow the application to get a hold of the WebClient instance? I want to use it to make calls to users apis (lookupByEmail for example)

Doesn't seem to be a way to do this without installing @slack/web-api and making an external instance of the WebClient

Love the repo!

@simenandre
Copy link
Member

Thanks for posting this.

I love the idea of exposing the WebClient instance, for sure! Do you have an idea for how the API could look like?

@simenandre
Copy link
Member

#271 might be relevant here as well?

@bneigher
Copy link
Contributor Author

bneigher commented Jan 27, 2023

it's similar, but why not just allow for a getter like follows:

Just expose client instance on the class, where class is the WebClient. in this way we can just use all of the sdk modules like so:

import { Injectable } from '@nestjs/common'
import { SlackService } from 'nestjs-slack'

@Injectable()
export class MyService {
  constructor(
    private slackService: SlackService
  ) {}

async myFunction(email) {
  const userResponse = await this.slackService.client.users.lookupByEmail(<>) // .client
  return userResponse.user
}

I can see about making a MR if you think this approach is OK

@bneigher
Copy link
Contributor Author

bneigher commented Jan 27, 2023

I think all that needs to change is making client public actually:

export declare class SlackService<C = Channels> {
    private readonly options: SlackConfig;
    public readonly client: WebClient; // <-- HERE
    private readonly log: LogSync;
    constructor(options: SlackConfig, client: WebClient | null, log: LogSync | null);
    sendText(text: string, opts?: Omit<SlackMessageOptions<C>, 'text' | 'blocks'>): Promise<void>;
    sendBlocks(blocks: Readonly<SlackBlockDto>[], opts?: Omit<SlackMessageOptions<C>, 'blocks'>): Promise<void>;
    postMessage(req: SlackMessageOptions<C>): Promise<void>;
    private runApiRequest;
    private runWebhookRequest;
    private runStdoutRequest;
    private runGoogleLoggingRequest;
}

@simenandre
Copy link
Member

I like it! Let's try and see how that would look :)

Would love to see a MR/PR :)

@bneigher
Copy link
Contributor Author

#283

@bneigher
Copy link
Contributor Author

@cobraz 🙏

@bneigher
Copy link
Contributor Author

I think the double ^^ in your package.json is preventing me from installing the module directly from the repo:

❯ npm i --save https://github.com/bjerkio/nestjs-slack.git
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /Users/benneigher/.nvm/versions/node/v18.12.1/bin/node /Users/benneigher/.nvm/versions/node/v18.12.1/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/benneigher/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code EINVALIDTAGNAME
npm ERR! npm ERR! Invalid tag name "^^9.0.0" of package "@nestjs/platform-express@^^9.0.0": Tags may not have any characters that encodeURIComponent encodes.
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /Users/benneigher/.npm/_logs/2023-01-31T19_28_09_518Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/benneigher/.npm/_logs/2023-01-31T19_27_59_836Z-debug-0.log

Specifically this line in package.json @nestjs/platform-express@^^9.0.0

@bneigher
Copy link
Contributor Author

bneigher commented Feb 2, 2023

alternatively -- if you published a new release to npm I will be out of your hair! Putting together a release and would prefer using the nestjs module over the slack sdk manually. much appreciated 🙏

@zindont
Copy link

zindont commented Nov 7, 2023

+1 on publish a new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants