botframework-webchat-api 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 (373) hide show
  1. package/.eslintrc.yml +4 -105
  2. package/.prettierrc.yml +1 -1
  3. package/lib/StyleOptions.d.ts +244 -14
  4. package/lib/StyleOptions.d.ts.map +1 -1
  5. package/lib/defaultStyleOptions.d.ts.map +1 -1
  6. package/lib/defaultStyleOptions.js +67 -14
  7. package/lib/hooks/Composer.d.ts +3 -3
  8. package/lib/hooks/Composer.d.ts.map +1 -1
  9. package/lib/hooks/Composer.js +29 -11
  10. package/lib/hooks/index.d.ts +11 -1
  11. package/lib/hooks/index.d.ts.map +1 -1
  12. package/lib/hooks/index.js +81 -1
  13. package/lib/hooks/internal/WebChatAPIContext.d.ts +3 -3
  14. package/lib/hooks/internal/WebChatAPIContext.d.ts.map +1 -1
  15. package/lib/hooks/internal/WebChatAPIContext.js +1 -1
  16. package/lib/hooks/internal/useCreateActivityRendererInternal.d.ts.map +1 -1
  17. package/lib/hooks/internal/useCreateActivityRendererInternal.js +1 -1
  18. package/lib/hooks/internal/useDebugDeps.js +10 -4
  19. package/lib/hooks/internal/usePrevious.d.ts +2 -0
  20. package/lib/hooks/internal/usePrevious.d.ts.map +1 -0
  21. package/lib/hooks/internal/usePrevious.js +17 -0
  22. package/lib/hooks/internal/useReadTelemetryDimensions.js +2 -2
  23. package/lib/hooks/internal/useValueRef.d.ts +3 -0
  24. package/lib/hooks/internal/useValueRef.d.ts.map +1 -0
  25. package/lib/hooks/internal/useValueRef.js +24 -0
  26. package/lib/hooks/middleware/UserlandBoundary.js +1 -1
  27. package/lib/hooks/middleware/applyMiddleware.js +1 -1
  28. package/lib/hooks/middleware/concatMiddleware.d.ts.map +1 -1
  29. package/lib/hooks/middleware/concatMiddleware.js +2 -2
  30. package/lib/hooks/middleware/createDefaultCardActionMiddleware.d.ts.map +1 -1
  31. package/lib/hooks/middleware/createDefaultCardActionMiddleware.js +1 -1
  32. package/lib/hooks/middleware/createDefaultGroupActivitiesMiddleware.d.ts.map +1 -1
  33. package/lib/hooks/middleware/createDefaultGroupActivitiesMiddleware.js +19 -3
  34. package/lib/hooks/useActiveTyping.d.ts.map +1 -1
  35. package/lib/hooks/useActiveTyping.js +5 -4
  36. package/lib/hooks/useActivities.d.ts +2 -2
  37. package/lib/hooks/useActivities.d.ts.map +1 -1
  38. package/lib/hooks/useActivities.js +1 -1
  39. package/lib/hooks/useActivityKeys.d.ts +3 -0
  40. package/lib/hooks/useActivityKeys.d.ts.map +1 -0
  41. package/lib/hooks/useActivityKeys.js +14 -0
  42. package/lib/hooks/useActivityKeysByRead.d.ts +3 -0
  43. package/lib/hooks/useActivityKeysByRead.d.ts.map +1 -0
  44. package/lib/hooks/useActivityKeysByRead.js +14 -0
  45. package/lib/hooks/useCreateActivityStatusRenderer.d.ts +3 -3
  46. package/lib/hooks/useCreateActivityStatusRenderer.d.ts.map +1 -1
  47. package/lib/hooks/useCreateActivityStatusRenderer.js +47 -16
  48. package/lib/hooks/useCreateAvatarRenderer.d.ts +5 -3
  49. package/lib/hooks/useCreateAvatarRenderer.d.ts.map +1 -1
  50. package/lib/hooks/useCreateAvatarRenderer.js +1 -1
  51. package/lib/hooks/useDateFormatter.d.ts.map +1 -1
  52. package/lib/hooks/useDateFormatter.js +1 -1
  53. package/lib/hooks/useDebouncedNotifications.js +3 -3
  54. package/lib/hooks/useGetActivityByKey.d.ts +3 -0
  55. package/lib/hooks/useGetActivityByKey.d.ts.map +1 -0
  56. package/lib/hooks/useGetActivityByKey.js +14 -0
  57. package/lib/hooks/useGetHasAcknowledgedByActivityKey.d.ts +3 -0
  58. package/lib/hooks/useGetHasAcknowledgedByActivityKey.d.ts.map +1 -0
  59. package/lib/hooks/useGetHasAcknowledgedByActivityKey.js +14 -0
  60. package/lib/hooks/useGetKeyByActivity.d.ts +3 -0
  61. package/lib/hooks/useGetKeyByActivity.d.ts.map +1 -0
  62. package/lib/hooks/useGetKeyByActivity.js +14 -0
  63. package/lib/hooks/useGetKeyByActivityId.d.ts +3 -0
  64. package/lib/hooks/useGetKeyByActivityId.d.ts.map +1 -0
  65. package/lib/hooks/useGetKeyByActivityId.js +14 -0
  66. package/lib/hooks/useGetSendTimeoutForActivity.d.ts +2 -2
  67. package/lib/hooks/useGetSendTimeoutForActivity.d.ts.map +1 -1
  68. package/lib/hooks/useGetSendTimeoutForActivity.js +4 -2
  69. package/lib/hooks/useGroupActivities.d.ts +4 -4
  70. package/lib/hooks/useGroupActivities.d.ts.map +1 -1
  71. package/lib/hooks/useGroupActivities.js +1 -1
  72. package/lib/hooks/useLastAcknowledgedActivityKey.d.ts +3 -0
  73. package/lib/hooks/useLastAcknowledgedActivityKey.d.ts.map +1 -0
  74. package/lib/hooks/useLastAcknowledgedActivityKey.js +14 -0
  75. package/lib/hooks/useLastReadActivityKey.d.ts +3 -0
  76. package/lib/hooks/useLastReadActivityKey.d.ts.map +1 -0
  77. package/lib/hooks/useLastReadActivityKey.js +14 -0
  78. package/lib/hooks/useLocalizer.d.ts +1 -1
  79. package/lib/hooks/useLocalizer.d.ts.map +1 -1
  80. package/lib/hooks/useLocalizer.js +9 -3
  81. package/lib/hooks/useMarkActivityAsSpoken.d.ts +2 -2
  82. package/lib/hooks/useMarkActivityAsSpoken.d.ts.map +1 -1
  83. package/lib/hooks/useMarkActivityAsSpoken.js +1 -1
  84. package/lib/hooks/useMarkActivityKeyAsRead.d.ts +3 -0
  85. package/lib/hooks/useMarkActivityKeyAsRead.d.ts.map +1 -0
  86. package/lib/hooks/useMarkActivityKeyAsRead.js +14 -0
  87. package/lib/hooks/useMarkAllAsAcknowledged.d.ts +3 -0
  88. package/lib/hooks/useMarkAllAsAcknowledged.d.ts.map +1 -0
  89. package/lib/hooks/useMarkAllAsAcknowledged.js +14 -0
  90. package/lib/hooks/usePerformCardAction.d.ts +2 -2
  91. package/lib/hooks/usePerformCardAction.d.ts.map +1 -1
  92. package/lib/hooks/usePerformCardAction.js +1 -1
  93. package/lib/hooks/usePostActivity.d.ts +2 -2
  94. package/lib/hooks/usePostActivity.d.ts.map +1 -1
  95. package/lib/hooks/usePostActivity.js +1 -1
  96. package/lib/hooks/useSendFiles.d.ts +8 -1
  97. package/lib/hooks/useSendFiles.d.ts.map +1 -1
  98. package/lib/hooks/useSendFiles.js +1 -1
  99. package/lib/hooks/useSendTimeoutForActivity.d.ts +2 -2
  100. package/lib/hooks/useSendTimeoutForActivity.d.ts.map +1 -1
  101. package/lib/hooks/useSendTimeoutForActivity.js +1 -1
  102. package/lib/hooks/useSubmitSendBox.d.ts.map +1 -1
  103. package/lib/hooks/useSubmitSendBox.js +8 -5
  104. package/lib/hooks/useSuggestedActions.d.ts +1 -1
  105. package/lib/hooks/useSuggestedActions.d.ts.map +1 -1
  106. package/lib/hooks/useSuggestedActions.js +1 -1
  107. package/lib/hooks/useTimeoutForSend.d.ts +2 -2
  108. package/lib/hooks/useTimeoutForSend.d.ts.map +1 -1
  109. package/lib/hooks/useTimeoutForSend.js +1 -1
  110. package/lib/hooks/useTrackException.js +2 -2
  111. package/lib/hooks/utils/ErrorBoundary.js +4 -4
  112. package/lib/index.js +8 -8
  113. package/lib/localization/Localize.d.ts.map +1 -1
  114. package/lib/localization/Localize.js +12 -6
  115. package/lib/localization/ar-SA.json +23 -4
  116. package/lib/localization/bg-BG.json +23 -4
  117. package/lib/localization/ca-ES.json +23 -4
  118. package/lib/localization/cs-CZ.json +23 -4
  119. package/lib/localization/da-DK.json +23 -4
  120. package/lib/localization/de-DE.json +23 -4
  121. package/lib/localization/el-GR.json +23 -4
  122. package/lib/localization/en-US.json +34 -9
  123. package/lib/localization/es-ES.json +23 -4
  124. package/lib/localization/et-EE.json +23 -4
  125. package/lib/localization/eu-ES.json +23 -4
  126. package/lib/localization/fi-FI.json +23 -4
  127. package/lib/localization/fr-FR.json +23 -4
  128. package/lib/localization/gl-ES.json +23 -4
  129. package/lib/localization/he-IL.json +23 -4
  130. package/lib/localization/hi-IN.json +23 -4
  131. package/lib/localization/hr-HR.json +23 -4
  132. package/lib/localization/hu-HU.json +23 -4
  133. package/lib/localization/id-ID.json +23 -4
  134. package/lib/localization/it-IT.json +23 -4
  135. package/lib/localization/ja-JP.json +23 -4
  136. package/lib/localization/kk-KZ.json +23 -4
  137. package/lib/localization/ko-KR.json +23 -4
  138. package/lib/localization/lt-LT.json +23 -4
  139. package/lib/localization/lv-LV.json +23 -4
  140. package/lib/localization/mergeLocalizedStrings.d.ts.map +1 -1
  141. package/lib/localization/mergeLocalizedStrings.js +13 -6
  142. package/lib/localization/ms-MY.json +23 -4
  143. package/lib/localization/nb-NO.json +23 -4
  144. package/lib/localization/nl-NL.json +23 -4
  145. package/lib/localization/pl-PL.json +23 -4
  146. package/lib/localization/pt-BR.json +23 -4
  147. package/lib/localization/pt-PT.json +23 -4
  148. package/lib/localization/ro-RO.json +23 -4
  149. package/lib/localization/ru-RU.json +23 -4
  150. package/lib/localization/sk-SK.json +23 -4
  151. package/lib/localization/sl-SI.json +23 -4
  152. package/lib/localization/sr-Cyrl-CS.json +23 -4
  153. package/lib/localization/sr-Latn-CS.json +23 -4
  154. package/lib/localization/sv-SE.json +23 -4
  155. package/lib/localization/th-TH.json +23 -4
  156. package/lib/localization/tr-TR.json +23 -4
  157. package/lib/localization/uk-UA.json +23 -4
  158. package/lib/localization/vi-VN.json +23 -4
  159. package/lib/localization/yue.json +26 -7
  160. package/lib/localization/zh-CN.json +23 -4
  161. package/lib/localization/zh-HK.json +23 -4
  162. package/lib/localization/zh-TW.json +23 -4
  163. package/lib/normalizeStyleOptions.d.ts.map +1 -1
  164. package/lib/normalizeStyleOptions.js +49 -4
  165. package/lib/patchStyleOptionsFromDeprecatedProps.js +1 -2
  166. package/lib/providers/ActivityAcknowledgement/ActivityAcknowledgementComposer.d.ts +5 -0
  167. package/lib/providers/ActivityAcknowledgement/ActivityAcknowledgementComposer.d.ts.map +1 -0
  168. package/lib/providers/ActivityAcknowledgement/ActivityAcknowledgementComposer.js +184 -0
  169. package/lib/providers/ActivityAcknowledgement/private/Context.d.ts +13 -0
  170. package/lib/providers/ActivityAcknowledgement/private/Context.d.ts.map +1 -0
  171. package/lib/providers/ActivityAcknowledgement/private/Context.js +13 -0
  172. package/lib/providers/ActivityAcknowledgement/private/types.d.ts +6 -0
  173. package/lib/providers/ActivityAcknowledgement/private/types.d.ts.map +1 -0
  174. package/lib/providers/ActivityAcknowledgement/private/types.js +2 -0
  175. package/lib/providers/ActivityAcknowledgement/private/useContext.d.ts +3 -0
  176. package/lib/providers/ActivityAcknowledgement/private/useContext.d.ts.map +1 -0
  177. package/lib/providers/ActivityAcknowledgement/private/useContext.js +24 -0
  178. package/lib/providers/ActivityAcknowledgement/useActivityKeysByRead.d.ts +5 -0
  179. package/lib/providers/ActivityAcknowledgement/useActivityKeysByRead.d.ts.map +1 -0
  180. package/lib/providers/ActivityAcknowledgement/useActivityKeysByRead.js +18 -0
  181. package/lib/providers/ActivityAcknowledgement/useGetHasAcknowledgedByActivityKey.d.ts +2 -0
  182. package/lib/providers/ActivityAcknowledgement/useGetHasAcknowledgedByActivityKey.d.ts.map +1 -0
  183. package/lib/providers/ActivityAcknowledgement/useGetHasAcknowledgedByActivityKey.js +15 -0
  184. package/lib/providers/ActivityAcknowledgement/useLastAcknowledgedActivityKey.d.ts +2 -0
  185. package/lib/providers/ActivityAcknowledgement/useLastAcknowledgedActivityKey.d.ts.map +1 -0
  186. package/lib/providers/ActivityAcknowledgement/useLastAcknowledgedActivityKey.js +15 -0
  187. package/lib/providers/ActivityAcknowledgement/useLastReadActivityKey.d.ts +2 -0
  188. package/lib/providers/ActivityAcknowledgement/useLastReadActivityKey.d.ts.map +1 -0
  189. package/lib/providers/ActivityAcknowledgement/useLastReadActivityKey.js +15 -0
  190. package/lib/providers/ActivityAcknowledgement/useMarkActivityKeyAsRead.d.ts +2 -0
  191. package/lib/providers/ActivityAcknowledgement/useMarkActivityKeyAsRead.d.ts.map +1 -0
  192. package/lib/providers/ActivityAcknowledgement/useMarkActivityKeyAsRead.js +15 -0
  193. package/lib/providers/ActivityAcknowledgement/useMarkAllAsAcknowledged.d.ts +2 -0
  194. package/lib/providers/ActivityAcknowledgement/useMarkAllAsAcknowledged.d.ts.map +1 -0
  195. package/lib/providers/ActivityAcknowledgement/useMarkAllAsAcknowledged.js +15 -0
  196. package/lib/providers/ActivityKeyer/ActivityKeyerComposer.d.ts +18 -0
  197. package/lib/providers/ActivityKeyer/ActivityKeyerComposer.d.ts.map +1 -0
  198. package/lib/providers/ActivityKeyer/ActivityKeyerComposer.js +153 -0
  199. package/lib/providers/ActivityKeyer/private/Context.d.ts +12 -0
  200. package/lib/providers/ActivityKeyer/private/Context.d.ts.map +1 -0
  201. package/lib/providers/ActivityKeyer/private/Context.js +13 -0
  202. package/lib/providers/ActivityKeyer/private/getActivityId.d.ts +3 -0
  203. package/lib/providers/ActivityKeyer/private/getActivityId.d.ts.map +1 -0
  204. package/lib/providers/ActivityKeyer/private/getActivityId.js +11 -0
  205. package/lib/providers/ActivityKeyer/private/getClientActivityId.d.ts +3 -0
  206. package/lib/providers/ActivityKeyer/private/getClientActivityId.d.ts.map +1 -0
  207. package/lib/providers/ActivityKeyer/private/getClientActivityId.js +13 -0
  208. package/lib/providers/ActivityKeyer/private/uniqueId.d.ts +2 -0
  209. package/lib/providers/ActivityKeyer/private/uniqueId.d.ts.map +1 -0
  210. package/lib/providers/ActivityKeyer/private/uniqueId.js +18 -0
  211. package/lib/providers/ActivityKeyer/private/useContext.d.ts +3 -0
  212. package/lib/providers/ActivityKeyer/private/useContext.d.ts.map +1 -0
  213. package/lib/providers/ActivityKeyer/private/useContext.js +24 -0
  214. package/lib/providers/ActivityKeyer/useActivityKeys.d.ts +2 -0
  215. package/lib/providers/ActivityKeyer/useActivityKeys.d.ts.map +1 -0
  216. package/lib/providers/ActivityKeyer/useActivityKeys.js +15 -0
  217. package/lib/providers/ActivityKeyer/useGetActivityByKey.d.ts +3 -0
  218. package/lib/providers/ActivityKeyer/useGetActivityByKey.d.ts.map +1 -0
  219. package/lib/providers/ActivityKeyer/useGetActivityByKey.js +15 -0
  220. package/lib/providers/ActivityKeyer/useGetKeyByActivity.d.ts +3 -0
  221. package/lib/providers/ActivityKeyer/useGetKeyByActivity.d.ts.map +1 -0
  222. package/lib/providers/ActivityKeyer/useGetKeyByActivity.js +15 -0
  223. package/lib/providers/ActivityKeyer/useGetKeyByActivityId.d.ts +2 -0
  224. package/lib/providers/ActivityKeyer/useGetKeyByActivityId.d.ts.map +1 -0
  225. package/lib/providers/ActivityKeyer/useGetKeyByActivityId.js +15 -0
  226. package/lib/types/ActivityMiddleware.d.ts +3 -3
  227. package/lib/types/ActivityMiddleware.d.ts.map +1 -1
  228. package/lib/types/ActivityStatusMiddleware.d.ts +3 -3
  229. package/lib/types/ActivityStatusMiddleware.d.ts.map +1 -1
  230. package/lib/types/AttachmentForScreenReaderMiddleware.d.ts +2 -2
  231. package/lib/types/AttachmentForScreenReaderMiddleware.d.ts.map +1 -1
  232. package/lib/types/AttachmentMiddleware.d.ts +2 -2
  233. package/lib/types/AttachmentMiddleware.d.ts.map +1 -1
  234. package/lib/types/AvatarMiddleware.d.ts +2 -2
  235. package/lib/types/AvatarMiddleware.d.ts.map +1 -1
  236. package/lib/types/CardActionMiddleware.d.ts +4 -2
  237. package/lib/types/CardActionMiddleware.d.ts.map +1 -1
  238. package/lib/types/GroupActivitiesMiddleware.d.ts +7 -7
  239. package/lib/types/GroupActivitiesMiddleware.d.ts.map +1 -1
  240. package/lib/types/WebSpeechPonyfill.d.ts +1 -0
  241. package/lib/types/WebSpeechPonyfill.d.ts.map +1 -1
  242. package/lib/utils/createCustomEvent.d.ts.map +1 -1
  243. package/lib/utils/createCustomEvent.js +8 -2
  244. package/lib/utils/findLastIndex.d.ts +2 -0
  245. package/lib/utils/findLastIndex.d.ts.map +1 -0
  246. package/lib/utils/findLastIndex.js +32 -0
  247. package/lib/utils/findMin.js +1 -1
  248. package/lib/utils/mapMap.d.ts.map +1 -1
  249. package/lib/utils/mapMap.js +9 -2
  250. package/lib/utils/randomId.d.ts.map +1 -1
  251. package/lib/utils/randomId.js +1 -1
  252. package/package.json +26 -29
  253. package/src/StyleOptions.ts +295 -14
  254. package/src/defaultStyleOptions.ts +71 -13
  255. package/src/hooks/Composer.tsx +90 -54
  256. package/src/hooks/index.ts +20 -0
  257. package/src/hooks/internal/WebChatAPIContext.ts +3 -3
  258. package/src/hooks/internal/useCreateActivityRendererInternal.ts +21 -20
  259. package/src/hooks/internal/useDebugDeps.js +9 -2
  260. package/src/hooks/internal/usePrevious.ts +11 -0
  261. package/src/hooks/internal/useValueRef.ts +21 -0
  262. package/src/hooks/middleware/concatMiddleware.ts +6 -4
  263. package/src/hooks/middleware/createDefaultCardActionMiddleware.ts +29 -27
  264. package/src/hooks/middleware/createDefaultGroupActivitiesMiddleware.ts +18 -6
  265. package/src/hooks/useActiveTyping.ts +5 -3
  266. package/src/hooks/useActivities.ts +2 -2
  267. package/src/hooks/useActivityKeys.ts +3 -0
  268. package/src/hooks/useActivityKeysByRead.ts +3 -0
  269. package/src/hooks/useCreateActivityStatusRenderer.tsx +65 -34
  270. package/src/hooks/useCreateAvatarRenderer.ts +24 -20
  271. package/src/hooks/useDateFormatter.ts +4 -3
  272. package/src/hooks/useGetActivityByKey.ts +3 -0
  273. package/src/hooks/useGetHasAcknowledgedByActivityKey.ts +3 -0
  274. package/src/hooks/useGetKeyByActivity.ts +3 -0
  275. package/src/hooks/useGetKeyByActivityId.ts +3 -0
  276. package/src/hooks/useGetSendTimeoutForActivity.ts +9 -8
  277. package/src/hooks/useGroupActivities.ts +4 -8
  278. package/src/hooks/useLastAcknowledgedActivityKey.ts +3 -0
  279. package/src/hooks/useLastReadActivityKey.ts +3 -0
  280. package/src/hooks/useLocalizer.ts +7 -2
  281. package/src/hooks/useMarkActivityAsSpoken.ts +2 -2
  282. package/src/hooks/useMarkActivityKeyAsRead.ts +3 -0
  283. package/src/hooks/useMarkAllAsAcknowledged.ts +3 -0
  284. package/src/hooks/usePerformCardAction.ts +2 -3
  285. package/src/hooks/usePostActivity.ts +2 -2
  286. package/src/hooks/useSendFiles.ts +8 -1
  287. package/src/hooks/useSendTimeoutForActivity.ts +2 -2
  288. package/src/hooks/useSubmitSendBox.ts +2 -5
  289. package/src/hooks/useSuggestedActions.ts +1 -1
  290. package/src/hooks/useTimeoutForSend.ts +2 -2
  291. package/src/localization/Localize.ts +9 -2
  292. package/src/localization/ar-SA.json +23 -4
  293. package/src/localization/bg-BG.json +23 -4
  294. package/src/localization/ca-ES.json +23 -4
  295. package/src/localization/cs-CZ.json +23 -4
  296. package/src/localization/da-DK.json +23 -4
  297. package/src/localization/de-DE.json +23 -4
  298. package/src/localization/el-GR.json +23 -4
  299. package/src/localization/en-US.json +34 -9
  300. package/src/localization/es-ES.json +23 -4
  301. package/src/localization/et-EE.json +23 -4
  302. package/src/localization/eu-ES.json +23 -4
  303. package/src/localization/fi-FI.json +23 -4
  304. package/src/localization/fr-FR.json +23 -4
  305. package/src/localization/gl-ES.json +23 -4
  306. package/src/localization/he-IL.json +23 -4
  307. package/src/localization/hi-IN.json +23 -4
  308. package/src/localization/hr-HR.json +23 -4
  309. package/src/localization/hu-HU.json +23 -4
  310. package/src/localization/id-ID.json +23 -4
  311. package/src/localization/it-IT.json +23 -4
  312. package/src/localization/ja-JP.json +23 -4
  313. package/src/localization/kk-KZ.json +23 -4
  314. package/src/localization/ko-KR.json +23 -4
  315. package/src/localization/lt-LT.json +23 -4
  316. package/src/localization/lv-LV.json +23 -4
  317. package/src/localization/mergeLocalizedStrings.ts +7 -1
  318. package/src/localization/ms-MY.json +23 -4
  319. package/src/localization/nb-NO.json +23 -4
  320. package/src/localization/nl-NL.json +23 -4
  321. package/src/localization/pl-PL.json +23 -4
  322. package/src/localization/pt-BR.json +23 -4
  323. package/src/localization/pt-PT.json +23 -4
  324. package/src/localization/ro-RO.json +23 -4
  325. package/src/localization/ru-RU.json +23 -4
  326. package/src/localization/sk-SK.json +23 -4
  327. package/src/localization/sl-SI.json +23 -4
  328. package/src/localization/sr-Cyrl-CS.json +23 -4
  329. package/src/localization/sr-Latn-CS.json +23 -4
  330. package/src/localization/sv-SE.json +23 -4
  331. package/src/localization/th-TH.json +23 -4
  332. package/src/localization/tr-TR.json +23 -4
  333. package/src/localization/uk-UA.json +23 -4
  334. package/src/localization/vi-VN.json +23 -4
  335. package/src/localization/yue.json +26 -7
  336. package/src/localization/zh-CN.json +23 -4
  337. package/src/localization/zh-HK.json +23 -4
  338. package/src/localization/zh-TW.json +23 -4
  339. package/src/normalizeStyleOptions.ts +70 -0
  340. package/src/patchStyleOptionsFromDeprecatedProps.js +0 -2
  341. package/src/providers/ActivityAcknowledgement/ActivityAcknowledgementComposer.tsx +180 -0
  342. package/src/providers/ActivityAcknowledgement/private/Context.ts +18 -0
  343. package/src/providers/ActivityAcknowledgement/private/types.ts +6 -0
  344. package/src/providers/ActivityAcknowledgement/private/useContext.ts +19 -0
  345. package/src/providers/ActivityAcknowledgement/useActivityKeysByRead.tsx +8 -0
  346. package/src/providers/ActivityAcknowledgement/useGetHasAcknowledgedByActivityKey.ts +5 -0
  347. package/src/providers/ActivityAcknowledgement/useLastAcknowledgedActivityKey.ts +5 -0
  348. package/src/providers/ActivityAcknowledgement/useLastReadActivityKey.ts +5 -0
  349. package/src/providers/ActivityAcknowledgement/useMarkActivityKeyAsRead.ts +5 -0
  350. package/src/providers/ActivityAcknowledgement/useMarkAllAsAcknowledged.ts +5 -0
  351. package/src/providers/ActivityKeyer/ActivityKeyerComposer.tsx +150 -0
  352. package/src/providers/ActivityKeyer/private/Context.ts +13 -0
  353. package/src/providers/ActivityKeyer/private/getActivityId.ts +5 -0
  354. package/src/providers/ActivityKeyer/private/getClientActivityId.ts +5 -0
  355. package/src/providers/ActivityKeyer/private/uniqueId.ts +8 -0
  356. package/src/providers/ActivityKeyer/private/useContext.ts +15 -0
  357. package/src/providers/ActivityKeyer/useActivityKeys.ts +5 -0
  358. package/src/providers/ActivityKeyer/useGetActivityByKey.ts +7 -0
  359. package/src/providers/ActivityKeyer/useGetKeyByActivity.ts +7 -0
  360. package/src/providers/ActivityKeyer/useGetKeyByActivityId.ts +5 -0
  361. package/src/types/ActivityMiddleware.ts +3 -3
  362. package/src/types/ActivityStatusMiddleware.ts +3 -3
  363. package/src/types/AttachmentForScreenReaderMiddleware.ts +2 -2
  364. package/src/types/AttachmentMiddleware.ts +2 -2
  365. package/src/types/AvatarMiddleware.ts +2 -2
  366. package/src/types/CardActionMiddleware.ts +2 -2
  367. package/src/types/GroupActivitiesMiddleware.ts +7 -7
  368. package/src/utils/createCustomEvent.ts +7 -1
  369. package/src/utils/findLastIndex.spec.js +31 -0
  370. package/src/utils/findLastIndex.ts +11 -0
  371. package/src/utils/mapMap.ts +7 -1
  372. package/src/utils/randomId.ts +1 -1
  373. package/.eslintignore +0 -1
@@ -2,18 +2,14 @@ import { Provider } from 'react-redux';
2
2
  import PropTypes from 'prop-types';
3
3
  import React, { FC, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import updateIn from 'simple-update-in';
5
-
6
5
  import {
7
6
  clearSuggestedActions,
8
7
  connect as createConnectAction,
9
8
  createStore,
10
- DirectLineActivity,
11
- DirectLineJSBotConnection,
12
9
  disconnect,
13
10
  dismissNotification,
14
11
  emitTypingIndicator,
15
12
  markActivity,
16
- OneOrMany,
17
13
  postActivity,
18
14
  sendEvent,
19
15
  sendFiles,
@@ -34,8 +30,11 @@ import {
34
30
  stopSpeakingActivity,
35
31
  submitSendBox
36
32
  } from 'botframework-webchat-core';
33
+ import type { DirectLineJSBotConnection, OneOrMany, WebChatActivity } from 'botframework-webchat-core';
37
34
 
38
35
  import { default as WebChatAPIContext } from './internal/WebChatAPIContext';
36
+ import ActivityAcknowledgementComposer from '../providers/ActivityAcknowledgement/ActivityAcknowledgementComposer';
37
+ import ActivityKeyerComposer from '../providers/ActivityKeyer/ActivityKeyerComposer';
39
38
  import ActivityMiddleware from '../types/ActivityMiddleware';
40
39
  import ActivityStatusMiddleware from '../types/ActivityStatusMiddleware';
41
40
  import AttachmentForScreenReaderMiddleware from '../types/AttachmentForScreenReaderMiddleware';
@@ -63,6 +62,7 @@ import TelemetryMeasurementEvent, { TelemetryExceptionMeasurementEvent } from '.
63
62
  import ToastMiddleware from '../types/ToastMiddleware';
64
63
  import Tracker from './internal/Tracker';
65
64
  import TypingIndicatorMiddleware from '../types/TypingIndicatorMiddleware';
65
+ import useMarkAllAsAcknowledged from './useMarkAllAsAcknowledged';
66
66
  import WebChatReduxContext, { useDispatch } from './internal/WebChatReduxContext';
67
67
 
68
68
  import applyMiddleware, {
@@ -98,7 +98,7 @@ const DISPATCHERS = {
98
98
  submitSendBox
99
99
  };
100
100
 
101
- function createCardActionContext({ cardActionMiddleware, directLine, dispatch }) {
101
+ function createCardActionContext({ cardActionMiddleware, directLine, dispatch, markAllAsAcknowledged }) {
102
102
  const runMiddleware = applyMiddleware(
103
103
  'card action',
104
104
  ...singleToArray(cardActionMiddleware),
@@ -106,8 +106,10 @@ function createCardActionContext({ cardActionMiddleware, directLine, dispatch })
106
106
  )({ dispatch });
107
107
 
108
108
  return {
109
- onCardAction: (cardAction, { target }: { target?: any } = {}) =>
110
- runMiddleware({
109
+ onCardAction: (cardAction, { target }: { target?: any } = {}) => {
110
+ markAllAsAcknowledged();
111
+
112
+ return runMiddleware({
111
113
  cardAction,
112
114
  getSignInUrl:
113
115
  cardAction.type === 'signin'
@@ -131,7 +133,8 @@ function createCardActionContext({ cardActionMiddleware, directLine, dispatch })
131
133
  }
132
134
  : null,
133
135
  target
134
- })
136
+ });
137
+ }
135
138
  };
136
139
  }
137
140
 
@@ -167,6 +170,12 @@ function mergeStringsOverrides(localizedStrings, language, overrideLocalizedStri
167
170
  return { ...localizedStrings, ...overrideLocalizedStrings };
168
171
  }
169
172
 
173
+ // It seems "react/require-default-props" did not pick up `ComposerCore.defaultProps`.
174
+ // And it falsely complaint `optional?: string` must have a corresponding `ComposerCore.defaultProps.optional = undefined`, even we already set it below.
175
+ // Since we set both TypeScript `Props` class and `ComposerCore.propTypes`, this check will be done there as well.
176
+ // Ignoring it in TypeScript version should be safe, as we have `propTypes` version to protect us.
177
+
178
+ /* eslint-disable react/require-default-props */
170
179
  type ComposerCoreProps = {
171
180
  activityMiddleware?: OneOrMany<ActivityMiddleware>;
172
181
  activityStatusMiddleware?: OneOrMany<ActivityStatusMiddleware>;
@@ -182,13 +191,12 @@ type ComposerCoreProps = {
182
191
  grammars?: any;
183
192
  groupActivitiesMiddleware?: OneOrMany<GroupActivitiesMiddleware>;
184
193
  internalErrorBoxClass?: React.Component | Function;
185
- internalRenderErrorBox?: any;
186
194
  locale?: string;
187
195
  onTelemetry?: (event: TelemetryMeasurementEvent) => void;
188
196
  overrideLocalizedStrings?: LocalizedStrings | ((strings: LocalizedStrings, language: string) => LocalizedStrings);
189
197
  renderMarkdown?: (markdown: string, { markdownRespectCRLF: boolean }, { externalLinkAlt: string }) => string;
190
198
  scrollToEndButtonMiddleware?: OneOrMany<ScrollToEndButtonMiddleware>;
191
- selectVoice?: (voices: typeof window.SpeechSynthesisVoice[], activity: DirectLineActivity) => void;
199
+ selectVoice?: (voices: typeof window.SpeechSynthesisVoice[], activity: WebChatActivity) => void;
192
200
  sendTypingIndicator?: boolean;
193
201
  styleOptions?: StyleOptions;
194
202
  toastMiddleware?: OneOrMany<ToastMiddleware>;
@@ -213,6 +221,7 @@ type ComposerCoreProps = {
213
221
  /** @deprecated Please use "typingIndicatorRenderer" instead. */
214
222
  typingIndicatorRenderer?: any; // TODO: [P4] Remove on or after 2022-06-15.
215
223
  };
224
+ /* eslint-enable react/require-default-props */
216
225
 
217
226
  const ComposerCore: FC<ComposerCoreProps> = ({
218
227
  activityMiddleware,
@@ -289,16 +298,17 @@ const ComposerCore: FC<ComposerCoreProps> = ({
289
298
  };
290
299
  }, [dispatch, directLine, userID, username]);
291
300
 
292
- const cardActionContext = useMemo(() => createCardActionContext({ cardActionMiddleware, directLine, dispatch }), [
293
- cardActionMiddleware,
294
- directLine,
295
- dispatch
296
- ]);
301
+ const markAllAsAcknowledged = useMarkAllAsAcknowledged();
302
+
303
+ const cardActionContext = useMemo(
304
+ () => createCardActionContext({ cardActionMiddleware, directLine, dispatch, markAllAsAcknowledged }),
305
+ [cardActionMiddleware, directLine, dispatch, markAllAsAcknowledged]
306
+ );
297
307
 
298
- const patchedSelectVoice = useMemo(() => selectVoice || defaultSelectVoice.bind(null, { language: locale }), [
299
- locale,
300
- selectVoice
301
- ]);
308
+ const patchedSelectVoice = useMemo(
309
+ () => selectVoice || defaultSelectVoice.bind(null, { language: locale }),
310
+ [locale, selectVoice]
311
+ );
302
312
 
303
313
  const groupActivitiesContext = useMemo(
304
314
  () =>
@@ -310,7 +320,13 @@ const ComposerCore: FC<ComposerCoreProps> = ({
310
320
  );
311
321
 
312
322
  const hoistedDispatchers = useMemo(
313
- () => mapMap(DISPATCHERS, dispatcher => (...args) => dispatch(dispatcher(...args))),
323
+ () =>
324
+ mapMap(
325
+ DISPATCHERS,
326
+ dispatcher =>
327
+ (...args) =>
328
+ dispatch(dispatcher(...args))
329
+ ),
314
330
  [dispatch]
315
331
  );
316
332
 
@@ -358,13 +374,15 @@ const ComposerCore: FC<ComposerCoreProps> = ({
358
374
  'activity',
359
375
  { strict: false },
360
376
  ...singleToArray(activityMiddleware),
361
- () => () => ({ activity }) => {
362
- if (activity) {
363
- throw new Error(`No renderer for activity of type "${activity.type}"`);
364
- } else {
365
- throw new Error('No activity to render');
377
+ () =>
378
+ () =>
379
+ ({ activity }) => {
380
+ if (activity) {
381
+ throw new Error(`No renderer for activity of type "${activity.type}"`);
382
+ } else {
383
+ throw new Error('No activity to render');
384
+ }
366
385
  }
367
- }
368
386
  )({})
369
387
  );
370
388
  }, [activityMiddleware, activityRenderer]);
@@ -392,19 +410,21 @@ const ComposerCore: FC<ComposerCoreProps> = ({
392
410
  'attachment for screen reader',
393
411
  { strict: true },
394
412
  ...singleToArray(attachmentForScreenReaderMiddleware),
395
- () => () => ({ attachment }) => {
396
- if (attachment) {
397
- console.warn(`No renderer for attachment for screen reader of type "${attachment.contentType}"`);
398
- return false;
413
+ () =>
414
+ () =>
415
+ ({ attachment }) => {
416
+ if (attachment) {
417
+ console.warn(`No renderer for attachment for screen reader of type "${attachment.contentType}"`);
418
+ return false;
419
+ }
420
+
421
+ return () => {
422
+ /**
423
+ * @todo TODO: [P4] Might be able to throw without returning a function -- investigate and possibly fix
424
+ */
425
+ throw new Error('No attachment to render');
426
+ };
399
427
  }
400
-
401
- return () => {
402
- /**
403
- * @todo TODO: [P4] Might be able to throw without returning a function -- investigate and possibly fix
404
- */
405
- throw new Error('No attachment to render');
406
- };
407
- }
408
428
  )({}),
409
429
  [attachmentForScreenReaderMiddleware]
410
430
  );
@@ -422,13 +442,15 @@ const ComposerCore: FC<ComposerCoreProps> = ({
422
442
  return applyMiddlewareForLegacyRenderer(
423
443
  'attachment',
424
444
  ...singleToArray(attachmentMiddleware),
425
- () => () => ({ attachment }) => {
426
- if (attachment) {
427
- throw new Error(`No renderer for attachment of type "${attachment.contentType}"`);
428
- } else {
429
- throw new Error('No attachment to render');
445
+ () =>
446
+ () =>
447
+ ({ attachment }) => {
448
+ if (attachment) {
449
+ throw new Error(`No renderer for attachment of type "${attachment.contentType}"`);
450
+ } else {
451
+ throw new Error('No attachment to render');
452
+ }
430
453
  }
431
- }
432
454
  )({});
433
455
  }, [attachmentMiddleware, attachmentRenderer]);
434
456
 
@@ -440,8 +462,11 @@ const ComposerCore: FC<ComposerCoreProps> = ({
440
462
 
441
463
  return (
442
464
  avatarRenderer ||
443
- applyMiddlewareForRenderer('avatar', { strict: false }, ...singleToArray(avatarMiddleware), () => () => () =>
444
- false
465
+ applyMiddlewareForRenderer(
466
+ 'avatar',
467
+ { strict: false },
468
+ ...singleToArray(avatarMiddleware),
469
+ () => () => () => false
445
470
  )({})
446
471
  );
447
472
  }, [avatarMiddleware, avatarRenderer]);
@@ -458,13 +483,15 @@ const ComposerCore: FC<ComposerCoreProps> = ({
458
483
  'toast',
459
484
  { strict: false },
460
485
  ...singleToArray(toastMiddleware),
461
- () => () => ({ notification }) => {
462
- if (notification) {
463
- throw new Error(`No renderer for notification of type "${notification.contentType}"`);
464
- } else {
465
- throw new Error('No notification to render');
486
+ () =>
487
+ () =>
488
+ ({ notification }) => {
489
+ if (notification) {
490
+ throw new Error(`No renderer for notification of type "${notification.contentType}"`);
491
+ } else {
492
+ throw new Error('No notification to render');
493
+ }
466
494
  }
467
- }
468
495
  )({})
469
496
  );
470
497
  }, [toastMiddleware, toastRenderer]);
@@ -636,6 +663,8 @@ ComposerCore.propTypes = {
636
663
  cardActionMiddleware: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.func), PropTypes.func]),
637
664
  children: PropTypes.any,
638
665
  dir: PropTypes.oneOf(['auto', 'ltr', 'rtl']),
666
+ // PropTypes.shape({ ... }) did not honor isRequired for its members.
667
+ // @ts-ignore
639
668
  directLine: PropTypes.shape({
640
669
  activity$: PropTypes.shape({
641
670
  subscribe: PropTypes.func.isRequired
@@ -672,7 +701,10 @@ ComposerCore.propTypes = {
672
701
  username: PropTypes.string
673
702
  };
674
703
 
675
- type ComposerProps = ComposerCoreProps & { store?: any };
704
+ type ComposerProps = ComposerCoreProps & {
705
+ internalRenderErrorBox?: any;
706
+ store?: any;
707
+ };
676
708
 
677
709
  // We will create a Redux store if it was not passed in
678
710
  const Composer: FC<ComposerProps> = ({ internalRenderErrorBox, onTelemetry, store, ...props }) => {
@@ -696,7 +728,11 @@ const Composer: FC<ComposerProps> = ({ internalRenderErrorBox, onTelemetry, stor
696
728
  ) : (
697
729
  <ErrorBoundary onError={handleError}>
698
730
  <Provider context={WebChatReduxContext} store={memoizedStore}>
699
- <ComposerCore internalRenderErrorBox={internalRenderErrorBox} onTelemetry={onTelemetry} {...props} />
731
+ <ActivityKeyerComposer>
732
+ <ActivityAcknowledgementComposer>
733
+ <ComposerCore onTelemetry={onTelemetry} {...props} />
734
+ </ActivityAcknowledgementComposer>
735
+ </ActivityKeyerComposer>
700
736
  </Provider>
701
737
  </ErrorBoundary>
702
738
  );
@@ -1,5 +1,7 @@
1
1
  import useActiveTyping from './useActiveTyping';
2
2
  import useActivities from './useActivities';
3
+ import useActivityKeys from './useActivityKeys';
4
+ import useActivityKeysByRead from './useActivityKeysByRead';
3
5
  import useAvatarForBot from './useAvatarForBot';
4
6
  import useAvatarForUser from './useAvatarForUser';
5
7
  import useByteFormatter from './useByteFormatter';
@@ -17,16 +19,24 @@ import useDirection from './useDirection';
17
19
  import useDisabled from './useDisabled';
18
20
  import useDismissNotification from './useDismissNotification';
19
21
  import useEmitTypingIndicator from './useEmitTypingIndicator';
22
+ import useGetActivityByKey from './useGetActivityByKey';
23
+ import useGetHasAcknowledgedByActivityKey from './useGetHasAcknowledgedByActivityKey';
24
+ import useGetKeyByActivity from './useGetKeyByActivity';
25
+ import useGetKeyByActivityId from './useGetKeyByActivityId';
20
26
  import useGetSendTimeoutForActivity from './useGetSendTimeoutForActivity';
21
27
  import useGrammars from './useGrammars';
22
28
  import useGroupActivities from './useGroupActivities';
23
29
  import useGroupTimestamp from './useGroupTimestamp';
24
30
  import useLanguage from './useLanguage';
31
+ import useLastAcknowledgedActivityKey from './useLastAcknowledgedActivityKey';
32
+ import useLastReadActivityKey from './useLastReadActivityKey';
25
33
  import useLastTypingAt from './useLastTypingAt';
26
34
  import useLocalize from './useLocalize'; // Deprecated on or after 2022-02-12
27
35
  import useLocalizeDate from './useLocalizeDate'; // Deprecated on or after 2022-02-12
28
36
  import useLocalizer from './useLocalizer';
29
37
  import useMarkActivityAsSpoken from './useMarkActivityAsSpoken';
38
+ import useMarkActivityKeyAsRead from './useMarkActivityKeyAsRead';
39
+ import useMarkAllAsAcknowledged from './useMarkAllAsAcknowledged';
30
40
  import usePerformCardAction from './usePerformCardAction';
31
41
  import usePostActivity from './usePostActivity';
32
42
  import useReferenceGrammarID from './useReferenceGrammarID';
@@ -64,6 +74,8 @@ import useVoiceSelector from './useVoiceSelector';
64
74
  export {
65
75
  useActiveTyping,
66
76
  useActivities,
77
+ useActivityKeys,
78
+ useActivityKeysByRead,
67
79
  useAvatarForBot,
68
80
  useAvatarForUser,
69
81
  useByteFormatter,
@@ -81,16 +93,24 @@ export {
81
93
  useDisabled,
82
94
  useDismissNotification,
83
95
  useEmitTypingIndicator,
96
+ useGetActivityByKey,
97
+ useGetHasAcknowledgedByActivityKey,
98
+ useGetKeyByActivity,
99
+ useGetKeyByActivityId,
84
100
  useGetSendTimeoutForActivity,
85
101
  useGrammars,
86
102
  useGroupActivities,
87
103
  useGroupTimestamp,
88
104
  useLanguage,
105
+ useLastAcknowledgedActivityKey,
106
+ useLastReadActivityKey,
89
107
  useLastTypingAt,
90
108
  useLocalize,
91
109
  useLocalizeDate,
92
110
  useLocalizer,
93
111
  useMarkActivityAsSpoken,
112
+ useMarkActivityKeyAsRead,
113
+ useMarkAllAsAcknowledged,
94
114
  usePerformCardAction,
95
115
  usePostActivity,
96
116
  useReferenceGrammarID,
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react';
2
- import { DirectLineActivity, DirectLineJSBotConnection } from 'botframework-webchat-core';
2
+ import type { DirectLineJSBotConnection, WebChatActivity } from 'botframework-webchat-core';
3
3
 
4
4
  import { AttachmentForScreenReaderComponentFactory } from '../../types/AttachmentForScreenReaderMiddleware';
5
5
  import { AvatarComponentFactory } from '../../types/AvatarMiddleware';
@@ -38,10 +38,10 @@ type WebChatAPIContext = {
38
38
  markActivity?: ({ id: string }, name: string, value?: any) => void;
39
39
  onCardAction?: PerformCardAction;
40
40
  onTelemetry?: (event: TelemetryMeasurementEvent) => void;
41
- postActivity?: (activity: DirectLineActivity) => Observable<string>;
41
+ postActivity?: (activity: WebChatActivity) => Observable<string>;
42
42
  renderMarkdown?: (markdown: string, { markdownRespectCRLF: boolean }, { externalLinkAlt: string }) => string;
43
43
  scrollToEndButtonRenderer?: ScrollToEndButtonComponentFactory;
44
- selectVoice?: (voices: typeof window.SpeechSynthesisVoice[], activity: DirectLineActivity) => void;
44
+ selectVoice?: (voices: typeof window.SpeechSynthesisVoice[], activity: WebChatActivity) => void;
45
45
  sendEvent?: (name: string, value: any) => void;
46
46
  sendFiles?: (files: File[]) => void;
47
47
  sendMessage?: (text: string, method?: string, { channelData }?: { channelData?: any }) => void;
@@ -14,32 +14,33 @@ export default function useCreateActivityRendererInternal(
14
14
  const renderAttachment: RenderAttachment = renderAttachmentOverride || defaultRenderAttachment;
15
15
 
16
16
  return useMemo(
17
- () => (...createActivityRendererOptions) => {
18
- const renderActivity = createActivityRenderer(...createActivityRendererOptions);
17
+ () =>
18
+ (...createActivityRendererOptions) => {
19
+ const renderActivity = createActivityRenderer(...createActivityRendererOptions);
19
20
 
20
- if (!renderActivity) {
21
- return false;
22
- }
23
-
24
- return renderActivityOptions => {
25
- if (isValidElement(renderActivity)) {
26
- return renderActivity;
21
+ if (!renderActivity) {
22
+ return false;
27
23
  }
28
24
 
29
- const activityElement = renderActivity(
30
- (...renderAttachmentArgs) => renderAttachment(...renderAttachmentArgs),
31
- renderActivityOptions
32
- );
25
+ return renderActivityOptions => {
26
+ if (isValidElement(renderActivity)) {
27
+ return renderActivity;
28
+ }
33
29
 
34
- // "activityElement" cannot be false. If the middleware want to hide the "activityElement", it should return "false" when we call createActivityRenderer().
35
- activityElement ||
36
- console.warn(
37
- 'botframework-webchat: To hide an activity, the activity renderer should return false. It should not return a function that will return false when called.'
30
+ const activityElement = renderActivity(
31
+ (...renderAttachmentArgs) => renderAttachment(...renderAttachmentArgs),
32
+ renderActivityOptions
38
33
  );
39
34
 
40
- return activityElement;
41
- };
42
- },
35
+ // "activityElement" cannot be false. If the middleware want to hide the "activityElement", it should return "false" when we call createActivityRenderer().
36
+ activityElement ||
37
+ console.warn(
38
+ 'botframework-webchat: To hide an activity, the activity renderer should return false. It should not return a function that will return false when called.'
39
+ );
40
+
41
+ return activityElement;
42
+ };
43
+ },
43
44
  [createActivityRenderer, renderAttachment]
44
45
  );
45
46
  }
@@ -1,5 +1,6 @@
1
1
  /* eslint no-console: "off" */
2
2
 
3
+ import { isForbiddenPropertyNames } from 'botframework-webchat-core';
3
4
  import { useRef } from 'react';
4
5
 
5
6
  export default function useDebugDeps(depsMap, name) {
@@ -7,13 +8,19 @@ export default function useDebugDeps(depsMap, name) {
7
8
 
8
9
  const { current: lastDepsMap } = lastDepsMapRef;
9
10
  const keys = new Set([...Object.keys(depsMap), ...Object.keys(lastDepsMap)]);
10
- const keysChanged = Array.from(keys).filter(key => !Object.is(depsMap[key], lastDepsMap[key]));
11
+ const keysChanged = Array.from(keys).filter(
12
+ // Mitigation through denylisting.
13
+ // eslint-disable-next-line security/detect-object-injection
14
+ key => !isForbiddenPropertyNames(key) && !Object.is(depsMap[key], lastDepsMap[key])
15
+ );
11
16
 
12
17
  if (keysChanged.length) {
13
18
  console.groupCollapsed(`Changes found in ${name}`);
14
19
 
15
20
  keysChanged.forEach(key => {
16
- console.log(key, { from: lastDepsMap[key], to: depsMap[key] });
21
+ // Mitigation through denylisting.
22
+ // eslint-disable-next-line security/detect-object-injection
23
+ isForbiddenPropertyNames(key) || console.log(key, { from: lastDepsMap[key], to: depsMap[key] });
17
24
  });
18
25
 
19
26
  console.groupEnd();
@@ -0,0 +1,11 @@
1
+ import { useEffect, useRef } from 'react';
2
+
3
+ export default function usePrevious<T>(value: T): T {
4
+ const ref = useRef<T>();
5
+
6
+ useEffect(() => {
7
+ ref.current = value;
8
+ });
9
+
10
+ return ref.current;
11
+ }
@@ -0,0 +1,21 @@
1
+ import { RefObject, useMemo, useRef } from 'react';
2
+
3
+ export default function useValueRef<T>(value: T): RefObject<T> {
4
+ const ref = useRef<T>();
5
+ const readOnlyRef = useMemo(
6
+ () =>
7
+ Object.create(
8
+ {},
9
+ {
10
+ current: {
11
+ get: () => ref.current
12
+ }
13
+ }
14
+ ),
15
+ []
16
+ );
17
+
18
+ ref.current = value;
19
+
20
+ return readOnlyRef;
21
+ }
@@ -13,11 +13,13 @@ export default function concatMiddleware<Setup, Result>(
13
13
 
14
14
  return last => {
15
15
  const stack = setup.slice();
16
- const work = index => (...runArgs) => {
17
- const next = stack[index];
16
+ const work =
17
+ (index: number) =>
18
+ (...runArgs) => {
19
+ const next = stack[+index];
18
20
 
19
- return (next ? next(work(index + 1)) : last)(...runArgs);
20
- };
21
+ return (next ? next(work(index + 1)) : last)(...runArgs);
22
+ };
21
23
 
22
24
  return work(0);
23
25
  };
@@ -3,38 +3,40 @@ import { sendMessage, sendMessageBack, sendPostBack } from 'botframework-webchat
3
3
  import CardActionMiddleware from '../../types/CardActionMiddleware';
4
4
 
5
5
  export default function createDefaultCardActionMiddleware(): CardActionMiddleware {
6
- return ({ dispatch }) => next => (...args) => {
7
- const [
8
- {
9
- cardAction,
10
- cardAction: { value }
11
- }
12
- ] = args;
13
-
14
- // We cannot use destructured "type" here because TypeScript don't recognize "messageBack" is "MessageBackCardAction".
15
- switch (cardAction.type) {
16
- case 'imBack':
17
- if (typeof value === 'string') {
18
- // TODO: [P4] Instead of calling dispatch, we should move to dispatchers instead for completeness
19
- dispatch(sendMessage(value, 'imBack'));
20
- } else {
21
- throw new Error('cannot send "imBack" with a non-string value');
6
+ return ({ dispatch }) =>
7
+ next =>
8
+ (...args) => {
9
+ const [
10
+ {
11
+ cardAction,
12
+ cardAction: { value }
22
13
  }
14
+ ] = args;
15
+
16
+ // We cannot use destructured "type" here because TypeScript don't recognize "messageBack" is "MessageBackCardAction".
17
+ switch (cardAction.type) {
18
+ case 'imBack':
19
+ if (typeof value === 'string') {
20
+ // TODO: [P4] Instead of calling dispatch, we should move to dispatchers instead for completeness
21
+ dispatch(sendMessage(value, 'imBack'));
22
+ } else {
23
+ throw new Error('cannot send "imBack" with a non-string value');
24
+ }
23
25
 
24
- break;
26
+ break;
25
27
 
26
- case 'messageBack':
27
- dispatch(sendMessageBack(value, cardAction.text, cardAction.displayText));
28
+ case 'messageBack':
29
+ dispatch(sendMessageBack(value, cardAction.text, cardAction.displayText));
28
30
 
29
- break;
31
+ break;
30
32
 
31
- case 'postBack':
32
- dispatch(sendPostBack(value));
33
+ case 'postBack':
34
+ dispatch(sendPostBack(value));
33
35
 
34
- break;
36
+ break;
35
37
 
36
- default:
37
- return next(...args);
38
- }
39
- };
38
+ default:
39
+ return next(...args);
40
+ }
41
+ };
40
42
  }
@@ -1,9 +1,10 @@
1
- import { Constants, DirectLineActivity } from 'botframework-webchat-core';
1
+ import { Constants } from 'botframework-webchat-core';
2
+ import type { WebChatActivity } from 'botframework-webchat-core';
2
3
 
3
4
  import GroupActivitiesMiddleware from '../../types/GroupActivitiesMiddleware';
4
5
 
5
6
  const {
6
- ActivityClientState: { SENT }
7
+ ActivityClientState: { SENDING, SEND_FAILED, SENT }
7
8
  } = Constants;
8
9
 
9
10
  function bin<T>(items: T[], grouping: (last: T, current: T) => boolean): T[][] {
@@ -25,13 +26,24 @@ function bin<T>(items: T[], grouping: (last: T, current: T) => boolean): T[][] {
25
26
  return bins;
26
27
  }
27
28
 
28
- function sending(activity: DirectLineActivity): boolean {
29
- return activity.from.role === 'user' && activity.channelData && activity.channelData.state !== SENT;
29
+ function sending(activity) {
30
+ if (activity.from.role === 'user') {
31
+ const state = activity.channelData?.state;
32
+
33
+ switch (state) {
34
+ case SENDING:
35
+ case SEND_FAILED:
36
+ return state;
37
+
38
+ default:
39
+ return SENT;
40
+ }
41
+ }
30
42
  }
31
43
 
32
44
  function shouldGroupTimestamp(
33
- activityX: DirectLineActivity,
34
- activityY: DirectLineActivity,
45
+ activityX: WebChatActivity,
46
+ activityY: WebChatActivity,
35
47
  groupTimestamp: boolean | number
36
48
  ): boolean {
37
49
  if (groupTimestamp === false) {
@@ -10,15 +10,17 @@ function useActiveTyping(expireAfter?: number): [{ [userId: string]: Typing }] {
10
10
 
11
11
  const [{ typingAnimationDuration }] = useStyleOptions();
12
12
  const forceRender = useForceRender();
13
- const typing: { [userId: string]: { at: number; name: string; role: string } } = useSelector(({ typing }) => typing);
13
+ const typing: { [userId: string]: { at: number; last: number; name: string; role: string } } = useSelector(
14
+ ({ typing }) => typing
15
+ );
14
16
 
15
17
  if (typeof expireAfter !== 'number') {
16
18
  expireAfter = typingAnimationDuration;
17
19
  }
18
20
 
19
21
  const activeTyping: { [userId: string]: Typing } = Object.entries(typing).reduce(
20
- (activeTyping, [id, { at, name, role }]) => {
21
- const until = at + expireAfter;
22
+ (activeTyping, [id, { at, last, name, role }]) => {
23
+ const until = last + expireAfter;
22
24
 
23
25
  if (until > now) {
24
26
  return { ...activeTyping, [id]: { at, expireAt: until, name, role } };
@@ -1,7 +1,7 @@
1
- import { DirectLineActivity } from 'botframework-webchat-core';
1
+ import type { WebChatActivity } from 'botframework-webchat-core';
2
2
 
3
3
  import { useSelector } from './internal/WebChatReduxContext';
4
4
 
5
- export default function useActivities(): [DirectLineActivity[]] {
5
+ export default function useActivities(): [WebChatActivity[]] {
6
6
  return [useSelector(({ activities }) => activities)];
7
7
  }
@@ -0,0 +1,3 @@
1
+ import useActivityKeys from '../providers/ActivityKeyer/useActivityKeys';
2
+
3
+ export default useActivityKeys;