botframework-webchat-core 4.14.1 → 4.15.2-main.20220413.af6e8a3

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.
Files changed (238) hide show
  1. package/.eslintrc.yml +4 -198
  2. package/.prettierrc.yml +1 -1
  3. package/babel.config.json +1 -1
  4. package/lib/actions/clearSuggestedActions.js +1 -1
  5. package/lib/actions/connect.js +1 -1
  6. package/lib/actions/connectionStatusUpdate.js +1 -1
  7. package/lib/actions/deleteActivity.d.ts +13 -0
  8. package/lib/actions/deleteActivity.d.ts.map +1 -0
  9. package/lib/actions/deleteActivity.js +5 -3
  10. package/lib/actions/disconnect.js +1 -1
  11. package/lib/actions/dismissNotification.js +1 -1
  12. package/lib/actions/emitTypingIndicator.js +1 -1
  13. package/lib/actions/incomingActivity.d.ts +14 -0
  14. package/lib/actions/incomingActivity.d.ts.map +1 -0
  15. package/lib/actions/incomingActivity.js +5 -3
  16. package/lib/actions/markActivity.d.ts +17 -0
  17. package/lib/actions/markActivity.d.ts.map +1 -0
  18. package/lib/actions/markActivity.js +5 -3
  19. package/lib/actions/postActivity.d.ts +52 -0
  20. package/lib/actions/postActivity.d.ts.map +1 -0
  21. package/lib/actions/postActivity.js +5 -3
  22. package/lib/actions/queueIncomingActivity.js +1 -1
  23. package/lib/actions/sagaError.js +1 -1
  24. package/lib/actions/sendEvent.js +1 -1
  25. package/lib/actions/sendFiles.js +1 -1
  26. package/lib/actions/sendMessage.js +1 -1
  27. package/lib/actions/sendMessageBack.js +1 -1
  28. package/lib/actions/sendPostBack.js +1 -1
  29. package/lib/actions/setDictateInterims.js +1 -1
  30. package/lib/actions/setDictateState.js +1 -1
  31. package/lib/actions/setLanguage.js +1 -1
  32. package/lib/actions/setNotification.js +2 -2
  33. package/lib/actions/setReferenceGrammarID.js +1 -1
  34. package/lib/actions/setSendBox.js +1 -1
  35. package/lib/actions/setSendTimeout.js +1 -1
  36. package/lib/actions/setSendTypingIndicator.js +1 -1
  37. package/lib/actions/setSuggestedActions.js +1 -1
  38. package/lib/actions/startDictate.js +1 -1
  39. package/lib/actions/startSpeakingActivity.js +1 -1
  40. package/lib/actions/stopDictate.js +1 -1
  41. package/lib/actions/stopSpeakingActivity.js +1 -1
  42. package/lib/actions/submitSendBox.js +1 -1
  43. package/lib/actions/updateConnectionStatus.js +1 -1
  44. package/lib/constants/ActivityClientState.js +1 -1
  45. package/lib/createStore.d.ts.map +1 -1
  46. package/lib/createStore.js +5 -5
  47. package/lib/definitions/speakingActivity.js +4 -2
  48. package/lib/index.d.ts +17 -15
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +12 -3
  51. package/lib/reducer.d.ts +1 -2
  52. package/lib/reducer.d.ts.map +1 -1
  53. package/lib/reducer.js +1 -4
  54. package/lib/reducers/activities.d.ts +10 -0
  55. package/lib/reducers/activities.d.ts.map +1 -0
  56. package/lib/reducers/activities.js +65 -45
  57. package/lib/reducers/notifications.js +21 -14
  58. package/lib/reducers/typing.js +13 -7
  59. package/lib/sagas/connectionStatusToNotificationSaga.js +1 -1
  60. package/lib/sagas/effects/observeOnce.js +1 -1
  61. package/lib/sagas/effects/whileConnected.js +1 -1
  62. package/lib/sagas/observeActivitySaga.js +21 -3
  63. package/lib/sagas/postActivitySaga.js +51 -72
  64. package/lib/sagas/queueIncomingActivitySaga.js +1 -1
  65. package/lib/sagas/sendFilesToPostActivitySaga.js +4 -4
  66. package/lib/sagas/sendMessageBackToPostActivitySaga.js +1 -1
  67. package/lib/sagas/sendTypingIndicatorOnSetSendBoxSaga.js +1 -1
  68. package/lib/sagas/speakActivityAndStartDictateOnIncomingActivityFromOthersSaga.js +1 -1
  69. package/lib/sagas/startSpeakActivityOnPostActivitySaga.js +1 -1
  70. package/lib/sagas/stopSpeakingActivityOnInputSaga.js +1 -1
  71. package/lib/sagas/submitSendBoxSaga.js +1 -1
  72. package/lib/selectors/activities.js +1 -1
  73. package/lib/selectors/combineSelectors.js +9 -4
  74. package/lib/selectors/dictateState.js +1 -1
  75. package/lib/selectors/language.js +1 -1
  76. package/lib/selectors/notifications.js +1 -1
  77. package/lib/selectors/sendBoxValue.js +1 -1
  78. package/lib/selectors/sendTimeout.js +1 -1
  79. package/lib/selectors/sendTypingIndicator.js +1 -1
  80. package/lib/selectors/shouldSpeakIncomingActivity.js +1 -1
  81. package/lib/types/AnyAnd.d.ts +2 -0
  82. package/lib/types/AnyAnd.d.ts.map +1 -0
  83. package/lib/types/AnyAnd.js +6 -0
  84. package/lib/types/OneOrMany.js +4 -0
  85. package/lib/types/WebChatActivity.d.ts +81 -0
  86. package/lib/types/WebChatActivity.d.ts.map +1 -0
  87. package/lib/types/WebChatActivity.js +6 -0
  88. package/lib/types/external/DirectLineActivity.d.ts +2 -2
  89. package/lib/types/external/DirectLineActivity.d.ts.map +1 -1
  90. package/lib/types/external/DirectLineActivity.js +4 -0
  91. package/lib/types/external/DirectLineAnimationCard.d.ts +5 -2
  92. package/lib/types/external/DirectLineAnimationCard.d.ts.map +1 -1
  93. package/lib/types/external/DirectLineAnimationCard.js +4 -0
  94. package/lib/types/external/DirectLineAttachment.d.ts +8 -2
  95. package/lib/types/external/DirectLineAttachment.d.ts.map +1 -1
  96. package/lib/types/external/DirectLineAttachment.js +4 -0
  97. package/lib/types/external/DirectLineAudioCard.d.ts +5 -2
  98. package/lib/types/external/DirectLineAudioCard.d.ts.map +1 -1
  99. package/lib/types/external/DirectLineAudioCard.js +4 -0
  100. package/lib/types/external/DirectLineBasicCardEssence.d.ts +12 -0
  101. package/lib/types/external/DirectLineBasicCardEssence.d.ts.map +1 -0
  102. package/lib/types/external/DirectLineBasicCardEssence.js +6 -0
  103. package/lib/types/external/DirectLineCardAction.d.ts +1 -1
  104. package/lib/types/external/DirectLineCardAction.d.ts.map +1 -1
  105. package/lib/types/external/DirectLineCardAction.js +4 -0
  106. package/lib/types/external/DirectLineCardImage.d.ts +8 -0
  107. package/lib/types/external/DirectLineCardImage.d.ts.map +1 -0
  108. package/lib/types/external/DirectLineCardImage.js +6 -0
  109. package/lib/types/external/DirectLineHeroCard.d.ts +5 -2
  110. package/lib/types/external/DirectLineHeroCard.d.ts.map +1 -1
  111. package/lib/types/external/DirectLineHeroCard.js +4 -0
  112. package/lib/types/external/DirectLineJSBotConnection.d.ts +1 -1
  113. package/lib/types/external/DirectLineJSBotConnection.d.ts.map +1 -1
  114. package/lib/types/external/DirectLineJSBotConnection.js +4 -0
  115. package/lib/types/external/DirectLineMediaCardEssence.d.ts +21 -0
  116. package/lib/types/external/DirectLineMediaCardEssence.d.ts.map +1 -0
  117. package/lib/types/external/DirectLineMediaCardEssence.js +6 -0
  118. package/lib/types/external/DirectLineOAuthCard.d.ts +7 -2
  119. package/lib/types/external/DirectLineOAuthCard.d.ts.map +1 -1
  120. package/lib/types/external/DirectLineOAuthCard.js +4 -0
  121. package/lib/types/external/DirectLineReceiptCard.d.ts +27 -2
  122. package/lib/types/external/DirectLineReceiptCard.d.ts.map +1 -1
  123. package/lib/types/external/DirectLineReceiptCard.js +4 -0
  124. package/lib/types/external/DirectLineSignInCard.d.ts +7 -2
  125. package/lib/types/external/DirectLineSignInCard.d.ts.map +1 -1
  126. package/lib/types/external/DirectLineSignInCard.js +4 -0
  127. package/lib/types/external/DirectLineSuggestedAction.d.ts +6 -2
  128. package/lib/types/external/DirectLineSuggestedAction.d.ts.map +1 -1
  129. package/lib/types/external/DirectLineSuggestedAction.js +4 -0
  130. package/lib/types/external/DirectLineThumbnailCard.d.ts +5 -2
  131. package/lib/types/external/DirectLineThumbnailCard.d.ts.map +1 -1
  132. package/lib/types/external/DirectLineThumbnailCard.js +4 -0
  133. package/lib/types/external/DirectLineVideoCard.d.ts +5 -2
  134. package/lib/types/external/DirectLineVideoCard.d.ts.map +1 -1
  135. package/lib/types/external/DirectLineVideoCard.js +4 -0
  136. package/lib/types/external/Observable.js +6 -0
  137. package/lib/types/internal/Notification.js +6 -0
  138. package/lib/types/internal/ReduxState.js +6 -0
  139. package/lib/utils/dateToLocaleISOString.js +5 -5
  140. package/lib/utils/deleteKey.js +2 -3
  141. package/lib/utils/isForbiddenPropertyName.d.ts +2 -0
  142. package/lib/utils/isForbiddenPropertyName.d.ts.map +1 -0
  143. package/lib/utils/isForbiddenPropertyName.js +21 -0
  144. package/lib/utils/sleep.js +1 -1
  145. package/lib/utils/uniqueID.js +1 -1
  146. package/package.json +20 -23
  147. package/src/__tests__/detectSlowConnectionSaga.spec.js +1 -1
  148. package/src/__tests__/observeOnce.spec.js +3 -3
  149. package/src/actions/deleteActivity.ts +19 -0
  150. package/src/actions/incomingActivity.ts +21 -0
  151. package/src/actions/markActivity.ts +23 -0
  152. package/src/actions/postActivity.ts +48 -0
  153. package/src/actions/setNotification.js +8 -2
  154. package/src/createStore.ts +4 -4
  155. package/src/definitions/speakingActivity.js +1 -1
  156. package/src/index.ts +19 -14
  157. package/src/reducer.ts +0 -2
  158. package/src/reducers/activities.ts +172 -0
  159. package/src/reducers/notifications.js +22 -16
  160. package/src/reducers/typing.js +6 -5
  161. package/src/sagas/connectionStatusToNotificationSaga.js +1 -1
  162. package/src/sagas/effects/{observeOnce.js → observeOnce.ts} +6 -4
  163. package/src/sagas/effects/{whileConnected.js → whileConnected.ts} +20 -1
  164. package/src/sagas/{observeActivitySaga.js → observeActivitySaga.ts} +25 -6
  165. package/src/sagas/{postActivitySaga.js → postActivitySaga.ts} +57 -48
  166. package/src/sagas/queueIncomingActivitySaga.js +40 -39
  167. package/src/sagas/sendFilesToPostActivitySaga.js +1 -1
  168. package/src/sagas/sendMessageBackToPostActivitySaga.js +0 -1
  169. package/src/sagas/sendTypingIndicatorOnSetSendBoxSaga.js +1 -1
  170. package/src/sagas/speakActivityAndStartDictateOnIncomingActivityFromOthersSaga.js +1 -1
  171. package/src/sagas/startSpeakActivityOnPostActivitySaga.js +1 -1
  172. package/src/sagas/stopSpeakingActivityOnInputSaga.js +1 -1
  173. package/src/sagas/submitSendBoxSaga.js +1 -1
  174. package/src/selectors/activities.ts +12 -0
  175. package/src/selectors/combineSelectors.ts +21 -0
  176. package/src/selectors/dictateState.ts +3 -0
  177. package/src/selectors/language.ts +3 -0
  178. package/src/selectors/notifications.ts +6 -0
  179. package/src/selectors/sendBoxValue.ts +3 -0
  180. package/src/selectors/sendTimeout.ts +3 -0
  181. package/src/selectors/sendTypingIndicator.ts +3 -0
  182. package/src/selectors/shouldSpeakIncomingActivity.ts +3 -0
  183. package/src/types/AnyAnd.ts +1 -0
  184. package/src/types/WebChatActivity.ts +154 -0
  185. package/src/types/external/DirectLineActivity.ts +4 -3
  186. package/src/types/external/DirectLineAnimationCard.ts +6 -4
  187. package/src/types/external/DirectLineAttachment.ts +10 -5
  188. package/src/types/external/DirectLineAudioCard.ts +6 -4
  189. package/src/types/external/DirectLineBasicCardEssence.ts +14 -0
  190. package/src/types/external/DirectLineCardAction.ts +1 -1
  191. package/src/types/external/DirectLineCardImage.ts +9 -0
  192. package/src/types/external/DirectLineHeroCard.ts +6 -4
  193. package/src/types/external/DirectLineJSBotConnection.ts +1 -2
  194. package/src/types/external/DirectLineMediaCardEssence.ts +19 -0
  195. package/src/types/external/DirectLineOAuthCard.ts +7 -4
  196. package/src/types/external/DirectLineReceiptCard.ts +30 -4
  197. package/src/types/external/DirectLineSignInCard.ts +8 -4
  198. package/src/types/external/DirectLineSuggestedAction.ts +6 -4
  199. package/src/types/external/DirectLineThumbnailCard.ts +6 -4
  200. package/src/types/external/DirectLineVideoCard.ts +6 -4
  201. package/src/types/external/Observable.ts +69 -0
  202. package/src/types/internal/Notification.ts +10 -0
  203. package/src/types/internal/ReduxState.ts +16 -0
  204. package/src/utils/dateToLocaleISOString.chatham.spec.js +1 -0
  205. package/src/utils/dateToLocaleISOString.japan.spec.js +1 -0
  206. package/src/utils/dateToLocaleISOString.pacific.spec.js +1 -0
  207. package/src/utils/{dateToLocaleISOString.js → dateToLocaleISOString.ts} +6 -6
  208. package/src/utils/dateToLocaleISOString.utc.spec.js +2 -0
  209. package/src/utils/deleteKey.ts +9 -0
  210. package/src/utils/isForbiddenPropertyName.spec.js +6 -0
  211. package/src/utils/isForbiddenPropertyName.ts +33 -0
  212. package/src/utils/{sleep.js → sleep.ts} +1 -1
  213. package/src/utils/uniqueID.ts +7 -0
  214. package/.eslintignore +0 -9
  215. package/lib/reducers/clockSkewAdjustment.js +0 -44
  216. package/lib/sagas/effects/callUntil.js +0 -48
  217. package/lib/selectors/clockSkewAdjustment.js +0 -14
  218. package/lib/utils/mime-wrapper.js +0 -49
  219. package/src/actions/deleteActivity.js +0 -8
  220. package/src/actions/incomingActivity.js +0 -10
  221. package/src/actions/markActivity.js +0 -14
  222. package/src/actions/postActivity.js +0 -14
  223. package/src/reducers/activities.js +0 -116
  224. package/src/reducers/clockSkewAdjustment.js +0 -29
  225. package/src/sagas/effects/callUntil.js +0 -13
  226. package/src/selectors/activities.js +0 -8
  227. package/src/selectors/clockSkewAdjustment.js +0 -1
  228. package/src/selectors/combineSelectors.js +0 -8
  229. package/src/selectors/dictateState.js +0 -1
  230. package/src/selectors/language.js +0 -1
  231. package/src/selectors/notifications.js +0 -3
  232. package/src/selectors/sendBoxValue.js +0 -1
  233. package/src/selectors/sendTimeout.js +0 -1
  234. package/src/selectors/sendTypingIndicator.js +0 -1
  235. package/src/selectors/shouldSpeakIncomingActivity.js +0 -1
  236. package/src/utils/deleteKey.js +0 -11
  237. package/src/utils/mime-wrapper.js +0 -40
  238. package/src/utils/uniqueID.js +0 -12
@@ -34,7 +34,7 @@ function* sendTypingIndicatorOnSetSendBox() {
34
34
  // When the user type, and then post the activity at t = 1500, we still have a pending typing indicator at t = 3000.
35
35
  // This code is to cancel the typing indicator at t = 3000.
36
36
  (type === POST_ACTIVITY && payload.activity.type !== 'typing'),
37
- function*({ payload, type }) {
37
+ function* ({ payload, type }) {
38
38
  if (type === SET_SEND_BOX) {
39
39
  const interval = SEND_INTERVAL - Date.now() + lastSend;
40
40
 
@@ -16,7 +16,7 @@ function* speakActivityAndStartDictateOnIncomingActivityFromOthers({ userID }) {
16
16
  // In Direct Line Speech, we do not know the user ID, but "role" is filled with "bot" or "user".
17
17
  // Here, we do two checks: the speakable activity must not have user ID, and must not have role === 'user'
18
18
  type === INCOMING_ACTIVITY && payload.activity.from.id !== userID && payload.activity.from.role !== 'user',
19
- function*({ payload: { activity } }) {
19
+ function* ({ payload: { activity } }) {
20
20
  const shouldSpeakIncomingActivity = yield select(shouldSpeakIncomingActivitySelector);
21
21
  const shouldSpeak = speakableActivity(activity) && shouldSpeakIncomingActivity;
22
22
 
@@ -8,7 +8,7 @@ function* startSpeakActivityOnPostActivity() {
8
8
  yield takeEvery(
9
9
  ({ meta, payload, type }) =>
10
10
  type === POST_ACTIVITY_PENDING && meta.method === 'speech' && payload.activity.type === 'message',
11
- function*() {
11
+ function* () {
12
12
  yield put(startSpeakingActivity());
13
13
  }
14
14
  );
@@ -14,7 +14,7 @@ function* stopSpeakingActivityOnInput() {
14
14
  // So, right now, we are using best-effort by listening to POST_ACTIVITY_PENDING with a "message" event
15
15
  // We filter out speech because we will call startSpeakingActivity() for POST_ACTIVITY_PENDING dispatched by speech
16
16
  (type === POST_ACTIVITY_PENDING && meta.method !== 'speech' && payload.activity.type === 'message'),
17
- function*() {
17
+ function* () {
18
18
  yield put(stopSpeakingActivity());
19
19
  }
20
20
  );
@@ -7,7 +7,7 @@ import setSendBox from '../actions/setSendBox';
7
7
  import whileConnected from './effects/whileConnected';
8
8
 
9
9
  function* submitSendBox() {
10
- yield takeEvery(SUBMIT_SEND_BOX, function*({ payload: { channelData, method } }) {
10
+ yield takeEvery(SUBMIT_SEND_BOX, function* ({ payload: { channelData, method } }) {
11
11
  const sendBoxValue = yield select(sendBoxValueSelector);
12
12
 
13
13
  if (sendBoxValue) {
@@ -0,0 +1,12 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+ import type { WebChatActivity } from '../types/WebChatActivity';
3
+
4
+ const activities = ({ activities }: ReduxState) => activities;
5
+
6
+ const of = (predicate: (activity: WebChatActivity) => boolean) => (state: ReduxState) =>
7
+ activities(state).filter(predicate);
8
+ const ofID = (targetID: string) => of(({ id }) => id === targetID);
9
+ const ofType = (targetType: string) => of(({ type }) => type === targetType);
10
+
11
+ export default activities;
12
+ export { of, ofID, ofType };
@@ -0,0 +1,21 @@
1
+ import isForbiddenPropertyName from '../utils/isForbiddenPropertyName';
2
+
3
+ export default function combineSelectors<
4
+ TState extends { [key: string]: unknown },
5
+ TResult extends { [key: string]: unknown }
6
+ >(selectors: { [P in keyof TResult]: (state: TState) => TResult[P] }): (state: TState) => {
7
+ [P in keyof TResult]?: TResult[P];
8
+ } {
9
+ if (Array.isArray(selectors)) {
10
+ return state => selectors.reduce((combinedState, selector) => [...combinedState, selector(state)], []);
11
+ }
12
+
13
+ return state =>
14
+ Object.keys(selectors).reduce(
15
+ (combinedState, key) =>
16
+ // Mitigated through denylisting.
17
+ // eslint-disable-next-line security/detect-object-injection
18
+ isForbiddenPropertyName(key) ? combinedState : { ...combinedState, [key]: selectors[key](state) },
19
+ {} as TResult
20
+ );
21
+ }
@@ -0,0 +1,3 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+
3
+ export default ({ dictateState }: ReduxState) => dictateState;
@@ -0,0 +1,3 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+
3
+ export default ({ language }: ReduxState): string => language;
@@ -0,0 +1,6 @@
1
+ import type { Notification } from '../types/internal/Notification';
2
+ import type { ReduxState } from '../types/internal/ReduxState';
3
+
4
+ const notifications = ({ notifications }: ReduxState): { [key: string]: Notification } => notifications;
5
+
6
+ export default notifications;
@@ -0,0 +1,3 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+
3
+ export default ({ sendBoxValue }: ReduxState): string => sendBoxValue;
@@ -0,0 +1,3 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+
3
+ export default ({ sendTimeout }: ReduxState): number => sendTimeout;
@@ -0,0 +1,3 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+
3
+ export default ({ sendTypingIndicator }: ReduxState): boolean => sendTypingIndicator;
@@ -0,0 +1,3 @@
1
+ import type { ReduxState } from '../types/internal/ReduxState';
2
+
3
+ export default ({ shouldSpeakIncomingActivity }: ReduxState): boolean => shouldSpeakIncomingActivity;
@@ -0,0 +1 @@
1
+ export type AnyAnd<T> = Omit<any, keyof T> & T;
@@ -0,0 +1,154 @@
1
+ // This is Web Chat view of Direct Line Activity, which is defined at https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md.
2
+ // It is not a direct port of Direct Line version of Activity.
3
+
4
+ // For example:
5
+ // - "channelId" is not needed by Web Chat, thus, it is optional
6
+ // - "localTimestamp" is a must when sending out activities to the server
7
+ // - However, we do not expect the server to return "localTimestamp" as they may not have capability to store this information
8
+ // - "conversationUpdate" activity is never sent to Web Chat, thus, it is not defined
9
+
10
+ import type { AnyAnd } from './AnyAnd';
11
+ import type { DirectLineAttachment } from './external/DirectLineAttachment';
12
+ import type { DirectLineSuggestedAction } from './external/DirectLineSuggestedAction';
13
+
14
+ type ChannelData<SendState extends string | undefined, Type extends string> = AnyAnd<
15
+ {
16
+ // TODO: [P2] #3953 Rename to "webchat:attachment-sizes".
17
+ attachmentSizes?: number[];
18
+
19
+ // TODO: [P2] #3953 Rename to "webchat:client-activity-id".
20
+ clientActivityID?: string;
21
+
22
+ // Sequence ID must be available when chat adapter send it to Web Chat.
23
+ 'webchat:sequence-id': number;
24
+ } & (SendState extends string
25
+ ? {
26
+ // TODO: [P2] #3953 Rename to "webchat:send-state".
27
+ state: SendState;
28
+ }
29
+ : {}) &
30
+ (Type extends 'message'
31
+ ? {
32
+ // TODO: [P2] #3953 Rename to "webchat:message-back".
33
+ messageBack?: {
34
+ displayText: string;
35
+ };
36
+
37
+ // TODO: [P2] #3953 Rename to "webchat:post-back".
38
+ postBack?: boolean;
39
+
40
+ // TODO: [P2] #3953 Rename to "webchat:speak-state".
41
+ speak?: boolean;
42
+
43
+ // TODO: [P2] #3953 Rename to "webchat:speech-synthesis-utterance".
44
+ speechSynthesisUtterance?: SpeechSynthesisUtterance;
45
+
46
+ // TODO: [P2] #3953 It seems Direct Line added a new "summary" field to cater this case.
47
+ 'webchat:fallback-text'?: string;
48
+ }
49
+ : {})
50
+ >;
51
+
52
+ // Entity - https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#entity
53
+
54
+ type ClientCapabilitiesEntity = {
55
+ requiresBotState?: boolean;
56
+ supportsListening?: boolean;
57
+ supportsTts?: boolean;
58
+ type: 'ClientCapabilities';
59
+ };
60
+
61
+ type Entity = ClientCapabilitiesEntity | AnyAnd<{ type: Exclude<string, 'ClientCapabilities'> }>;
62
+
63
+ // Channel account - https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#channel-account
64
+ type ChannelAcount<Role = 'bot' | 'channel' | 'user'> = {
65
+ id: string;
66
+ name?: string;
67
+ role: Role;
68
+ };
69
+
70
+ // Abstract - content of different activity types
71
+
72
+ // https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#event-activity
73
+ type EventActivityEssence = {
74
+ name: string;
75
+ type: 'event';
76
+ value?: any;
77
+ };
78
+
79
+ // https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#message-activity
80
+ type MessageActivityEssence = {
81
+ attachmentLayout?: 'carousel' | 'stacked';
82
+ attachments?: DirectLineAttachment[];
83
+ inputHint?: 'accepting' | 'expecting' | 'ignoring';
84
+ locale?: string;
85
+ speak?: string;
86
+ suggestedActions?: DirectLineSuggestedAction;
87
+ text: string | undefined;
88
+ textFormat?: 'markdown' | 'plain' | 'xml';
89
+ type: 'message';
90
+ value?: any;
91
+ };
92
+
93
+ // https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#typing-activity
94
+ type TypingActivityEssence = {
95
+ type: 'typing';
96
+ };
97
+
98
+ // Abstract - timestamps
99
+
100
+ type TimestampFromServerEssence = {
101
+ id: string;
102
+ localTimestamp?: string;
103
+ timestamp: string;
104
+ };
105
+
106
+ type TimestampInTransitEssence = {
107
+ id?: string;
108
+ localTimestamp: string;
109
+ timestamp?: string;
110
+ };
111
+
112
+ type TimestampEssence<Role extends string, SendState extends string | undefined> = Role extends 'user'
113
+ ? SendState extends 'sending' | 'send failed'
114
+ ? TimestampInTransitEssence
115
+ : TimestampFromServerEssence
116
+ : TimestampFromServerEssence;
117
+
118
+ // Abstract - core
119
+
120
+ type CoreActivityEssence<
121
+ Role extends 'bot' | 'channel' | 'user',
122
+ SendState extends string | undefined,
123
+ Type extends string = 'conversationUpdate' | 'event' | 'invoke' | 'message' | 'typing'
124
+ > = {
125
+ channelData: ChannelData<SendState, Type>;
126
+ channelId?: string;
127
+ entities?: Entity[];
128
+ from: ChannelAcount<Role>;
129
+ localTimezone?: string;
130
+ replyToId?: string;
131
+ type: string;
132
+ } & TimestampEssence<Role, SendState> &
133
+ (Type extends 'event'
134
+ ? EventActivityEssence
135
+ : Type extends 'message'
136
+ ? MessageActivityEssence
137
+ : Type extends 'typing'
138
+ ? TypingActivityEssence
139
+ : { type: Type });
140
+
141
+ // Concrete
142
+
143
+ type SelfActivityInTransit = CoreActivityEssence<'user', 'sending' | 'send failed'>;
144
+ type SelfActivityFromServer = CoreActivityEssence<'user', 'sent'>;
145
+
146
+ type SelfActivity = SelfActivityInTransit | SelfActivityFromServer;
147
+
148
+ type OthersActivity = CoreActivityEssence<'bot' | 'channel', undefined>;
149
+
150
+ // Exported
151
+
152
+ type WebChatActivity = SelfActivity | OthersActivity;
153
+
154
+ export type { WebChatActivity };
@@ -1,6 +1,7 @@
1
1
  // TODO: [P1] #3953 We should fully type it out.
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineActivity = any;
3
+ // Until we fully typed out DirectLineActivity, we need to use "any" here.
4
+ // We only know the DirectLineActivity must be a map, and not other primitive types.
5
+ type DirectLineActivity = Exclude<any, [] | boolean | Function | number | string>;
5
6
 
6
- export default DirectLineActivity;
7
+ export type { DirectLineActivity };
@@ -1,6 +1,8 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineMediaCardEssence } from './DirectLineMediaCardEssence';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineAnimationCard = any;
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#Animation-card
4
+ type DirectLineAnimationCard = DirectLineMediaCardEssence & {
5
+ contentType: 'application/vnd.microsoft.card.animation';
6
+ };
5
7
 
6
- export default DirectLineAnimationCard;
8
+ export type { DirectLineAnimationCard };
@@ -1,6 +1,11 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ // https://github.com/Microsoft/botframework-sdk/blob/main/specs/botframework-activity/botframework-activity.md#attachment
2
+ type DirectLineAttachment = {
3
+ // Currently, we allow "text/plain" with "content" field of type string. Under the spec, "content" must not contains primitive types.
4
+ content?: any;
5
+ contentType: string;
6
+ contentUrl?: string;
7
+ name?: string;
8
+ thumbnailUrl?: string;
9
+ };
2
10
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineAttachment = any;
5
-
6
- export default DirectLineAttachment;
11
+ export type { DirectLineAttachment };
@@ -1,6 +1,8 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineMediaCardEssence } from './DirectLineMediaCardEssence';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineAudioCard = any;
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#audio-card
4
+ type DirectLineAudioCard = DirectLineMediaCardEssence & {
5
+ contentType: 'application/vnd.microsoft.card.audio';
6
+ };
5
7
 
6
- export default DirectLineAudioCard;
8
+ export type { DirectLineAudioCard };
@@ -0,0 +1,14 @@
1
+ import type { DirectLineCardImage } from './DirectLineCardImage';
2
+ import type { DirectLineCardAction } from './DirectLineCardAction';
3
+
4
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#basic-cards
5
+ type DirectLineBasicCardEssence = {
6
+ buttons?: DirectLineCardAction[];
7
+ images?: DirectLineCardImage[];
8
+ subtitle?: string;
9
+ tap?: DirectLineCardAction;
10
+ text?: string;
11
+ title?: string;
12
+ };
13
+
14
+ export type { DirectLineBasicCardEssence };
@@ -125,4 +125,4 @@ type DirectLineCardAction =
125
125
  | ShowImageCardAction
126
126
  | SignInCardAction;
127
127
 
128
- export default DirectLineCardAction;
128
+ export type { DirectLineCardAction };
@@ -0,0 +1,9 @@
1
+ import type { DirectLineCardAction } from './DirectLineCardAction';
2
+
3
+ type DirectLineCardImage = {
4
+ alt: string;
5
+ tap?: DirectLineCardAction;
6
+ url: string;
7
+ };
8
+
9
+ export type { DirectLineCardImage };
@@ -1,6 +1,8 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineBasicCardEssence } from './DirectLineBasicCardEssence';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineHeroCard = any;
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#Hero-cards
4
+ type DirectLineHeroCard = DirectLineBasicCardEssence & {
5
+ contentType: 'application/vnd.microsoft.card.hero';
6
+ };
5
7
 
6
- export default DirectLineHeroCard;
8
+ export type { DirectLineHeroCard };
@@ -1,6 +1,5 @@
1
1
  // TODO: [P1] #3953 We should fully type it out.
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
3
  type DirectLineJSBotConnection = any;
5
4
 
6
- export default DirectLineJSBotConnection;
5
+ export type { DirectLineJSBotConnection };
@@ -0,0 +1,19 @@
1
+ import type { DirectLineCardAction } from './DirectLineCardAction';
2
+
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#media-cards
4
+ type DirectLineMediaCardEssence = {
5
+ aspect?: '4:3' | '16:9';
6
+ autoloop?: boolean;
7
+ autostart?: boolean;
8
+ buttons?: DirectLineCardAction[];
9
+ duration?: string;
10
+ // In the spec, "image" is of type "thumbnailUrl", which is simply a string.
11
+ image?: { url: string };
12
+ media: { profile?: string; url: string }[];
13
+ shareable?: boolean;
14
+ subtitle?: string;
15
+ title?: string;
16
+ value?: any;
17
+ };
18
+
19
+ export type { DirectLineMediaCardEssence };
@@ -1,6 +1,9 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineCardAction } from './DirectLineCardAction';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineOAuthCard = any;
3
+ type DirectLineOAuthCard = {
4
+ buttons?: DirectLineCardAction[];
5
+ contentType: 'application/vnd.microsoft.card.oauth';
6
+ text?: string;
7
+ };
5
8
 
6
- export default DirectLineOAuthCard;
9
+ export type { DirectLineOAuthCard };
@@ -1,6 +1,32 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineCardAction } from './DirectLineCardAction';
2
+ import type { DirectLineCardImage } from './DirectLineCardImage';
2
3
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineReceiptCard = any;
4
+ type Fact = {
5
+ key?: string;
6
+ value?: string;
7
+ };
5
8
 
6
- export default DirectLineReceiptCard;
9
+ type ReceiptItem = {
10
+ image?: DirectLineCardImage;
11
+ price?: string;
12
+ quantity?: string;
13
+ subtitle?: string;
14
+ tap?: DirectLineCardAction;
15
+ text?: string;
16
+ title?: string;
17
+ };
18
+
19
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#receipt-card
20
+ type DirectLineReceiptCard = {
21
+ buttons?: DirectLineCardAction[];
22
+ contentType: 'application/vnd.microsoft.card.receipt';
23
+ facts?: Fact[];
24
+ items?: ReceiptItem[];
25
+ tap?: DirectLineCardAction;
26
+ tax?: string;
27
+ title?: string;
28
+ total?: string;
29
+ vat?: string;
30
+ };
31
+
32
+ export type { DirectLineReceiptCard };
@@ -1,6 +1,10 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineCardAction } from './DirectLineCardAction';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineSignInCard = any;
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#Signin-card
4
+ type DirectLineSignInCard = {
5
+ buttons?: DirectLineCardAction[];
6
+ contentType: 'application/vnd.microsoft.card.signin';
7
+ text?: string;
8
+ };
5
9
 
6
- export default DirectLineSignInCard;
10
+ export type { DirectLineSignInCard };
@@ -1,6 +1,8 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineCardAction } from './DirectLineCardAction';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineSuggestedAction = any;
3
+ type DirectLineSuggestedAction = {
4
+ actions?: DirectLineCardAction[];
5
+ to?: string[];
6
+ };
5
7
 
6
- export default DirectLineSuggestedAction;
8
+ export type { DirectLineSuggestedAction };
@@ -1,6 +1,8 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineBasicCardEssence } from './DirectLineBasicCardEssence';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineThumbnailCard = any;
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#Thumbnail-cards
4
+ type DirectLineThumbnailCard = DirectLineBasicCardEssence & {
5
+ contentType: 'application/vnd.microsoft.card.thumbnail';
6
+ };
5
7
 
6
- export default DirectLineThumbnailCard;
8
+ export type { DirectLineThumbnailCard };
@@ -1,6 +1,8 @@
1
- // TODO: [P1] #3953 We should fully type it out.
1
+ import type { DirectLineMediaCardEssence } from './DirectLineMediaCardEssence';
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- type DirectLineVideoCard = any;
3
+ // https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#video-card
4
+ type DirectLineVideoCard = DirectLineMediaCardEssence & {
5
+ contentType: 'application/vnd.microsoft.card.video';
6
+ };
5
7
 
6
- export default DirectLineVideoCard;
8
+ export type { DirectLineVideoCard };
@@ -0,0 +1,69 @@
1
+ // This is a declaration file for a single ES feature. Could contains multiple classes definitions.
2
+ /* eslint-disable max-classes-per-file */
3
+
4
+ // Adopted from https://github.com/tc39/proposal-observable.
5
+
6
+ /** Receives a completion notification */
7
+ type CompleteFunction = () => void;
8
+
9
+ /** Receives the sequence error */
10
+ type ErrorFunction = (error: Error) => void;
11
+
12
+ /** Receives the next value in the sequence */
13
+ type NextFunction<T> = (value: T) => void;
14
+ type SubscriberFunction<T> = (observer: SubscriptionObserver<T>) => Subscription;
15
+
16
+ /** An `Observable` represents a sequence of values which may be observed. */
17
+ declare class Observable<T> {
18
+ constructor(subscriber: SubscriberFunction<T>);
19
+
20
+ /** Subscribes to the sequence with an observer */
21
+ subscribe(observer: Observer<T>): Subscription;
22
+
23
+ /** Subscribes to the sequence with callbacks */
24
+ subscribe(onNext: NextFunction<T>, onError?: ErrorFunction, onComplete?: CompleteFunction): Subscription;
25
+ }
26
+
27
+ declare class Subscription {
28
+ /** Cancels the subscription */
29
+ unsubscribe(): void;
30
+
31
+ /** A boolean value indicating whether the subscription is closed */
32
+ get closed(): boolean;
33
+ }
34
+
35
+ /**
36
+ * An `Observer` is used to receive data from an `Observable`, and is supplied as an argument to `subscribe`.
37
+ *
38
+ * All methods are optional.
39
+ */
40
+ declare class Observer<T> {
41
+ /** Receives the subscription object when `subscribe` is called */
42
+ start(subscription: Subscription);
43
+
44
+ /** Receives the next value in the sequence */
45
+ next: NextFunction<T>;
46
+
47
+ /** Receives the sequence error */
48
+ error: ErrorFunction;
49
+
50
+ /** Receives a completion notification */
51
+ complete: CompleteFunction;
52
+ }
53
+
54
+ /** A `SubscriptionObserver` is a normalized `Observer` which wraps the observer object supplied to `subscribe`. */
55
+ declare class SubscriptionObserver<T> {
56
+ /** Sends the next value in the sequence */
57
+ next: NextFunction<T>;
58
+
59
+ /** Sends the sequence error */
60
+ error: ErrorFunction;
61
+
62
+ /** Sends the completion notification */
63
+ complete: CompleteFunction;
64
+
65
+ /** A boolean value indicating whether the subscription is closed */
66
+ get closed(): boolean;
67
+ }
68
+
69
+ export type { Observable, Observer, Subscription, SubscriptionObserver };
@@ -0,0 +1,10 @@
1
+ type Notification = {
2
+ alt: string;
3
+ data: any;
4
+ id: string;
5
+ level: string;
6
+ message: string;
7
+ timestamp: number;
8
+ };
9
+
10
+ export type { Notification };
@@ -0,0 +1,16 @@
1
+ import type { Notification } from './Notification';
2
+ import type { WebChatActivity } from '../external/WebChatActivity';
3
+
4
+ type ReduxState = {
5
+ activities: WebChatActivity[];
6
+ clockSkewAdjustment: number;
7
+ dictateState: string;
8
+ language: string;
9
+ notifications: { [key: string]: Notification };
10
+ sendBoxValue: string;
11
+ sendTimeout: number;
12
+ sendTypingIndicator: boolean;
13
+ shouldSpeakIncomingActivity: boolean;
14
+ };
15
+
16
+ export type { ReduxState };
@@ -6,6 +6,7 @@
6
6
  import dateToLocaleISOString from './dateToLocaleISOString';
7
7
 
8
8
  test('formatting a time in Chatham Islands timezone', () => {
9
+ // eslint-disable-next-line no-magic-numbers
9
10
  const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
10
11
  const actual = dateToLocaleISOString(date);
11
12