botframework-directlinejs-tmp
Advanced tools
Comparing version 0.9.16 to 0.15.6-0
{ | ||
"name": "botframework-directlinejs-tmp", | ||
"version": "0.9.16", | ||
"description": "client library for the Microsoft Bot Framework Direct Line 3.0 protocol", | ||
"main": "built/directLine.js", | ||
"types": "built/directLine.d.ts", | ||
"version": "0.15.6-0", | ||
"description": "Client library for the Microsoft Bot Framework Direct Line 3.0 protocol", | ||
"files": [ | ||
"dist/**/*", | ||
"lib/**/*" | ||
], | ||
"main": "lib/directLine.js", | ||
"types": "lib/directLine.d.ts", | ||
"scripts": { | ||
"build": "tsc && webpack", | ||
"watch": "npm-run-all -p -r -l tsc-watch webpack-watch", | ||
"tsc-watch": "tsc -w", | ||
"webpack-watch": "webpack -w", | ||
"clean": "rm -rf built", | ||
"prepublish": "tsc && webpack --config webpack.production.config.js", | ||
"test": "mocha test" | ||
"build": "npm run build:typecheck && npm run build:babel -- --env-name test && npm run build:webpack -- --config webpack-development.config.js", | ||
"build:babel": "babel --extensions .js,.ts --ignore src/**/*.spec.js,src/**/*.spec.ts,src/**/*.test.js,src/**/*.test.ts --out-dir lib src", | ||
"build:typecheck": "tsc", | ||
"build:webpack": "webpack", | ||
"clean": "rimraf dist lib", | ||
"prepublishOnly": "npm run build:typecheck && npm run build:babel && npm run build:webpack", | ||
"start": "npm run build && concurrently --names \"babel,typecheck,webpack\" \"npm run build:babel -- --watch\" \"npm run build:typecheck -- --preserveWatchOutput --watch\" \"npm run build:webpack -- --config webpack-watch.config.js --watch\"", | ||
"test": "jest --silent", | ||
"watch": "npm run start" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://git@github.com/Microsoft/BotFramework-DirectLineJS.git" | ||
"url": "git+https://github.com/Microsoft/BotFramework-DirectLineJS.git" | ||
}, | ||
"author": "Microsoft Corp", | ||
"author": "Microsoft Corporation", | ||
"license": "MIT", | ||
"dependencies": { | ||
"rxjs": "^5.0.3" | ||
"@babel/runtime": "7.23.9", | ||
"botframework-streaming": "4.22.1", | ||
"buffer": "6.0.3", | ||
"core-js": "3.35.1", | ||
"cross-fetch": "4.0.0", | ||
"jwt-decode": "4.0.0", | ||
"rxjs": "7.8.1", | ||
"url-search-params-polyfill": "8.2.5" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^3.4.34", | ||
"@types/chai-subset": "^1.0.29", | ||
"@types/deep-freeze": "0.0.29", | ||
"chai": "^3.5.0", | ||
"chai-subset": "^1.4.0", | ||
"deep-freeze": "0.0.1", | ||
"http-server": "^0.9.0", | ||
"mocha": "^3.2.0", | ||
"npm-run-all": "^3.1.2", | ||
"source-map-loader": "^0.1.5", | ||
"ts-loader": "^1.3.3", | ||
"typescript": "^2.3.2", | ||
"webpack": "^1.14.0" | ||
"@babel/cli": "7.23.9", | ||
"@babel/core": "7.23.9", | ||
"@babel/plugin-transform-runtime": "7.23.9", | ||
"@babel/preset-env": "7.23.9", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@types/express": "4.17.21", | ||
"@types/jest": "29.5.12", | ||
"@types/jsonwebtoken": "9.0.5", | ||
"@types/node": "20.11.16", | ||
"babel-jest": "29.7.0", | ||
"babel-loader": "9.1.3", | ||
"babel-plugin-istanbul": "6.1.1", | ||
"babel-plugin-transform-inline-environment-variables": "0.4.4", | ||
"concurrently": "8.2.2", | ||
"dotenv": "16.4.1", | ||
"event-target-shim": "6.0.2", | ||
"get-port": "7.0.0", | ||
"global-agent": "3.0.0", | ||
"has-resolved": "1.1.0", | ||
"http-proxy": "1.18.1", | ||
"jest": "29.7.0", | ||
"jest-environment-jsdom": "29.7.0", | ||
"jsdom": "24.0.0", | ||
"nock": "13.5.1", | ||
"node-fetch": "3.3.2", | ||
"on-error-resume-next": "1.1.0", | ||
"restify": "11.1.0", | ||
"rimraf": "5.0.5", | ||
"simple-update-in": "2.2.0", | ||
"typescript": "5.3.3", | ||
"webpack": "5.90.1", | ||
"webpack-cli": "5.1.4", | ||
"webpack-stats-plugin": "1.1.3" | ||
} | ||
} |
142
README.md
@@ -1,5 +0,9 @@ | ||
# BotFramework-DirectLineJS | ||
![Bot Framework DirectLineJS](./docs/media/FrameWorkDirectLineJS@1x.png) | ||
Client library for the [Microsoft Bot Framework](http://www.botframework.com) *[Direct Line](https://docs.botframework.com/en-us/restapi/directline3/)* protocol. | ||
# Microsoft Bot Framework Direct Line JS Client | ||
[![Build Status](https://travis-ci.org/Microsoft/BotFramework-DirectLineJS.svg?branch=master)](https://travis-ci.org/Microsoft/BotFramework-DirectLineJS) | ||
Client library for the [Microsoft Bot Framework](http://www.botframework.com) _[Direct Line](https://docs.botframework.com/en-us/restapi/directline3/)_ protocol. | ||
Used by [WebChat](https://github.com/Microsoft/BotFramework-WebChat) and thus (by extension) [Emulator](https://github.com/Microsoft/BotFramework-Emulator), WebChat channel, and [Azure Bot Service](https://azure.microsoft.com/en-us/services/bot-service/). | ||
@@ -9,13 +13,13 @@ | ||
### *Who is this for?* | ||
### _Who is this for?_ | ||
Anyone who is building a Bot Framework JavaScript client who does not want to use [WebChat](https://github.com/Microsoft/BotFramework-WebChat). | ||
If you're currently using WebChat, you don't need to make any changes as it includes this package. | ||
If you're currently using WebChat, you don't need to make any changes as it includes this package. | ||
### *What is that funny `subscribe()` method in the samples below?* | ||
### _What is that funny `subscribe()` method in the samples below?_ | ||
Instead of callbacks or Promises, this library handles async operations using Observables. Try it, you'll like it! For more information, check out [RxJS](https://github.com/reactivex/rxjs/). | ||
### *Can I use [TypeScript](http://www.typescriptlang.com)?* | ||
### _Can I use [TypeScript](http://www.typescriptlang.com)?_ | ||
@@ -30,2 +34,18 @@ You bet. | ||
### Why the library did not detect Web Socket disconnections? | ||
On iOS/iPadOS, when network change from Wi-Fi to cellular, the `WebSocket` object will be stalled without any errors. This is not detectable nor workaroundable without any additional assistance. The issue is related to an experimental feature named "NSURLSession WebSocket". The feature is enabled by default on iOS/iPadOS 15 and up. | ||
An option named `networkInformation` can be used to assist the library to detect any connection issues. The option is based on [W3C Network Information API](https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API) and it should implement at least 2 members: | ||
- [A `type` property](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/type) to indicate the current network type | ||
- When the `type` is `"offline"`, network is not available and no connection will be made | ||
- [A `change` event](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/change_event) should dispatch when the `type` property change | ||
However, Safari on iOS/iPadOS [does not support W3C Network Information API](https://bugs.webkit.org/show_bug.cgi?id=185697). It is up to web developers to implement the `NetworkInformation` polyfill. | ||
One effective way to detect network type change is to subscribe to a [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) source. The service would send a message every 30 seconds. If network type changed and current network type is no longer available, the connection will be closed prematurely and an `error` event will be dispatched to the [`EventSource`](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) instance. Upon receiving the `error` event, the `NetworkInformation.type` should then change to `"offline"`. The browser would automatically retry the Server-Sent Events connection. Upon receiving an `open` event, the polyfill should change the `type` back to `"unknown"`. | ||
If the library is being used in a native iOS/iPadOS app, a less resource-intensive solution would be partially implementing the [Network Information API](https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API) using [`NWPathMonitor`](https://developer.apple.com/documentation/network/nwpathmonitor). When network change happens, the `NetworkInformation` instance should update the [`type` property](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/type) based on network type and dispatch a [`change` event](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/change_event). | ||
## How to build from source | ||
@@ -35,3 +55,3 @@ | ||
1. `npm install` | ||
2. `npm run build` (or `npm run watch` to rebuild on every change, or `npm run prepublish` to build production) | ||
2. `npm run build` (or `npm run watch` to rebuild on every change, or `npm run prepublishOnly` to build production) | ||
@@ -42,5 +62,4 @@ ## How to include in your app | ||
1. Build from scratch and include either `/directLine.js` (webpacked with rxjs) or `built/directline.js` in your app | ||
2. Use the unpkg CDN, e.g. `<script src="http://unpkg.com/botframework-directlinejs/directLine.js"/>` | ||
3. `npm install botframework-directlinejs` | ||
1. Build from scratch and include either `/directLine.js` (webpacked with rxjs) or `lib/directline.js` in your app | ||
2. `npm install botframework-directlinejs` | ||
@@ -51,9 +70,10 @@ ## Using from within a Node environment | ||
1. `npm install --save xhr2` | ||
1. `npm install --save ws xhr2` | ||
2. Add the following towards the top of your main application file: | ||
```typescript | ||
global.XMLHttpRequest = require("xhr2"); | ||
global.XMLHttpRequest = require('xhr2'); | ||
global.WebSocket = require('ws'); | ||
``` | ||
## How to create and use a directLine object | ||
@@ -63,5 +83,5 @@ | ||
1. If you haven't already, [register your bot](https://dev.botframework.com/bots/new). | ||
1. If you haven't already, [register your bot](https://azure.microsoft.com/en-us/services/bot-service/). | ||
2. Add a DirectLine (**not WebChat**) channel, and generate a Direct Line Secret. Make sure Direct Line 3.0 is enabled. | ||
3. For testing you can use your Direct Line Secret as a security token, but for production you will likely want to exchange that Secret for a Token as detailed in the Direct Line [documentation](https://docs.botframework.com/en-us/restapi/directline3/). | ||
3. For testing you can use your Direct Line Secret as a security token, but for production you will likely want to exchange that Secret for a Token as detailed in the Direct Line [documentation](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline?view=azure-bot-service-4.0). | ||
@@ -72,2 +92,4 @@ ### Create a DirectLine object: | ||
import { DirectLine } from 'botframework-directlinejs'; | ||
// For Node.js: | ||
// const { DirectLine } = require('botframework-directlinejs'); | ||
@@ -79,3 +101,7 @@ var directLine = new DirectLine({ | ||
webSocket: /* optional: false if you want to use polling GET to receive messages. Defaults to true (use WebSocket). */, | ||
pollingInterval: /* optional: set polling interval in milliseconds. Default to 1000 */, | ||
pollingInterval: /* optional: set polling interval in milliseconds. Defaults to 1000 */, | ||
timeout: /* optional: a timeout in milliseconds for requests to the bot. Defaults to 20000 */, | ||
conversationStartProperties: { /* optional: properties to send to the bot on conversation start */ | ||
locale: 'en-US' | ||
} | ||
}); | ||
@@ -87,10 +113,12 @@ ``` | ||
```typescript | ||
directLine.postActivity({ | ||
directLine | ||
.postActivity({ | ||
from: { id: 'myUserId', name: 'myUserName' }, // required (from.name is optional) | ||
type: 'message', | ||
text: 'a message for you, Rudy' | ||
}).subscribe( | ||
id => console.log("Posted activity, assigned ID ", id), | ||
error => console.log("Error posting activity", error) | ||
); | ||
}) | ||
.subscribe( | ||
id => console.log('Posted activity, assigned ID ', id), | ||
error => console.log('Error posting activity', error) | ||
); | ||
``` | ||
@@ -103,6 +131,3 @@ | ||
```typescript | ||
directLine.activity$ | ||
.subscribe( | ||
activity => console.log("received activity ", activity) | ||
); | ||
directLine.activity$.subscribe(activity => console.log('received activity ', activity)); | ||
``` | ||
@@ -114,6 +139,4 @@ | ||
directLine.activity$ | ||
.filter(activity => activity.type === 'message') | ||
.subscribe( | ||
message => console.log("received message ", message) | ||
); | ||
.filter(activity => activity.type === 'message') | ||
.subscribe(message => console.log('received message ', message)); | ||
``` | ||
@@ -125,6 +148,4 @@ | ||
directLine.activity$ | ||
.filter(activity => activity.type === 'message' && activity.from.id === 'yourBotHandle') | ||
.subscribe( | ||
message => console.log("received message ", message) | ||
); | ||
.filter(activity => activity.type === 'message' && activity.from.id === 'yourBotHandle') | ||
.subscribe(message => console.log('received message ', message)); | ||
``` | ||
@@ -137,15 +158,13 @@ | ||
```typescript | ||
import { ConnectionStatus } from 'botframework-directlinejs'; | ||
directLine.connectionStatus$ | ||
.subscribe(connectionStatus => { | ||
switch(connectionStatus) { | ||
case ConnectionStatus.Uninitialized: // the status when the DirectLine object is first created/constructed | ||
case ConnectionStatus.Connecting: // currently trying to connect to the conversation | ||
case ConnectionStatus.Online: // successfully connected to the converstaion. Connection is healthy so far as we know. | ||
case ConnectionStatus.ExpiredToken: // last operation errored out with an expired token. Your app should supply a new one. | ||
case ConnectionStatus.FailedToConnect: // the initial attempt to connect to the conversation failed. No recovery possible. | ||
case ConnectionStatus.Ended: // the bot ended the conversation | ||
} | ||
directLine.connectionStatus$.subscribe(connectionStatus => { | ||
switch (connectionStatus) { | ||
case ConnectionStatus.Uninitialized: // the status when the DirectLine object is first created/constructed | ||
case ConnectionStatus.Connecting: // currently trying to connect to the conversation | ||
case ConnectionStatus.Online: // successfully connected to the converstaion. Connection is healthy so far as we know. | ||
case ConnectionStatus.ExpiredToken: // last operation errored out with an expired token. Your app should supply a new one. | ||
case ConnectionStatus.FailedToConnect: // the initial attempt to connect to the conversation failed. No recovery possible. | ||
case ConnectionStatus.Ended: // the bot ended the conversation | ||
} | ||
}); | ||
@@ -159,4 +178,4 @@ ``` | ||
will change to `ConnectionStatus.ExpiredToken`. Your app can request a new token from its server, which should call | ||
the [Reconnect](https://docs.botframework.com/en-us/restapi/directline3/#reconnecting-to-a-conversation) API. | ||
The resultant Conversation object can then be passed by the app to DirectLine, which will | ||
the [Reconnect](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-reconnect-to-conversation?view=azure-bot-service-4.0) API. | ||
The resultant Conversation object can then be passed by the app to DirectLine. | ||
@@ -173,3 +192,4 @@ ```typescript | ||
**When using a secret** you can resume a conversation by: | ||
- Storing the conversationid (in a *permanent* place, like local storage) | ||
- Storing the conversationid (in a _permanent_ place, like local storage) | ||
- Giving this value back while creating the DirectLine object along with the secret | ||
@@ -187,3 +207,4 @@ | ||
**When using a token** you can resume a conversation by: | ||
- Storing the conversationid and your token (in a *permanent* place, like local storage) | ||
- Storing the conversationid and your token (in a _permanent_ place, like local storage) | ||
- Calling the DirectLine reconnect API yourself to get a refreshed token and a streamurl | ||
@@ -203,3 +224,3 @@ - Creating the DirectLine object using the ConversationId, Token, and StreamUrl | ||
**Getting any history that Direct Line has cached** : you can retrieve history using watermarks: | ||
You can see the watermark as an *activity 'bookmark'*. The resuming scenario will replay all the conversation activities from the watermark you specify. For now, this only works when using the polling version of DirectLine. | ||
You can see the watermark as an _activity 'bookmark'_. The resuming scenario will replay all the conversation activities from the watermark you specify. | ||
@@ -218,8 +239,23 @@ ```typescript | ||
*Watermark with websocket will be supported in the future.* | ||
## Contributing | ||
## Copyright & License | ||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us | ||
the rights to use your contribution. For details, visit https://cla.microsoft.com. | ||
© 2017 Microsoft Corporation | ||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide | ||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions | ||
provided by the bot. You will only need to do this once across all repos using our CLA. | ||
[MIT License](/LICENSE) | ||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide | ||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions | ||
provided by the bot. You will only need to do this once across all repos using our CLA. | ||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. | ||
## Reporting Security Issues | ||
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at [secure@microsoft.com](mailto:secure@microsoft.com). You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the [MSRC PGP](https://technet.microsoft.com/en-us/security/dn606155) key, can be found in the [Security TechCenter](https://technet.microsoft.com/en-us/security/default). | ||
Copyright (c) Microsoft Corporation. All rights reserved. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6024569
25
3340
244
8
33
1
80
1
+ Added@babel/runtime@7.23.9
+ Addedbuffer@6.0.3
+ Addedcore-js@3.35.1
+ Addedcross-fetch@4.0.0
+ Addedjwt-decode@4.0.0
+ Added@babel/runtime@7.23.9(transitive)
+ Added@types/node@10.17.60(transitive)
+ Added@types/ws@6.0.4(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbotframework-streaming@4.22.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedcore-js@3.35.1(transitive)
+ Addedcross-fetch@4.0.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedjwt-decode@4.0.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedurl-search-params-polyfill@8.2.5(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedws@7.5.10(transitive)
- Removedrxjs@5.5.12(transitive)
- Removedsymbol-observable@1.0.1(transitive)
Updatedrxjs@7.8.1