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

Fix for #221 Allow custom WebClient options #228

Merged
merged 6 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import rewiremock from 'rewiremock';
import { ErrorCode } from './errors';
import { Receiver, ReceiverEvent, SayFn, NextMiddleware } from './types';
import { ConversationStore } from './conversation-store';
import { LogLevel } from '@slack/logger';

describe('App', () => {
describe('constructor', () => {
Expand Down Expand Up @@ -155,6 +156,32 @@ describe('App', () => {
assert(fakeConversationContext.firstCall.calledWith(dummyConvoStore));
});
});
it('with clientOptions', async () => {
const fakeConstructor = sinon.fake()
const overrides = mergeOverrides(
withNoopAppMetadata(),
{
'@slack/web-api': {
WebClient: class {
constructor() {
fakeConstructor(...arguments)
}
},
}
}
)
const App = await importApp(overrides);

const clientOptions = { slackApiUrl: 'proxy.slack.com' };
new App({ authorize: noopAuthorize, signingSecret: '', logLevel: LogLevel.ERROR, clientOptions });

assert.ok(fakeConstructor.called);

const [token, options] = fakeConstructor.lastCall.args;
assert.strictEqual(undefined, token, 'token should be undefined');
assert.strictEqual(clientOptions.slackApiUrl, options.slackApiUrl);
assert.strictEqual(LogLevel.ERROR, options.logLevel, 'override logLevel');
})
// TODO: tests for ignoreSelf option
// TODO: tests for logger and logLevel option
// TODO: tests for providing botId and botUserId options
Expand Down
11 changes: 8 additions & 3 deletions src/App.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import util from 'util';
import { WebClient, ChatPostMessageArguments, addAppMetadata } from '@slack/web-api';
import { WebClient, ChatPostMessageArguments, addAppMetadata, WebClientOptions } from '@slack/web-api';
import { Logger, LogLevel, ConsoleLogger } from '@slack/logger';
import ExpressReceiver, { ExpressReceiverOptions } from './ExpressReceiver';
import {
Expand Down Expand Up @@ -50,6 +50,7 @@ export interface AppOptions {
logger?: Logger;
logLevel?: LogLevel;
ignoreSelf?: boolean;
clientOptions?: WebClientOptions;
}

export { LogLevel, Logger } from '@slack/logger';
Expand Down Expand Up @@ -127,14 +128,18 @@ export default class App {
logger = new ConsoleLogger(),
logLevel = LogLevel.INFO,
ignoreSelf = true,
clientOptions = undefined,
}: AppOptions = {}) {

this.logger = logger;
this.logger.setLevel(logLevel);
this.errorHandler = defaultErrorHandler(this.logger);

// TODO: other webclient options (such as proxy)
this.client = new WebClient(undefined, { logLevel });
let options = { logLevel };
if (clientOptions !== undefined) {
options = { ...clientOptions, ...options };
}
this.client = new WebClient(undefined, options);

if (token !== undefined) {
if (authorize !== undefined) {
Expand Down