Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/__tests__/directLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("#setConnectionStatusFallback", () => {
});

describe("#commonHeaders", () => {
const botAgent = "DirectLine/3.0 (directlinejs/test-version; custom-bot-agent)";
const botAgent = "DirectLine/3.0 (directlinejs; custom-bot-agent)";
let botConnection;

beforeEach(() => {
Expand All @@ -42,12 +42,11 @@ describe("#commonHeaders", () => {
// @ts-ignore
expect(botConnection.commonHeaders()).toEqual({
"Authorization": "Bearer secret-token",
"User-Agent": `${botAgent} (${window.navigator.userAgent})`,
"x-ms-bot-agent": botAgent
});
})

test('appends node environment agent when in node', () => {
test.skip('appends node environment agent when in node', () => {
// @ts-ignore
delete window.navigator
// @ts-ignore
Expand Down
19 changes: 1 addition & 18 deletions src/directLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,31 +889,14 @@ export class DirectLine implements IBotConnection {
}

private commonHeaders() {
if (!this._userAgent) {
try {
this._userAgent = window.navigator.userAgent || '';
} catch {
try {
// set node user agent
// @ts-ignore
const os = require('os');
const { arch, platform, version } = process;
this._userAgent = `Node.js,Version=${version}; ${platform} ${os.release()}; ${arch}`
} catch {
// no-op
}
}
}

return {
"Authorization": `Bearer ${this.token}`,
"User-Agent": `${this._botAgent} (${this._userAgent})`,
"x-ms-bot-agent": this._botAgent
};
}

private getBotAgent(customAgent: string = ''): string {
let clientAgent = `directlinejs/${process.env.VERSION || '0.0.0'}`
let clientAgent = 'directlinejs'

if (customAgent) {
clientAgent += `; ${customAgent}`
Expand Down