forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuseSendFiles.ts
More file actions
41 lines (33 loc) · 1.06 KB
/
useSendFiles.ts
File metadata and controls
41 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint no-magic-numbers: ["error", { "ignore": [0, 1024] }] */
import { warnOnce } from '@msinternal/botframework-webchat-base/utils';
import { useCallback } from 'react';
import useWebChatAPIContext from './internal/useWebChatAPIContext';
import useTrackEvent from './useTrackEvent';
type PostActivityFile = {
name: string;
size: number;
thumbnail?: string;
url: string;
};
const warnDeprecation = warnOnce(
'This hook will be removed on or after 2026-04-03. Please use `useSendMessage` instead.'
);
function useSendFiles(): (files: PostActivityFile[]) => void {
const { sendFiles } = useWebChatAPIContext();
const trackEvent = useTrackEvent();
return useCallback(
files => {
if (files && files.length) {
warnDeprecation();
sendFiles(files);
trackEvent('sendFiles', {
numFiles: files.length,
sumSizeInKB: Math.round(files.reduce((total, { size }) => total + size, 0) / 1024)
});
}
},
[sendFiles, trackEvent]
);
}
export default useSendFiles;
export { type PostActivityFile };