Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
// Since v3.4, WebClient starts sharing logger with App
this.clientOptions.logger = this.logger;
}

// Tag the User-Agent with the concrete receiver class before any
// WebClient is constructed. WebClient snapshots `getUserAgent()` into
// its axios headers at construction time, so this must run before
// `new WebClient(...)` below (see #1150).
const receiverTypeName = receiver
? receiver.constructor.name
: this.socketMode
? 'SocketModeReceiver'
: 'HTTPReceiver';
addAppMetadata({
name: `${packageJson.name}-${receiverTypeName}`,
version: packageJson.version,
});

// The public WebClient instance (app.client)
// Since v3.4, it can have the passed token in the case of single workspace installation.
this.client = new WebClient(token, this.clientOptions);
Expand Down
17 changes: 17 additions & 0 deletions test/unit/App/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ describe('App basic features', () => {
// TODO: tests for providing endpoints option
});

describe('receiver-type app metadata', () => {
it('should tag the user-agent metadata with the concrete receiver class name', () => {
const addAppMetadata = sinon.fake();
const customOverrides = mergeOverrides(
{ '@slack/web-api': { addAppMetadata } },
withSuccessfulBotUserFetchingWebClient(fakeBotId, fakeBotUserId),
);
const MockApp = importApp(customOverrides);
new MockApp({ receiver: new FakeReceiver(), authorize: noop });
const names: string[] = addAppMetadata.getCalls().map((call) => call.args[0].name);
assert.isTrue(
names.some((name) => name.endsWith('-FakeReceiver')),
`expected an addAppMetadata call ending in "-FakeReceiver", got ${JSON.stringify(names)}`,
);
});
});

describe('#start', () => {
it('should pass calls through to receiver', async () => {
// Arrange
Expand Down