webclient-factory.ts 876 B

123456789101112131415161718192021222324252627
  1. import { LogLevel, WebClient, WebClientOptions } from '@slack/web-api';
  2. const isProduction = process.env.NODE_ENV === 'production';
  3. const logLevel: LogLevel = isProduction ? LogLevel.DEBUG : LogLevel.INFO;
  4. /**
  5. * Generate WebClilent instance
  6. * @param token
  7. * @param serverUri Slack Bot Token or Proxy Server URI
  8. * @param headers
  9. */
  10. export function generateWebClient(token?: string, serverUri?: string, headers?:{[key:string]:string}): WebClient;
  11. /**
  12. * Generate WebClilent instance
  13. * @param token
  14. * @param opts
  15. */
  16. export function generateWebClient(token?: string, opts?: WebClientOptions): WebClient;
  17. export function generateWebClient(token?: string, ...args: any[]): WebClient {
  18. if (typeof args[0] === 'string') {
  19. return new WebClient(token, { logLevel, slackApiUrl: args[0], headers: args[1] });
  20. }
  21. return new WebClient(token, { logLevel, ...args });
  22. }