Skip to content

Commit

Permalink
Added the Web Chat Version and Bundle to User Agent (#2101)
Browse files Browse the repository at this point in the history
* Added WebChat Version to BotAgent

* Minor changes to botAgent and revert misc eslint changes

* Revert eslint change

* Added warning message

* removed eslint changes

* Update packages/bundle/src/index-es5.ts

Co-Authored-By: William Wong <compulim@users.noreply.github.com>

* Update packages/bundle/src/index-minimal.ts

Co-Authored-By: William Wong <compulim@users.noreply.github.com>

* Update packages/bundle/src/index.ts

Co-Authored-By: William Wong <compulim@users.noreply.github.com>

* Added tests for createDirectLine

* Updated test description
  • Loading branch information
tdurnford authored and corinagum committed Jul 1, 2019
1 parent 3aa0279 commit 3d55e1e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 10 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- `*`: Added [`eslint`](https://npmjs.com/package/eslint/) to static code analysis, by [@compulim](https://github.com/compulim), in PR [#1970](https://github.com/microsoft/BotFramework-WebChat/pull/1970)
- Added pt-PT language, by [@bodyzatva](https://github.com/bodyzatva) in PR [#2005](https://github.com/microsoft/BotFramework-WebChat/pull/2005) and PR [#2020](https://github.com/Microsoft/BotFramework-WebChat/pull/2020)
- Added documentation for using Web Chat dev build, by [@corinagum](https://github.com/corinagum), in PR [#2074](https://github.com/Microsoft/BotFramework-WebChat/pull/2074)
- Added pt-PT language, by [@bodyzatva](https://github.com/bodyzatva) in PR [#2005](https://github.com/microsoft/BotFramework-WebChat/pull/2005) and PR [#2020](https://github.com/Microsoft/BotFramework-WebChat/pull/2020)
- Added documentation for using Web Chat dev build, by [@corinagum](https://github.com/corinagum), in PR [#2074](https://github.com/Microsoft/BotFramework-WebChat/pull/2074)
- Added the Web Chat version to DirectLine's botAgent option, by [@tdurnford](https://github.com/tdurnford), in PR [#2101](https://github.com/Microsoft/BotFramework-WebChat/pull/2101)

### Changed

Expand Down Expand Up @@ -59,10 +60,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix [#1627](https://github.com/Microsoft/BotFramework-WebChat/issues/1627). Fixed timestamps randomly stopped from updating, by [@compulim](https://github.com/compulim) in PR [#2090](https://github.com/Microsoft/BotFramework-WebChat/pull/2090)
- Fix [#2001](https://github.com/Microsoft/BotFramework-WebChat/issues/2001). Strip Markdown from ARIA labels, so screen readers do not speak Markdown in text, by [@corinagum](https://github.com/corinagum) in PR [#2096](https://github.com/Microsoft/BotFramework-WebChat/pull/2096)
- Fix [#1926](https://github.com/microsoft/BotFramework-WebChat/issues/1926). Fixed scroll stickiness issue when submitting an Adaptive Card form with suggested actions opened, by [@compulim](https://github.com/compulim) in PR [#2107](https://github.com/microsoft/BotFramework-WebChat/pull/2107)
- Fix [#2106](https://github.com/Microsoft/BotFramework-WebChat/issues/2016). Fix AdaptiveCardHostConfig warning associated with the CommonCard component, by [@tdurnford](https://github.com/tdurnford) in PR [#2108](https://github.com/Microsoft/BotFramework-WebChat/pull/2108)
- Fix [#2110](https://github.com/Microsoft/BotFramework-WebChat/issues/2110). Fixed sendBox input/textarea background color issue, by [@tdurnford](https://github.com/johndoe) in PR [#2111](https://github.com/Microsoft/BotFramework-WebChat/pull/2111)
- Fix [#2104](https://github.com/Microsoft/BotFramework-WebChat/issues/2104). Remove deprecated `/master/webchat\*\*.js links from samples, by [@corinagum](https://github.com/corinagum) in PR [#2105](https://github.com/Microsoft/BotFramework-WebChat/pull/2105)
- Fix [#2104](https://github.com/Microsoft/BotFramework-WebChat/issues/2104). Remove deprecated `/master/webchat**.js` links from samples, by [@corinagum](https://github.com/corinagum) in PR [#2105](https://github.com/Microsoft/BotFramework-WebChat/pull/2105)
- Fix [#1863](https://github.com/Microsoft/BotFramework-WebChat/issues/1863). Remove title, subtitle, and text of cards from being spoken by [@corinagum](https://github.com/corinagum) in PR [#2118](https://github.com/Microsoft/BotFramework-WebChat/pull/2118)
- Fix [#2106](https://github.com/Microsoft/BotFramework-WebChat/issues/2016). Fix `AdaptiveCardHostConfig` warning associated with the `CommonCard` component, by [@tdurnford](https://github.com/tdurnford) in PR [#2108](https://github.com/Microsoft/BotFramework-WebChat/pull/2108)

### Samples

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"lcov",
"text-summary"
],
"globals": {
"VERSION": "0.0.0-0"
},
"moduleDirectories": [
"node_modules",
"packages"
Expand Down
30 changes: 30 additions & 0 deletions packages/bundle/src/__tests__/createDirectLine.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
jest.mock('botframework-directlinejs', () => {
class DirectLine {
constructor({ botAgent }) {
this.botAgent = botAgent;
}
}

return { DirectLine };
});

import * as WebChatFull from '../index';
import * as WebChatMinimal from '../index-minimal';
import * as WebChatES5 from '../index-es5';

describe('Web Chat createDirectLine', () => {
it('for full bundle', () => {
const directLine = WebChatFull.createDirectLine({});
expect(directLine.botAgent).toBe(`WebChat/${WebChatFull.version} (Full)`);
});

it('for minimal bundle', () => {
const directLine = WebChatMinimal.createDirectLine({});
expect(directLine.botAgent).toBe(`WebChat/${WebChatMinimal.version} (Minimal)`);
});

it('for ES5 bundle', () => {
const directLine = WebChatES5.createDirectLine({});
expect(directLine.botAgent).toBe(`WebChat/${WebChatES5.version} (ES5)`);
});
});
3 changes: 2 additions & 1 deletion packages/bundle/src/createDirectLine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DirectLine } from 'botframework-directlinejs';

export default function createDirectLine({
botAgent,
conversationId,
domain,
fetch,
Expand All @@ -12,6 +13,7 @@ export default function createDirectLine({
webSocket
}) {
return new DirectLine({
botAgent,
conversationId,
domain,
fetch,
Expand All @@ -21,7 +23,6 @@ export default function createDirectLine({
token,
watermark,
webSocket,
botAgent: 'webchat',
createFormData: attachments => {
const formData = new FormData();

Expand Down
20 changes: 19 additions & 1 deletion packages/bundle/src/index-es5.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
// window['WebChat'] is required for TypeScript

// Polyfills for IE11 and other ES5 browsers
// To maintain quality, we prefer polyfills without additives
// For example, we prefer Promise implementation from "core-js" than "bluebird"

import 'core-js/modules/es6.array.find-index';
import 'core-js/modules/es6.array.find';
import 'core-js/modules/es6.array.iterator';
Expand All @@ -13,9 +17,23 @@ import 'core-js/modules/es6.symbol';
import 'core-js/modules/es7.array.includes';
import 'url-search-params-polyfill';
import 'whatwg-fetch';

import { version } from './index-minimal';
import addVersion from './addVersion';
import defaultCreateDirectLine from './createDirectLine';

export * from './index';

export const createDirectLine = options => {
options.botAgent &&
console.warn(
'Web Chat: Developers are not currently allowed to set botAgent in the createDirectLine function. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
);
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (ES5)` });
};

window['WebChat'] = {
...window['WebChat'],
createDirectLine
};

addVersion('full-es5');
16 changes: 12 additions & 4 deletions packages/bundle/src/index-minimal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
// window['WebChat'] is required for TypeScript

import { Constants, createStore } from 'botframework-webchat-core';
import { Constants, createStore, version } from 'botframework-webchat-core';

import ReactWebChat, {
Components,
Expand All @@ -13,10 +13,18 @@ import ReactWebChat, {
import addVersion from './addVersion';
import coreRenderWebChat from './renderWebChat';
import createBrowserWebSpeechPonyfillFactory from './createBrowserWebSpeechPonyfillFactory';
import createDirectLine from './createDirectLine';
import defaultCreateDirectLine from './createDirectLine';

const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);

export const createDirectLine = options => {
options.botAgent &&
console.warn(
'Web Chat: Developers are not currently allowed to set botAgent in the createDirectLine function. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
);
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (Minimal)` });
};

export default ReactWebChat;

export {
Expand All @@ -25,10 +33,10 @@ export {
connectToWebChat,
Constants,
createBrowserWebSpeechPonyfillFactory,
createDirectLine,
createStore,
createStyleSet,
renderWebChat
renderWebChat,
version
};

window['WebChat'] = {
Expand Down
11 changes: 11 additions & 0 deletions packages/bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@

export * from './index-minimal';

import { version } from './index-minimal';
import addVersion from './addVersion';
import coreRenderWebChat from './renderWebChat';
import createCognitiveServicesBingSpeechPonyfillFactory from './createCognitiveServicesBingSpeechPonyfillFactory';
import createCognitiveServicesSpeechServicesPonyfillFactory from './createCognitiveServicesSpeechServicesPonyfillFactory';
import createStyleSet from './adaptiveCards/Styles/createStyleSetWithAdaptiveCards';
import defaultCreateDirectLine from './createDirectLine';
import ReactWebChat from './FullReactWebChat';
import renderMarkdown from './renderMarkdown';

const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);

export const createDirectLine = options => {
options.botAgent &&
console.warn(
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
);
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (Full)` });
};

export default ReactWebChat;

export {
Expand All @@ -27,6 +37,7 @@ window['WebChat'] = {
...window['WebChat'],
createCognitiveServicesBingSpeechPonyfillFactory,
createCognitiveServicesSpeechServicesPonyfillFactory,
createDirectLine,
createStyleSet,
ReactWebChat,
renderMarkdown,
Expand Down

0 comments on commit 3d55e1e

Please sign in to comment.