botframework-directlinejs 0.15.5-master.21a5787 → 0.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,23 +6,23 @@
6
6
 
7
7
  [![Build Status](https://travis-ci.org/Microsoft/BotFramework-DirectLineJS.svg?branch=master)](https://travis-ci.org/Microsoft/BotFramework-DirectLineJS)
8
8
 
9
- Client library for the [Microsoft Bot Framework](http://www.botframework.com) *[Direct Line](https://docs.botframework.com/en-us/restapi/directline3/)* protocol.
9
+ Client library for the [Microsoft Bot Framework](http://www.botframework.com) _[Direct Line](https://docs.botframework.com/en-us/restapi/directline3/)_ protocol.
10
10
 
11
11
  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/).
12
12
 
13
13
  ## FAQ
14
14
 
15
- ### *Who is this for?*
15
+ ### _Who is this for?_
16
16
 
17
17
  Anyone who is building a Bot Framework JavaScript client who does not want to use [WebChat](https://github.com/Microsoft/BotFramework-WebChat).
18
18
 
19
19
  If you're currently using WebChat, you don't need to make any changes as it includes this package.
20
20
 
21
- ### *What is that funny `subscribe()` method in the samples below?*
21
+ ### _What is that funny `subscribe()` method in the samples below?_
22
22
 
23
23
  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/).
24
24
 
25
- ### *Can I use [TypeScript](http://www.typescriptlang.com)?*
25
+ ### _Can I use [TypeScript](http://www.typescriptlang.com)?_
26
26
 
27
27
  You bet.
28
28
 
@@ -32,6 +32,22 @@ This is an official Microsoft-supported library, and is considered largely compl
32
32
 
33
33
  That said, the public API is still subject to change.
34
34
 
35
+ ### Why the library did not detect Web Socket disconnections?
36
+
37
+ 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.
38
+
39
+ 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:
40
+
41
+ - [A `type` property](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/type) to indicate the current network type
42
+ - When the `type` is `"offline"`, network is not available and no connection will be made
43
+ - [A `change` event](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/change_event) should dispatch when the `type` property change
44
+
45
+ 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.
46
+
47
+ 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"`.
48
+
49
+ 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).
50
+
35
51
  ## How to build from source
36
52
 
37
53
  0. Clone this repo
@@ -88,14 +104,16 @@ var directLine = new DirectLine({
88
104
  ### Post activities to the bot:
89
105
 
90
106
  ```typescript
91
- directLine.postActivity({
107
+ directLine
108
+ .postActivity({
92
109
  from: { id: 'myUserId', name: 'myUserName' }, // required (from.name is optional)
93
110
  type: 'message',
94
111
  text: 'a message for you, Rudy'
95
- }).subscribe(
96
- id => console.log("Posted activity, assigned ID ", id),
97
- error => console.log("Error posting activity", error)
98
- );
112
+ })
113
+ .subscribe(
114
+ id => console.log('Posted activity, assigned ID ', id),
115
+ error => console.log('Error posting activity', error)
116
+ );
99
117
  ```
100
118
 
101
119
  You can also post messages with attachments, and non-message activities such as events, by supplying the appropriate fields in the activity.
@@ -103,30 +121,23 @@ You can also post messages with attachments, and non-message activities such as
103
121
  ### Listen to activities sent from the bot:
104
122
 
105
123
  ```typescript
106
- directLine.activity$
107
- .subscribe(
108
- activity => console.log("received activity ", activity)
109
- );
124
+ directLine.activity$.subscribe(activity => console.log('received activity ', activity));
110
125
  ```
111
126
 
112
127
  You can use RxJS operators on incoming activities. To see only message activities:
113
128
 
114
129
  ```typescript
115
130
  directLine.activity$
116
- .filter(activity => activity.type === 'message')
117
- .subscribe(
118
- message => console.log("received message ", message)
119
- );
131
+ .filter(activity => activity.type === 'message')
132
+ .subscribe(message => console.log('received message ', message));
120
133
  ```
121
134
 
122
135
  Direct Line will helpfully send your client a copy of every sent activity, so a common pattern is to filter incoming messages on `from`:
123
136
 
124
137
  ```typescript
125
138
  directLine.activity$
126
- .filter(activity => activity.type === 'message' && activity.from.id === 'yourBotHandle')
127
- .subscribe(
128
- message => console.log("received message ", message)
129
- );
139
+ .filter(activity => activity.type === 'message' && activity.from.id === 'yourBotHandle')
140
+ .subscribe(message => console.log('received message ', message));
130
141
  ```
131
142
 
132
143
  ### Monitor connection status
@@ -134,19 +145,17 @@ directLine.activity$
134
145
  Subscribing to either `postActivity` or `activity$` will start the process of connecting to the bot. Your app can listen to the connection status and react appropriately :
135
146
 
136
147
  ```typescript
137
-
138
148
  import { ConnectionStatus } from 'botframework-directlinejs';
139
149
 
140
- directLine.connectionStatus$
141
- .subscribe(connectionStatus => {
142
- switch(connectionStatus) {
143
- case ConnectionStatus.Uninitialized: // the status when the DirectLine object is first created/constructed
144
- case ConnectionStatus.Connecting: // currently trying to connect to the conversation
145
- case ConnectionStatus.Online: // successfully connected to the converstaion. Connection is healthy so far as we know.
146
- case ConnectionStatus.ExpiredToken: // last operation errored out with an expired token. Your app should supply a new one.
147
- case ConnectionStatus.FailedToConnect: // the initial attempt to connect to the conversation failed. No recovery possible.
148
- case ConnectionStatus.Ended: // the bot ended the conversation
149
- }
150
+ directLine.connectionStatus$.subscribe(connectionStatus => {
151
+ switch (connectionStatus) {
152
+ case ConnectionStatus.Uninitialized: // the status when the DirectLine object is first created/constructed
153
+ case ConnectionStatus.Connecting: // currently trying to connect to the conversation
154
+ case ConnectionStatus.Online: // successfully connected to the converstaion. Connection is healthy so far as we know.
155
+ case ConnectionStatus.ExpiredToken: // last operation errored out with an expired token. Your app should supply a new one.
156
+ case ConnectionStatus.FailedToConnect: // the initial attempt to connect to the conversation failed. No recovery possible.
157
+ case ConnectionStatus.Ended: // the bot ended the conversation
158
+ }
150
159
  });
151
160
  ```
152
161
 
@@ -168,7 +177,8 @@ directLine.reconnect(conversation);
168
177
  When using DirectLine with WebChat, closing the current tab or refreshing the page will create a new conversation in most cases. You can resume an existing conversation to keep the user in the same context.
169
178
 
170
179
  **When using a secret** you can resume a conversation by:
171
- - Storing the conversationid (in a *permanent* place, like local storage)
180
+
181
+ - Storing the conversationid (in a _permanent_ place, like local storage)
172
182
  - Giving this value back while creating the DirectLine object along with the secret
173
183
 
174
184
  ```typescript
@@ -181,7 +191,8 @@ const dl = new DirectLine({
181
191
  ```
182
192
 
183
193
  **When using a token** you can resume a conversation by:
184
- - Storing the conversationid and your token (in a *permanent* place, like local storage)
194
+
195
+ - Storing the conversationid and your token (in a _permanent_ place, like local storage)
185
196
  - Calling the DirectLine reconnect API yourself to get a refreshed token and a streamurl
186
197
  - Creating the DirectLine object using the ConversationId, Token, and StreamUrl
187
198
 
@@ -196,7 +207,7 @@ const dl = new DirectLine({
196
207
  ```
197
208
 
198
209
  **Getting any history that Direct Line has cached** : you can retrieve history using watermarks:
199
- You can see the watermark as an *activity 'bookmark'*. The resuming scenario will replay all the conversation activities from the watermark you specify.
210
+ You can see the watermark as an _activity 'bookmark'_. The resuming scenario will replay all the conversation activities from the watermark you specify.
200
211
 
201
212
  ```typescript
202
213
  import { DirectLine } from 'botframework-directlinejs';
@@ -212,7 +223,7 @@ const dl = new DirectLine({
212
223
 
213
224
  ## Contributing
214
225
 
215
- This project welcomes contributions and suggestions. Most contributions require you to agree to a
226
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
216
227
  Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
217
228
  the rights to use your contribution. For details, visit https://cla.microsoft.com.
218
229
 
@@ -228,6 +239,7 @@ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.
228
239
  contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
229
240
 
230
241
  ## Reporting Security Issues
242
+
231
243
  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).
232
244
 
233
245
  Copyright (c) Microsoft Corporation. All rights reserved.