@cometchat/chat-uikit-react-native 4.0.2 → 4.1.1

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 (175) hide show
  1. package/README.md +1 -1
  2. package/ios/FileManager.m +1 -1
  3. package/package.json +3 -3
  4. package/src/AI/AIAssistBot/AIAssistBotDecorator.tsx +164 -0
  5. package/src/AI/AIAssistBot/AIAssistBotExtension.tsx +22 -0
  6. package/src/AI/AIAssistBot/AIAssistBotStyle.ts +43 -0
  7. package/src/AI/AIAssistBot/AIAssistBotView.tsx +294 -0
  8. package/src/AI/AIAssistBot/configuration.ts +22 -0
  9. package/src/AI/AIAssistBot/resources/index.ts +5 -0
  10. package/src/AI/{configuration.ts → AIBaseConfiguration.ts} +3 -6
  11. package/src/AI/AIBaseStyle.ts +58 -0
  12. package/src/AI/AIConversationStarter/AIConversationStarter.ts +5 -19
  13. package/src/AI/AIConversationStarter/AIConversationStarterDecorator.tsx +144 -130
  14. package/src/AI/AIConversationStarter/AIConversationStarterStyle.ts +11 -6
  15. package/src/AI/AIConversationStarter/configuration.ts +10 -17
  16. package/src/AI/AIConversationSummary/AIConversationSummaryDecorator.tsx +175 -0
  17. package/src/AI/AIConversationSummary/AIConversationSummaryExtension.ts +21 -0
  18. package/src/AI/AIConversationSummary/AIConversationSummaryStyle.tsx +20 -0
  19. package/src/AI/AIConversationSummary/AIConversationSummaryView.tsx +190 -0
  20. package/src/AI/AIConversationSummary/configuration.ts +14 -0
  21. package/src/AI/AIConversationSummary/resources/close.png +0 -0
  22. package/src/AI/AIConversationSummary/resources/index.ts +5 -0
  23. package/src/AI/AIExtensionDataSource.ts +17 -12
  24. package/src/AI/AIOptionsStyle.ts +14 -0
  25. package/src/AI/AISmartReplies/AISmartReplies.ts +6 -15
  26. package/src/AI/AISmartReplies/AISmartRepliesDecorator.tsx +302 -0
  27. package/src/AI/AISmartReplies/AISmartRepliesStyle.ts +1 -1
  28. package/src/AI/AISmartReplies/configuration.ts +4 -11
  29. package/src/AI/resources/index.ts +0 -2
  30. package/src/AI/utils.ts +3 -3
  31. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +118 -5
  32. package/src/CometChatMessageComposer/MessageComposerConfiguration.tsx +3 -0
  33. package/src/CometChatMessageComposer/resources/index.ts +2 -0
  34. package/src/CometChatMessageComposer/styles.ts +1 -4
  35. package/src/CometChatMessageList/CometChatMessageList.tsx +52 -35
  36. package/src/CometChatMessages/CometChatMessages.tsx +4 -13
  37. package/src/CometChatMessages/MessagesConfiguration.ts +2 -2
  38. package/src/calls/CallEvents.ts +1 -0
  39. package/src/calls/CallUtils.ts +106 -45
  40. package/src/calls/CallingDetailsUtils.tsx +133 -15
  41. package/src/calls/CallingExtentionDecorator.tsx +56 -45
  42. package/src/calls/CallingPackage.ts +16 -2
  43. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +9 -10
  44. package/src/calls/CometChatCallLogDetails/CallLogDetailsConfiguration.ts +116 -0
  45. package/src/calls/CometChatCallLogDetails/CallLogDetailsStyle.ts +36 -0
  46. package/src/calls/CometChatCallLogDetails/CometChatCallLogDetails.tsx +308 -0
  47. package/src/calls/CometChatCallLogDetails/index.ts +12 -0
  48. package/src/calls/CometChatCallLogDetails/resources/CloseIcon.png +0 -0
  49. package/src/calls/{CometChatCallDetails → CometChatCallLogDetails}/style.ts +1 -0
  50. package/src/calls/{CometChatCallHistory/CallHistoryConfiguration.ts → CometChatCallLogHistory/CallLogHistoryConfiguration.ts} +15 -27
  51. package/src/calls/CometChatCallLogHistory/CallLogHistoryStyle.ts +46 -0
  52. package/src/calls/CometChatCallLogHistory/CometChatCallLogHistory.tsx +337 -0
  53. package/src/calls/CometChatCallLogHistory/index.ts +12 -0
  54. package/src/calls/CometChatCallLogHistory/resources/incomingcall.png +0 -0
  55. package/src/calls/CometChatCallLogHistory/resources/incomingvideo.png +0 -0
  56. package/src/calls/CometChatCallLogHistory/resources/index.ts +29 -0
  57. package/src/calls/CometChatCallLogHistory/resources/missedcall.png +0 -0
  58. package/src/calls/CometChatCallLogHistory/resources/missedvideo.png +0 -0
  59. package/src/calls/CometChatCallLogHistory/resources/outgoingcall.png +0 -0
  60. package/src/calls/CometChatCallLogHistory/resources/outgoingvideo.png +0 -0
  61. package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/style.ts +2 -1
  62. package/src/calls/CometChatCallLogParticipants/CallLogParticipantsConfiguration.ts +61 -0
  63. package/src/calls/CometChatCallLogParticipants/CallLogParticipantsStyle.ts +59 -0
  64. package/src/calls/CometChatCallLogParticipants/CometChatCallLogParticipants.tsx +220 -0
  65. package/src/calls/CometChatCallLogParticipants/index.ts +12 -0
  66. package/src/calls/CometChatCallLogParticipants/resources/Back.png +0 -0
  67. package/src/calls/CometChatCallLogParticipants/resources/index.ts +4 -0
  68. package/src/calls/CometChatCallLogParticipants/style.ts +24 -0
  69. package/src/calls/CometChatCallLogRecordings/CallLogRecordingsConfiguration.ts +63 -0
  70. package/src/calls/CometChatCallLogRecordings/CallLogRecordingsStyle.ts +63 -0
  71. package/src/calls/CometChatCallLogRecordings/CometChatCallLogRecordings.tsx +253 -0
  72. package/src/calls/CometChatCallLogRecordings/index.ts +12 -0
  73. package/src/calls/CometChatCallLogRecordings/resources/Back.png +0 -0
  74. package/src/calls/CometChatCallLogRecordings/resources/download.png +0 -0
  75. package/src/calls/CometChatCallLogRecordings/resources/index.ts +6 -0
  76. package/src/calls/CometChatCallLogRecordings/style.ts +24 -0
  77. package/src/calls/CometChatCallLogs/CallLogsConfiguration.ts +87 -0
  78. package/src/calls/CometChatCallLogs/CallLogsStyle.ts +95 -0
  79. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +482 -0
  80. package/src/calls/CometChatCallLogs/index.ts +12 -0
  81. package/src/calls/CometChatCallLogs/resources/Back.png +0 -0
  82. package/src/calls/CometChatCallLogs/resources/Info.png +0 -0
  83. package/src/calls/CometChatCallLogs/resources/Selection.png +0 -0
  84. package/src/calls/CometChatCallLogs/resources/Spinner.png +0 -0
  85. package/src/calls/CometChatCallLogs/resources/check.png +0 -0
  86. package/src/calls/CometChatCallLogs/resources/incomingcall.png +0 -0
  87. package/src/calls/CometChatCallLogs/resources/incomingvideo.png +0 -0
  88. package/src/calls/CometChatCallLogs/resources/index.ts +25 -0
  89. package/src/calls/CometChatCallLogs/resources/missedcall.png +0 -0
  90. package/src/calls/CometChatCallLogs/resources/missedvideo.png +0 -0
  91. package/src/calls/CometChatCallLogs/resources/outgoingcall.png +0 -0
  92. package/src/calls/CometChatCallLogs/resources/outgoingvideo.png +0 -0
  93. package/src/calls/CometChatCallLogs/style.ts +24 -0
  94. package/src/calls/CometChatCallLogsWithDetails/CallLogsWithDetailsConfiguration.ts +9 -0
  95. package/src/calls/{CometChatCallHistoryWithDetails/CometChatCallHistoryWithDetails.tsx → CometChatCallLogsWithDetails/CometChatCallLogsWithDetails.tsx} +17 -16
  96. package/src/calls/CometChatCallLogsWithDetails/index.ts +7 -0
  97. package/src/calls/index.ts +40 -1
  98. package/src/calls/resources/index.ts +3 -1
  99. package/src/calls/resources/nextarrow.png +0 -0
  100. package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +3 -5
  101. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +1 -1
  102. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +5 -3
  103. package/src/extensions/ThumbnailGeneration/resources/empty.png +0 -0
  104. package/src/extensions/ThumbnailGeneration/resources/index.ts +5 -0
  105. package/src/index.ts +79 -4
  106. package/src/shared/CometChatUiKit/CometChatUIKit.ts +154 -130
  107. package/src/shared/CometChatUiKit/UIKitSettings.ts +2 -2
  108. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +4 -1
  109. package/src/shared/events/CometChatUIEventHandler/Listener.ts +5 -1
  110. package/src/shared/framework/DataSource.ts +4 -0
  111. package/src/shared/framework/DataSourceDecorator.tsx +5 -0
  112. package/src/shared/framework/MessageDataSource.tsx +4 -1
  113. package/src/shared/index.ts +4 -0
  114. package/src/shared/modals/CometChatCallLogDetailsOptions.ts +23 -0
  115. package/src/shared/modals/CometChatCallLogDetailsTemplate.ts +16 -0
  116. package/src/shared/modals/index.ts +5 -1
  117. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +19 -5
  118. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +19 -5
  119. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +21 -7
  120. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +19 -5
  121. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +19 -5
  122. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +19 -5
  123. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +19 -5
  124. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +19 -5
  125. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +19 -5
  126. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +19 -5
  127. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +19 -5
  128. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +19 -4
  129. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +19 -5
  130. package/src/shared/resources/CometChatTheme/Palette.ts +16 -0
  131. package/src/shared/utils/DetailsUtils/DetailsUtils.tsx +1 -1
  132. package/src/shared/utils/conversationUtils.ts +1 -1
  133. package/src/shared/views/CometChatAICard/CometChatAICard.tsx +71 -0
  134. package/src/shared/views/CometChatAICard/resources/errormessage.png +0 -0
  135. package/src/shared/views/CometChatAICard/resources/index.ts +4 -0
  136. package/src/shared/views/CometChatAICard/resources/nomessage.png +0 -0
  137. package/src/shared/views/CometChatActionSheet/ActionSheetStyle.ts +4 -0
  138. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +11 -7
  139. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +56 -47
  140. package/src/shared/views/CometChatBottomSheet/style.ts +0 -2
  141. package/src/shared/views/CometChatDate/CometChatDate.tsx +7 -3
  142. package/src/shared/views/CometChatDate/DateConfiguration.ts +4 -0
  143. package/src/shared/views/CometChatDate/style.ts +1 -1
  144. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +31 -19
  145. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -2
  146. package/src/shared/views/CometChatPanel/CometChatPanel.tsx +51 -0
  147. package/src/shared/views/CometChatPanel/PanelStyle.tsx +43 -0
  148. package/src/shared/views/CometChatPanel/resources/CloseIcon.png +0 -0
  149. package/src/shared/views/CometChatPanel/resources/index.ts +5 -0
  150. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +7 -5
  151. package/src/AI/AIEnabler.ts +0 -115
  152. package/src/AI/AIEnablerDecorator.tsx +0 -324
  153. package/src/AI/AISmartReplies/AISmartRepliesDecorator.ts +0 -18
  154. package/src/calls/CometChatCallDetails/CallDetailsConfiguration.ts +0 -68
  155. package/src/calls/CometChatCallDetails/CallDetailsStyle.ts +0 -52
  156. package/src/calls/CometChatCallDetails/CometChatCallDetails.tsx +0 -268
  157. package/src/calls/CometChatCallDetails/index.ts +0 -9
  158. package/src/calls/CometChatCallHistory/CallHistoryStyle.ts +0 -34
  159. package/src/calls/CometChatCallHistory/CometChatCallHistory.tsx +0 -422
  160. package/src/calls/CometChatCallHistory/index.ts +0 -9
  161. package/src/calls/CometChatCallHistory/resources/index.ts +0 -17
  162. package/src/calls/CometChatCallHistoryWithDetails/HistoryWithDetailsConfiguration.ts +0 -7
  163. package/src/calls/CometChatCallHistoryWithDetails/HistoryWithDetailsStyle.ts +0 -3
  164. package/src/calls/CometChatCallHistoryWithDetails/index.ts +0 -8
  165. /package/src/{calls/CometChatCallDetails → AI/AIAssistBot}/resources/CloseIcon.png +0 -0
  166. /package/src/{AI → CometChatMessageComposer}/resources/ai.png +0 -0
  167. /package/src/calls/{CometChatCallDetails → CometChatCallLogDetails}/resources/index.ts +0 -0
  168. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Back.png +0 -0
  169. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Call.png +0 -0
  170. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Info.png +0 -0
  171. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Selection.png +0 -0
  172. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Spineer.png +0 -0
  173. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Video.png +0 -0
  174. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/check.png +0 -0
  175. /package/src/calls/{CometChatCallHistoryWithDetails → CometChatCallLogsWithDetails}/style.ts +0 -0
@@ -0,0 +1,20 @@
1
+
2
+ import { BorderStyle, FontStyle } from "../../shared";
3
+ import { AIBaseStyle } from "../AIBaseStyle";
4
+
5
+ export class AIConversationSummaryStyle extends AIBaseStyle {
6
+ titleFont?: FontStyle;
7
+ titleColor?: string = "";
8
+ textFont?: FontStyle;
9
+ textColor?: string = "";
10
+ buttonTextColor?: string = "";
11
+ buttonTextFont?: FontStyle;
12
+ buttonBackground?: string = "";
13
+ buttonBorderRadius?: number;
14
+ buttonBorder?: BorderStyle;
15
+ closeIconTint?: string = "";
16
+ constructor(props: Partial<AIConversationSummaryStyle>) {
17
+ super({});
18
+ Object.assign(this, props);
19
+ }
20
+ }
@@ -0,0 +1,190 @@
1
+
2
+ import React, { useContext, useEffect, useState } from 'react';
3
+ import { View } from 'react-native';
4
+ import { CometChatContext, CometChatTheme, localize } from '../../shared';
5
+ import { AIConversationSummaryConfiguration } from './configuration';
6
+ import { CometChatPanel } from '../../shared/views/CometChatPanel/CometChatPanel';
7
+ import CometChatAICard from '../../shared/views/CometChatAICard/CometChatAICard';
8
+
9
+ interface IAIConversationSummaryProps {
10
+ getConversationSummaryCallback?: (theme?: CometChatTheme) => Promise<string>
11
+ editReplyCallback?: (reply: string) => void
12
+ configuration?: AIConversationSummaryConfiguration
13
+ theme?: CometChatTheme,
14
+ onPanelClose: () => void
15
+ };
16
+
17
+ const defaultProps: IAIConversationSummaryProps = {
18
+ getConversationSummaryCallback: undefined,
19
+ editReplyCallback: undefined,
20
+ configuration: undefined,
21
+ theme: new CometChatTheme({}),
22
+ onPanelClose: () => { }
23
+ }
24
+
25
+ const enum States {
26
+ loading = "loading",
27
+ error = "error",
28
+ empty = "empty",
29
+ loaded = "loaded"
30
+ }
31
+
32
+ let inProgress = false;
33
+ const AIConversationSummaryView = (props: IAIConversationSummaryProps) => {
34
+
35
+ const [messageListState, setMessageListState] = useState<States>(States.loading);
36
+ const [activeView, setActiveView] = useState<JSX.Element | null>(null);
37
+
38
+ const { theme } = useContext(CometChatContext)
39
+
40
+ const errorStateText: string = localize("SOMETHING_WRONG");
41
+ const emptyStateText: string = localize("NO_MESSAGES_FOUND");
42
+ const loadingStateText: string = localize("GENERATING_SUMMARY");
43
+ const titleText: string = localize("CONVERSATION_SUMMARY")
44
+
45
+ useEffect(() => {
46
+ fetchButtonContent();
47
+ }, []);
48
+
49
+ function fetchButtonContent() {
50
+ setMessageListState(States.loading);
51
+ if (props && props.getConversationSummaryCallback) {
52
+ props.getConversationSummaryCallback(theme)
53
+ .then((response) => {
54
+ if (response) {
55
+ inProgress = true;
56
+ getLoadedView(response)
57
+ .then(res => {
58
+ setMessageListState(States.loaded);
59
+ setActiveView(res);
60
+ })
61
+ .catch(err => {
62
+ inProgress = false;
63
+ setMessageListState(States.empty);
64
+ })
65
+ } else {
66
+ inProgress = false;
67
+ setMessageListState(States.empty);
68
+ }
69
+ })
70
+ .catch((err) => {
71
+ inProgress = false;
72
+ setMessageListState(States.error);
73
+ })
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Create a view based on the value of the `state` prop.
79
+ */
80
+ function getStateView(): JSX.Element | null {
81
+ let res: JSX.Element | null = null;
82
+ switch (messageListState) {
83
+ case States.loading:
84
+ res = getLoadingView();
85
+ break;
86
+ case States.error:
87
+ res = getErrorView();
88
+ break;
89
+ case States.empty:
90
+ res = getEmptyView();
91
+ break;
92
+ case States.loaded:
93
+ break;
94
+ default:
95
+ const x: never = messageListState;
96
+ }
97
+ return res;
98
+ }
99
+
100
+ /**
101
+ * Creates the loading view
102
+ */
103
+ function getLoadingView(): JSX.Element {
104
+ let LoadingView = props.configuration?.LoadingStateView;
105
+ return (
106
+
107
+ <CometChatAICard
108
+ state={States.loading}
109
+ style={props.configuration?.conversationSummaryStyle}
110
+ loadingIconURL={props.configuration?.loadingIconURL}
111
+ loadingStateText={loadingStateText}
112
+ >
113
+ {LoadingView ? <LoadingView /> : null}
114
+ </CometChatAICard>
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Creates the error view
120
+ */
121
+ function getErrorView(): JSX.Element | null {
122
+ let ErrorView = props.configuration?.ErrorStateView;
123
+ return (
124
+ <CometChatAICard
125
+ state={States.error}
126
+ style={props.configuration?.conversationSummaryStyle}
127
+ errorIconURL={props.configuration?.errorIconURL}
128
+ errorStateText={errorStateText}
129
+ >
130
+ {ErrorView ? <ErrorView /> : null}
131
+ </CometChatAICard>
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Creates the empty view
137
+ */
138
+ function getEmptyView(): JSX.Element {
139
+ let EmptyView = props.configuration?.EmptyStateView;
140
+ return (
141
+ <CometChatAICard
142
+ state={States.empty}
143
+ style={props.configuration?.conversationSummaryStyle}
144
+ emptyIconURL={props.configuration?.emptyIconURL}
145
+ emptyStateText={emptyStateText}
146
+ >
147
+ {EmptyView ? <EmptyView /> : null}
148
+ </CometChatAICard>
149
+ );
150
+ }
151
+
152
+ /**
153
+ * Creates the loaded view
154
+ */
155
+ async function getLoadedView(conversationSummary: string): Promise<JSX.Element> {
156
+ return new Promise((resolve, reject) => {
157
+ try {
158
+ let CustomView = props.configuration?.customView;
159
+
160
+ if (CustomView) {
161
+ props.configuration?.customView!(conversationSummary, props.onPanelClose).then((res: any) => {
162
+ return resolve(res);
163
+ })
164
+ .catch((err: CometChat.CometChatException) => {
165
+ return reject(err)
166
+ })
167
+ } else {
168
+ let conversationSummaryView = <CometChatPanel
169
+ title={titleText}
170
+ textContent={conversationSummary}
171
+ style={props.configuration?.conversationSummaryStyle}
172
+ onClose={props.onPanelClose}
173
+ />
174
+ return resolve(conversationSummaryView);
175
+ }
176
+ } catch (e) {
177
+ reject(e);
178
+ }
179
+ })
180
+ }
181
+
182
+ return (
183
+ <View style={{ marginTop: 10, overflow: "hidden" }} >
184
+ {messageListState === States.loaded ? activeView : getStateView()}
185
+ </View>
186
+ );
187
+ };
188
+
189
+ AIConversationSummaryView.defaultProps = defaultProps
190
+ export default AIConversationSummaryView;
@@ -0,0 +1,14 @@
1
+ import { AIBaseConfiguration } from "../AIBaseConfiguration";
2
+ import { AIConversationSummaryStyle } from "./AIConversationSummaryStyle";
3
+ import { closeIcon } from "./resources";
4
+
5
+ export class AIConversationSummaryConfiguration extends AIBaseConfiguration {
6
+ customView?: (response: string, onClose: Function) => Promise<any>;
7
+ conversationSummaryStyle?: AIConversationSummaryStyle;
8
+ unreadMessageThreshold?: number = 30;
9
+ closeIconURL?: string = closeIcon;
10
+ constructor(props: Partial<AIConversationSummaryConfiguration>) {
11
+ super({});
12
+ Object.assign(this, props);
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ import closeIcon from "./close.png";
2
+
3
+ export {
4
+ closeIcon,
5
+ }
@@ -1,12 +1,17 @@
1
- import { ExtensionsDataSource } from "../shared/framework/ExtensionsDataSource";
2
- import { AIEnablerConfiguration } from "./configuration";
3
-
4
- export abstract class AIExtensionDataSource extends ExtensionsDataSource {
5
- getConfiguration():any{
6
-
7
- };
8
- setConfiguration(config?:AIEnablerConfiguration):void{
9
-
10
- };
11
-
12
- }
1
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
2
+
3
+ abstract class AIExtensionDataSource {
4
+ abstract addExtension(): void;
5
+ abstract getExtensionId(): string;
6
+
7
+ enable(): void {
8
+ CometChat.isAIFeatureEnabled(this.getExtensionId()).then(
9
+ (enabled: Boolean) => {
10
+ if (enabled) this.addExtension();
11
+ }
12
+ );
13
+ }
14
+
15
+ }
16
+
17
+ export { AIExtensionDataSource };
@@ -0,0 +1,14 @@
1
+ import { BaseStyle, FontStyle } from "../shared";
2
+
3
+ export class AIOptionsStyle extends BaseStyle {
4
+ listItemBackground?: string;
5
+ listItemTitleFont?: FontStyle;
6
+ listItemTitleColor?: string;
7
+ listItemBorderRadius?: number;
8
+ listItemBorder?: string;
9
+ optionsSeparatorTint?: string;
10
+ constructor(props: Partial<AIOptionsStyle>) {
11
+ super({});
12
+ Object.assign(this, props);
13
+ }
14
+ }
@@ -1,28 +1,19 @@
1
- import { AISmartRepliesExtensionDecorator } from "./AISmartRepliesDecorator";
1
+ import { AISmartRepliesExtensionDecorator } from "./AISmartRepliesDecorator";
2
2
  import { ChatConfigurator } from "../../shared";
3
3
  import { AIExtensionDataSource } from "../AIExtensionDataSource";
4
4
  import { AISmartRepliesConfiguration } from "./configuration";
5
5
  export class AISmartRepliesExtension extends AIExtensionDataSource {
6
-
7
6
  private configuration?: AISmartRepliesConfiguration;
8
7
 
9
- constructor(configuration?: AISmartRepliesConfiguration) {
10
- super();
11
- this.configuration = configuration;
12
- }
8
+ constructor(configuration?: AISmartRepliesConfiguration) {
9
+ super();
10
+ this.configuration = configuration;
11
+ }
13
12
  override addExtension(): void {
14
- ChatConfigurator.enable((dataSource: any) => new AISmartRepliesExtensionDecorator(dataSource,this.configuration));
13
+ ChatConfigurator.enable((dataSource: any) => new AISmartRepliesExtensionDecorator(dataSource, this.configuration));
15
14
  }
16
15
  override getExtensionId(): string {
17
16
  return "smart-replies";
18
17
  }
19
- override enable(): void {
20
- this.addExtension()
21
-
22
- }
23
- override getConfiguration():AISmartRepliesConfiguration{
24
- return this.configuration;
25
- }
26
-
27
18
 
28
19
  }
@@ -0,0 +1,302 @@
1
+ import React from "react";
2
+ import { CometChatMessageComposerActionInterface, CometChatTheme, CometChatUIEventHandler, CometChatUIEvents, DataSource, DataSourceDecorator, MessageEvents, localize } from "../../shared";
3
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
4
+ import { State } from "../utils";
5
+ import { AISmartRepliesConfiguration } from "./configuration";
6
+ import { AIOptionsStyle } from "../AIOptionsStyle";
7
+ import { MessageStatusConstants, ReceiverTypeConstants, ViewAlignment } from "../../shared/constants/UIKitConstants";
8
+ import { TouchableOpacity, View, Text, ScrollView, Keyboard } from "react-native";
9
+ import CometChatAICard from "../../shared/views/CometChatAICard/CometChatAICard";
10
+ import { CardViewStyle } from "../CardViewStyle";
11
+ import { getCardViewStyle, getRepliesStyle, getRepliesWrapperStyle } from "../style";
12
+ export class AISmartRepliesExtensionDecorator extends DataSourceDecorator {
13
+ public configuration?: AISmartRepliesConfiguration;
14
+ public user!: CometChat.User;
15
+ public group!: CometChat.Group;
16
+ public theme: CometChatTheme = new CometChatTheme({});
17
+ public isPannelVisible: boolean = false;
18
+ public repliesView: JSX.Element;
19
+ public loadingStateText: string = localize("GENERATING_REPLIES");
20
+ public errorStateText: string = localize("SOMETHING_WRONG");
21
+ public emptyStateText: string = localize("NO_MESSAGES_FOUND");
22
+ public cardViewStyle: CardViewStyle = {};
23
+ public keyboardDidShowListener;
24
+ public keyboardDidHideListener;
25
+ public loggedInUser!: CometChat.User | null;
26
+ private LISTENER_ID: string = "aismartlistener__listener";
27
+
28
+ constructor(dataSource: DataSource, configuration?: AISmartRepliesConfiguration) {
29
+ super(dataSource);
30
+ this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.hideOnKeyboardShow);
31
+ // this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this.showOnKeyboardShow);
32
+ this.configuration = configuration;
33
+ this.cardViewStyle = getCardViewStyle(this.theme, this.configuration?.smartRepliesStyle)
34
+ setTimeout(() => {
35
+ this.addMessageListener();
36
+ }, 1000);
37
+ }
38
+ override getId(): string {
39
+ return "aismartreply";
40
+ }
41
+
42
+ override getAIOptions(user: CometChat.User | null, group: CometChat.Group | null, theme: CometChatTheme, id?: any, AIOptionsStyle?: AIOptionsStyle): CometChatMessageComposerActionInterface[] {
43
+ this.user = user!;
44
+ this.group = group!;
45
+ if (!id?.parentMessageId) {
46
+ const messageComposerActions: CometChatMessageComposerActionInterface[] = super.getAIOptions(user, group, theme, id, AIOptionsStyle);
47
+ let newAction = {
48
+ title: localize("SUGGEST_A_REPLY"),
49
+ onPress: () => {
50
+ this.onButtonClick()
51
+ },
52
+ id: "smart-replies",
53
+ iconURL: '',
54
+ iconTint: '',
55
+ titleColor: this.configuration?.smartRepliesStyle?.buttonTextColor || AIOptionsStyle.listItemTitleColor,
56
+ titleFont: this.configuration?.smartRepliesStyle?.buttonTextFont || AIOptionsStyle.listItemTitleFont,
57
+ background: this.configuration?.smartRepliesStyle?.backgroundColor || AIOptionsStyle.listItemBackground,
58
+ cornerRadius: this.configuration?.smartRepliesStyle?.buttonBorderRadius || AIOptionsStyle.listItemBorderRadius,
59
+ };
60
+ messageComposerActions.push(newAction);
61
+ return messageComposerActions;
62
+ } else {
63
+ return super.getAIOptions(user, group, theme, id, AIOptionsStyle);
64
+ }
65
+ }
66
+
67
+
68
+ private getLoadingView(): JSX.Element {
69
+ let LoadingView: JSX.Element = this.configuration?.LoadingStateView;
70
+ return (
71
+ <CometChatAICard
72
+ state={State.loading}
73
+ style={this.configuration?.smartRepliesStyle}
74
+ loadingIconURL={this.configuration?.loadingIconURL}
75
+ loadingStateText={this.loadingStateText}
76
+ >
77
+ {LoadingView ? <LoadingView /> : null}
78
+ </CometChatAICard>
79
+ )
80
+ }
81
+
82
+ private getEmptyView(): JSX.Element {
83
+ let EmptyView: JSX.Element = this.configuration?.EmptyStateView
84
+ return (
85
+ <CometChatAICard
86
+ state={State.empty}
87
+ style={this.configuration?.smartRepliesStyle}
88
+ emptyIconURL={this.configuration?.emptyIconURL}
89
+ emptyStateText={this.emptyStateText}
90
+ >
91
+ {EmptyView ? <EmptyView /> : null}
92
+ </CometChatAICard>
93
+ )
94
+ }
95
+
96
+ private getErrorView(error?: CometChat.CometChatException): JSX.Element {
97
+ return (
98
+ <CometChatAICard
99
+ state={State.error}
100
+ style={this.configuration?.smartRepliesStyle}
101
+ errorIconURL={this.configuration?.errorIconURL}
102
+ errorStateText={this.errorStateText}
103
+ >
104
+ {this.configuration?.ErrorStateView ? this.configuration?.ErrorStateView(error) : null}
105
+ </CometChatAICard>
106
+ )
107
+ }
108
+
109
+ editReply(reply: string) {
110
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
111
+ alignment: ViewAlignment.composerBottom,
112
+ child: () => (null),
113
+ });
114
+ this.isPannelVisible = false;
115
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccComposeMessage, { text: reply });
116
+ this.keyboardDidShowListener?.remove();
117
+ this.keyboardDidHideListener?.remove();
118
+ }
119
+
120
+ hideOnKeyboardShow = () => {
121
+ if (this.isPannelVisible) {
122
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
123
+ alignment: ViewAlignment.composerBottom,
124
+ child: () => (null),
125
+ });
126
+ }
127
+ }
128
+
129
+ showOnKeyboardShow = () => {
130
+ if (this.isPannelVisible) {
131
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
132
+ alignment: ViewAlignment.composerBottom,
133
+ child: () => this.repliesView,
134
+ });
135
+ }
136
+ }
137
+
138
+ getSmartReplies(): Promise<JSX.Element> {
139
+ return new Promise((resolve, reject) => {
140
+ let receiverId: string = this.user ? this.user?.getUid() : this.group?.getGuid();
141
+ let receiverType: string = this.user ? ReceiverTypeConstants.user : ReceiverTypeConstants.group;
142
+ if (this.configuration?.customView) {
143
+ CometChat.getSmartReplies(receiverId, receiverType).then((response: any) => {
144
+ this.configuration.customView(response).then((res) => {
145
+ return resolve((<View>{res}</View>))
146
+
147
+ })
148
+ .catch((err: CometChat.CometChatException) => {
149
+ return reject(err)
150
+ })
151
+
152
+ })
153
+ .catch((err: CometChat.CometChatException) => {
154
+ return reject(err)
155
+ })
156
+ }
157
+ else {
158
+ CometChat.getSmartReplies(receiverId, receiverType).then((response: any) => {
159
+ let view: JSX.Element[] = []
160
+ Object.keys(response).forEach((reply) => {
161
+ if (response[reply] && response[reply] != "") {
162
+ view.push(
163
+ (<TouchableOpacity
164
+ style={getRepliesWrapperStyle(this.theme, this.configuration?.smartRepliesStyle, this.configuration?.listItemStyle)}
165
+ key={response[reply]} // Make sure to set a unique key for each item
166
+ onPress={() => this.editReply(response[reply])}
167
+ >
168
+ <Text style={getRepliesStyle(this.theme, this.configuration?.smartRepliesStyle, this.configuration?.listItemStyle)}>{response[reply]}</Text>
169
+ </TouchableOpacity>)
170
+ )
171
+ }
172
+ })
173
+ return resolve((<View>{view}</View>))
174
+
175
+ })
176
+ .catch((err: CometChat.CometChatException) => {
177
+ return reject(err)
178
+ })
179
+ }
180
+
181
+ })
182
+
183
+ }
184
+
185
+ onButtonClick = (): void => {
186
+ this.showDefaultPanel(State.loading)
187
+ this.getSmartReplies().then((replies) => {
188
+ if (!replies || (replies?.length && replies.length <= 0)) {
189
+ this.showDefaultPanel(State.empty)
190
+ }
191
+ else {
192
+ this.repliesView = (<View style={{ width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 200, backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius: this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, marginTop: 8 }}>
193
+ <ScrollView style={{ height: "100%", width: "100%" }}>
194
+ {replies}
195
+ </ScrollView>
196
+
197
+
198
+ </View>)
199
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.showPanel, {
200
+ alignment: ViewAlignment.composerBottom,
201
+ child: () => this.repliesView,
202
+ });
203
+ }
204
+
205
+ this.isPannelVisible = true
206
+
207
+ })
208
+ .catch((err) => {
209
+ this.showDefaultPanel(State.error, err)
210
+
211
+ })
212
+ }
213
+
214
+ showDefaultPanel(state: State = State.loading, error?: CometChat.CometChatException) {
215
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.showPanel, {
216
+ alignment: ViewAlignment.composerBottom,
217
+ child: () => (
218
+ <View
219
+ style={{
220
+ width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 160,
221
+ backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius: this.cardViewStyle?.borderRadius,
222
+ ...this.cardViewStyle?.border,
223
+ justifyContent: "center", alignItems: "center"
224
+ }}
225
+ >
226
+ {state == State.loading ? this.getLoadingView() : (state == State.empty ? this.getEmptyView() : this.getErrorView(error))}
227
+ </View>
228
+ )
229
+ });
230
+
231
+ this.isPannelVisible = true;
232
+ }
233
+
234
+ closePanel = () => {
235
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
236
+ alignment: ViewAlignment.composerBottom,
237
+ child: () => (null),
238
+ });
239
+ };
240
+
241
+ closeIfMessageReceived(message: CometChat.BaseMessage) {
242
+ if (message?.getReceiverId() === this.loggedInUser?.getUid()) {
243
+ this.closePanel();
244
+ }
245
+ }
246
+
247
+ private addMessageListener(): void {
248
+ CometChat.getLoggedinUser().then((user: CometChat.User | null) => {
249
+ if (user) {
250
+ this.loggedInUser = user;
251
+ }
252
+ });
253
+
254
+ CometChatUIEventHandler.addMessageListener(this.LISTENER_ID, {
255
+ onTextMessageReceived: (message: CometChat.TextMessage) => {
256
+ this.closeIfMessageReceived(message);
257
+ },
258
+ onCustomMessageReceived: (message: CometChat.CustomMessage) => {
259
+ this.closeIfMessageReceived(message);
260
+ },
261
+ onMediaMessageReceived: (message: CometChat.MediaMessage) => {
262
+ this.closeIfMessageReceived(message);
263
+ },
264
+ onFormMessageReceived: (formMessage) => {
265
+ this.closeIfMessageReceived(formMessage)
266
+ },
267
+ onCardMessageReceived: (cardMessage) => {
268
+ this.closeIfMessageReceived(cardMessage)
269
+ },
270
+ onCustomInteractiveMessageReceived: (customInteractiveMessage) => {
271
+ this.closeIfMessageReceived(customInteractiveMessage)
272
+ }
273
+ });
274
+
275
+ CometChatUIEventHandler.addMessageListener(
276
+ MessageEvents.ccActiveChatChanged + "_AISmartReplies",
277
+ {
278
+ ccActiveChatChanged: (data) => {
279
+ // console.log("_________ACTIVE CHAT CHANGED IN AI CONVERSATION SUMMARY")
280
+ // this.currentMessage = data.message!;
281
+ // this.user = data.user!;
282
+ // this.group = data.group!;
283
+ // this.unreadMessageCount = data.unreadMessageCount ?? 0;
284
+ // if (this.unreadMessageCount >= (this.configuration?.unreadMessageThreshold ?? 30)) {
285
+ // this.loadConversationSummary();
286
+ // }
287
+ },
288
+ ccMessageSent: ({ message, status }) => {
289
+ if (status == MessageStatusConstants.success && message?.sender?.uid == this.loggedInUser?.uid) {
290
+ this.closePanel();
291
+ }
292
+ }
293
+ }
294
+ );
295
+
296
+ }
297
+
298
+ }
299
+
300
+
301
+
302
+
@@ -5,7 +5,7 @@ export class AISmartRepliesStyle extends AIButtonsStyle {
5
5
  buttonTextColor?:string;
6
6
  buttonTextFont?:FontStyleInterface;
7
7
  buttonBorder?:BorderStyleInterface;
8
- buttonBorderRadius?:string;
8
+ buttonBorderRadius?:number;
9
9
  buttonHeight?:string;
10
10
  buttonWidth?:string;
11
11
  buttonBackgroundColor?:string;
@@ -1,17 +1,10 @@
1
- import {CometChat} from '@cometchat/chat-sdk-react-native'
2
1
  import { AISmartRepliesStyle } from './AISmartRepliesStyle';
3
- import { loadingIcon, errorIcon, emptyIcon } from '../resources';
4
- export class AISmartRepliesConfiguration {
5
- onClick?:(user?:CometChat.User,group?:CometChat.Group)=>Promise<Object>;
6
- smartRepliesStyle?:AISmartRepliesStyle;
2
+ import { AIBaseConfiguration } from '../AIBaseConfiguration';
3
+ export class AISmartRepliesConfiguration extends AIBaseConfiguration {
7
4
  customView?:(response:Object,closeBottomsheet?:()=>void) => Promise<Object>;
8
- ErrorStateView?: (e?: CometChat.CometChatException) => JSX.Element;
9
- EmptyStateView?: () => JSX.Element;
10
- LoadingStateView?: () => JSX.Element;
11
- loadingIconURL?:string = loadingIcon;
12
- errorIconURL?:string = errorIcon;
13
- emptyIconURL?:string = emptyIcon;
5
+ smartRepliesStyle?:AISmartRepliesStyle;
14
6
  constructor(props: Partial<AISmartRepliesConfiguration>) {
7
+ super({});
15
8
  Object.assign(this, props);
16
9
  }
17
10
  }
@@ -1,10 +1,8 @@
1
- import AIBotIcon from "./ai.png";
2
1
  import loadingIcon from './spineer.png'
3
2
  import errorIcon from './ai-error.png'
4
3
  import emptyIcon from './ai-empty.png'
5
4
 
6
5
  export {
7
- AIBotIcon,
8
6
  loadingIcon,
9
7
  errorIcon,
10
8
  emptyIcon
package/src/AI/utils.ts CHANGED
@@ -33,7 +33,7 @@ export interface AIConfigurations {
33
33
 
34
34
 
35
35
  export enum State {
36
- loading,
37
- error,
38
- empty
36
+ loading = "loading",
37
+ error = "error",
38
+ empty = "empty",
39
39
  }