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

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 (169) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/AI/AIAssistBot/AIAssistBotDecorator.tsx +164 -0
  4. package/src/AI/AIAssistBot/AIAssistBotExtension.tsx +22 -0
  5. package/src/AI/AIAssistBot/AIAssistBotStyle.ts +43 -0
  6. package/src/AI/AIAssistBot/AIAssistBotView.tsx +294 -0
  7. package/src/AI/AIAssistBot/configuration.ts +22 -0
  8. package/src/AI/AIAssistBot/resources/index.ts +5 -0
  9. package/src/AI/{configuration.ts → AIBaseConfiguration.ts} +3 -6
  10. package/src/AI/AIBaseStyle.ts +58 -0
  11. package/src/AI/AIConversationStarter/AIConversationStarter.ts +5 -19
  12. package/src/AI/AIConversationStarter/AIConversationStarterDecorator.tsx +144 -130
  13. package/src/AI/AIConversationStarter/AIConversationStarterStyle.ts +11 -6
  14. package/src/AI/AIConversationStarter/configuration.ts +10 -17
  15. package/src/AI/AIConversationSummary/AIConversationSummaryDecorator.tsx +175 -0
  16. package/src/AI/AIConversationSummary/AIConversationSummaryExtension.ts +21 -0
  17. package/src/AI/AIConversationSummary/AIConversationSummaryStyle.tsx +20 -0
  18. package/src/AI/AIConversationSummary/AIConversationSummaryView.tsx +190 -0
  19. package/src/AI/AIConversationSummary/configuration.ts +14 -0
  20. package/src/AI/AIConversationSummary/resources/close.png +0 -0
  21. package/src/AI/AIConversationSummary/resources/index.ts +5 -0
  22. package/src/AI/AIExtensionDataSource.ts +17 -12
  23. package/src/AI/AIOptionsStyle.ts +14 -0
  24. package/src/AI/AISmartReplies/AISmartReplies.ts +6 -15
  25. package/src/AI/AISmartReplies/AISmartRepliesDecorator.tsx +302 -0
  26. package/src/AI/AISmartReplies/AISmartRepliesStyle.ts +1 -1
  27. package/src/AI/AISmartReplies/configuration.ts +4 -11
  28. package/src/AI/resources/index.ts +0 -2
  29. package/src/AI/utils.ts +3 -3
  30. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +118 -5
  31. package/src/CometChatMessageComposer/MessageComposerConfiguration.tsx +3 -0
  32. package/src/CometChatMessageComposer/resources/index.ts +2 -0
  33. package/src/CometChatMessageComposer/styles.ts +1 -4
  34. package/src/CometChatMessageList/CometChatMessageList.tsx +33 -24
  35. package/src/CometChatMessages/CometChatMessages.tsx +4 -13
  36. package/src/CometChatMessages/MessagesConfiguration.ts +2 -2
  37. package/src/calls/CallUtils.ts +106 -45
  38. package/src/calls/CallingDetailsUtils.tsx +133 -15
  39. package/src/calls/CallingPackage.ts +16 -2
  40. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +9 -10
  41. package/src/calls/CometChatCallLogDetails/CallLogDetailsConfiguration.ts +116 -0
  42. package/src/calls/CometChatCallLogDetails/CallLogDetailsStyle.ts +36 -0
  43. package/src/calls/CometChatCallLogDetails/CometChatCallLogDetails.tsx +308 -0
  44. package/src/calls/CometChatCallLogDetails/index.ts +12 -0
  45. package/src/calls/CometChatCallLogDetails/resources/CloseIcon.png +0 -0
  46. package/src/calls/{CometChatCallDetails → CometChatCallLogDetails}/style.ts +1 -0
  47. package/src/calls/{CometChatCallHistory/CallHistoryConfiguration.ts → CometChatCallLogHistory/CallLogHistoryConfiguration.ts} +15 -27
  48. package/src/calls/CometChatCallLogHistory/CallLogHistoryStyle.ts +46 -0
  49. package/src/calls/CometChatCallLogHistory/CometChatCallLogHistory.tsx +337 -0
  50. package/src/calls/CometChatCallLogHistory/index.ts +12 -0
  51. package/src/calls/CometChatCallLogHistory/resources/incomingcall.png +0 -0
  52. package/src/calls/CometChatCallLogHistory/resources/incomingvideo.png +0 -0
  53. package/src/calls/CometChatCallLogHistory/resources/index.ts +29 -0
  54. package/src/calls/CometChatCallLogHistory/resources/missedcall.png +0 -0
  55. package/src/calls/CometChatCallLogHistory/resources/missedvideo.png +0 -0
  56. package/src/calls/CometChatCallLogHistory/resources/outgoingcall.png +0 -0
  57. package/src/calls/CometChatCallLogHistory/resources/outgoingvideo.png +0 -0
  58. package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/style.ts +2 -1
  59. package/src/calls/CometChatCallLogParticipants/CallLogParticipantsConfiguration.ts +61 -0
  60. package/src/calls/CometChatCallLogParticipants/CallLogParticipantsStyle.ts +59 -0
  61. package/src/calls/CometChatCallLogParticipants/CometChatCallLogParticipants.tsx +220 -0
  62. package/src/calls/CometChatCallLogParticipants/index.ts +12 -0
  63. package/src/calls/CometChatCallLogParticipants/resources/Back.png +0 -0
  64. package/src/calls/CometChatCallLogParticipants/resources/index.ts +4 -0
  65. package/src/calls/CometChatCallLogParticipants/style.ts +24 -0
  66. package/src/calls/CometChatCallLogRecordings/CallLogRecordingsConfiguration.ts +63 -0
  67. package/src/calls/CometChatCallLogRecordings/CallLogRecordingsStyle.ts +63 -0
  68. package/src/calls/CometChatCallLogRecordings/CometChatCallLogRecordings.tsx +253 -0
  69. package/src/calls/CometChatCallLogRecordings/index.ts +12 -0
  70. package/src/calls/CometChatCallLogRecordings/resources/Back.png +0 -0
  71. package/src/calls/CometChatCallLogRecordings/resources/download.png +0 -0
  72. package/src/calls/CometChatCallLogRecordings/resources/index.ts +6 -0
  73. package/src/calls/CometChatCallLogRecordings/style.ts +24 -0
  74. package/src/calls/CometChatCallLogs/CallLogsConfiguration.ts +87 -0
  75. package/src/calls/CometChatCallLogs/CallLogsStyle.ts +95 -0
  76. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +482 -0
  77. package/src/calls/CometChatCallLogs/index.ts +12 -0
  78. package/src/calls/CometChatCallLogs/resources/Back.png +0 -0
  79. package/src/calls/CometChatCallLogs/resources/Info.png +0 -0
  80. package/src/calls/CometChatCallLogs/resources/Selection.png +0 -0
  81. package/src/calls/CometChatCallLogs/resources/Spinner.png +0 -0
  82. package/src/calls/CometChatCallLogs/resources/check.png +0 -0
  83. package/src/calls/CometChatCallLogs/resources/incomingcall.png +0 -0
  84. package/src/calls/CometChatCallLogs/resources/incomingvideo.png +0 -0
  85. package/src/calls/CometChatCallLogs/resources/index.ts +25 -0
  86. package/src/calls/CometChatCallLogs/resources/missedcall.png +0 -0
  87. package/src/calls/CometChatCallLogs/resources/missedvideo.png +0 -0
  88. package/src/calls/CometChatCallLogs/resources/outgoingcall.png +0 -0
  89. package/src/calls/CometChatCallLogs/resources/outgoingvideo.png +0 -0
  90. package/src/calls/CometChatCallLogs/style.ts +24 -0
  91. package/src/calls/CometChatCallLogsWithDetails/CallLogsWithDetailsConfiguration.ts +9 -0
  92. package/src/calls/{CometChatCallHistoryWithDetails/CometChatCallHistoryWithDetails.tsx → CometChatCallLogsWithDetails/CometChatCallLogsWithDetails.tsx} +17 -16
  93. package/src/calls/CometChatCallLogsWithDetails/index.ts +7 -0
  94. package/src/calls/index.ts +40 -1
  95. package/src/calls/resources/index.ts +3 -1
  96. package/src/calls/resources/nextarrow.png +0 -0
  97. package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +3 -5
  98. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +1 -1
  99. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +5 -3
  100. package/src/extensions/ThumbnailGeneration/resources/empty.png +0 -0
  101. package/src/extensions/ThumbnailGeneration/resources/index.ts +5 -0
  102. package/src/index.ts +79 -4
  103. package/src/shared/CometChatUiKit/CometChatUIKit.ts +154 -130
  104. package/src/shared/CometChatUiKit/UIKitSettings.ts +2 -2
  105. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +1 -1
  106. package/src/shared/framework/DataSource.ts +4 -0
  107. package/src/shared/framework/DataSourceDecorator.tsx +5 -0
  108. package/src/shared/framework/MessageDataSource.tsx +4 -1
  109. package/src/shared/index.ts +4 -0
  110. package/src/shared/modals/CometChatCallLogDetailsOptions.ts +23 -0
  111. package/src/shared/modals/CometChatCallLogDetailsTemplate.ts +16 -0
  112. package/src/shared/modals/index.ts +5 -1
  113. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +19 -5
  114. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +19 -5
  115. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +21 -7
  116. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +19 -5
  117. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +19 -5
  118. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +19 -5
  119. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +19 -5
  120. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +19 -5
  121. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +19 -5
  122. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +19 -5
  123. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +19 -5
  124. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +19 -4
  125. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +19 -5
  126. package/src/shared/resources/CometChatTheme/Palette.ts +16 -0
  127. package/src/shared/utils/DetailsUtils/DetailsUtils.tsx +1 -1
  128. package/src/shared/views/CometChatAICard/CometChatAICard.tsx +71 -0
  129. package/src/shared/views/CometChatAICard/resources/errormessage.png +0 -0
  130. package/src/shared/views/CometChatAICard/resources/index.ts +4 -0
  131. package/src/shared/views/CometChatAICard/resources/nomessage.png +0 -0
  132. package/src/shared/views/CometChatActionSheet/ActionSheetStyle.ts +4 -0
  133. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +11 -7
  134. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +56 -47
  135. package/src/shared/views/CometChatBottomSheet/style.ts +0 -2
  136. package/src/shared/views/CometChatDate/CometChatDate.tsx +7 -3
  137. package/src/shared/views/CometChatDate/DateConfiguration.ts +4 -0
  138. package/src/shared/views/CometChatDate/style.ts +1 -1
  139. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +31 -19
  140. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -2
  141. package/src/shared/views/CometChatPanel/CometChatPanel.tsx +51 -0
  142. package/src/shared/views/CometChatPanel/PanelStyle.tsx +43 -0
  143. package/src/shared/views/CometChatPanel/resources/CloseIcon.png +0 -0
  144. package/src/shared/views/CometChatPanel/resources/index.ts +5 -0
  145. package/src/AI/AIEnabler.ts +0 -115
  146. package/src/AI/AIEnablerDecorator.tsx +0 -324
  147. package/src/AI/AISmartReplies/AISmartRepliesDecorator.ts +0 -18
  148. package/src/calls/CometChatCallDetails/CallDetailsConfiguration.ts +0 -68
  149. package/src/calls/CometChatCallDetails/CallDetailsStyle.ts +0 -52
  150. package/src/calls/CometChatCallDetails/CometChatCallDetails.tsx +0 -268
  151. package/src/calls/CometChatCallDetails/index.ts +0 -9
  152. package/src/calls/CometChatCallHistory/CallHistoryStyle.ts +0 -34
  153. package/src/calls/CometChatCallHistory/CometChatCallHistory.tsx +0 -422
  154. package/src/calls/CometChatCallHistory/index.ts +0 -9
  155. package/src/calls/CometChatCallHistory/resources/index.ts +0 -17
  156. package/src/calls/CometChatCallHistoryWithDetails/HistoryWithDetailsConfiguration.ts +0 -7
  157. package/src/calls/CometChatCallHistoryWithDetails/HistoryWithDetailsStyle.ts +0 -3
  158. package/src/calls/CometChatCallHistoryWithDetails/index.ts +0 -8
  159. /package/src/{calls/CometChatCallDetails → AI/AIAssistBot}/resources/CloseIcon.png +0 -0
  160. /package/src/{AI → CometChatMessageComposer}/resources/ai.png +0 -0
  161. /package/src/calls/{CometChatCallDetails → CometChatCallLogDetails}/resources/index.ts +0 -0
  162. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Back.png +0 -0
  163. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Call.png +0 -0
  164. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Info.png +0 -0
  165. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Selection.png +0 -0
  166. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Spineer.png +0 -0
  167. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/Video.png +0 -0
  168. /package/src/calls/{CometChatCallHistory → CometChatCallLogHistory}/resources/check.png +0 -0
  169. /package/src/calls/{CometChatCallHistoryWithDetails → CometChatCallLogsWithDetails}/style.ts +0 -0
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  [![Platform](https://img.shields.io/badge/Platform-ReactNative-brightgreen.svg)](#)
13
13
  [![Platform](https://img.shields.io/badge/Language-TypeScript-yellowgreen.svg)](#)
14
- ![Version](https://shields.io/badge/version-v4.0.2-orange)
14
+ ![Version](https://shields.io/badge/version-v4.1.0-orange)
15
15
  ![Twitter Follow](https://img.shields.io/twitter/follow/cometchat?style=social)
16
16
 
17
17
  ## Table of contents
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "CometChat React Native UI Kit is a collection of custom UI Components designed to build text , chat and calling features in your application. The UI Kit is developed to keep developers in mind and aims to reduce development efforts significantly",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -70,13 +70,13 @@
70
70
  "@types/react": "17.0.21"
71
71
  },
72
72
  "dependencies": {
73
- "@cometchat/chat-sdk-react-native": "^4.0.3",
74
73
  "@react-native-async-storage/async-storage": "^1.17.10",
75
74
  "@react-native-community/clipboard": "^1.5.1"
76
75
  },
77
76
  "peerDependencies": {
78
77
  "react": "*",
79
- "react-native": "*"
78
+ "react-native": "*",
79
+ "@cometchat/chat-sdk-react-native": "*"
80
80
  },
81
81
  "jest": {
82
82
  "preset": "react-native",
@@ -0,0 +1,164 @@
1
+ import React from "react";
2
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
3
+ import { CometChatMessageComposerActionInterface, CometChatTheme, CometChatUIEventHandler, CometChatUIEvents, DataSource, DataSourceDecorator, MessageEvents, localize } from "../../shared";
4
+ import { AIAssistBotConfiguration } from "./configuration";
5
+ import { AIOptionsStyle } from "../AIOptionsStyle";
6
+ import AIAssistBotView from "./AIAssistBotView";
7
+
8
+ export class AIAssistBotDecorator extends DataSourceDecorator {
9
+ public configuration?: AIAssistBotConfiguration;
10
+ public user!: CometChat.User;
11
+ public group!: CometChat.Group;
12
+ public bots!: CometChat.User[];
13
+ public theme: CometChatTheme = new CometChatTheme({});
14
+ public loggedInUser!: CometChat.User | null;
15
+ public usersRequest: CometChat.UsersRequestBuilder;
16
+
17
+ constructor(
18
+ dataSource: DataSource,
19
+ configuration?: AIAssistBotConfiguration
20
+ ) {
21
+ super(dataSource);
22
+ this.configuration = configuration!;
23
+ this.usersRequest = new CometChat.UsersRequestBuilder()
24
+ .setLimit(30)
25
+ .setTags(["aibot"])
26
+ .build();
27
+ this.fetchBots();
28
+ setTimeout(() => {
29
+ this.addMessageListener();
30
+ }, 1000);
31
+ }
32
+
33
+ fetchBots() {
34
+ this.usersRequest.fetchNext().then((bots) => {
35
+ if (bots.length > 0) {
36
+ this.bots = [...(this.bots || []), ...bots];
37
+ if (bots.length > 0) {
38
+ this.fetchBots();
39
+ }
40
+ }
41
+ })
42
+
43
+ }
44
+
45
+ override getId(): string {
46
+ return "bots";
47
+ }
48
+
49
+ override getAIOptions(user: CometChat.User | null, group: CometChat.Group | null, theme: CometChatTheme, id?: any, AIOptionsStyle?: AIOptionsStyle): CometChatMessageComposerActionInterface[] {
50
+ this.user = user!;
51
+ this.group = group!;
52
+ if (!id?.parentMessageId) {
53
+ const numberOfBots = this.bots?.length;
54
+ const titleName = numberOfBots > 1 ? localize("COMETCHAT_ASK_AI_BOT") : `${localize("COMETCHAT_ASK_BOT")} ${this.bots[0]?.getName()}`;
55
+ const messageComposerActions: CometChatMessageComposerActionInterface[] = super.getAIOptions(user, group, theme, id, AIOptionsStyle);
56
+ let newAction = {
57
+ title: titleName,
58
+ onPress: () => {
59
+ this.onOptionsClick(AIOptionsStyle)
60
+ },
61
+ id: "ai-assist-bot",
62
+ iconURL: '',
63
+ iconTint: '',
64
+ titleColor: this.configuration?.style?.buttonTextColor || AIOptionsStyle.listItemTitleColor,
65
+ titleFont: this.configuration?.style?.buttonTextFont || AIOptionsStyle.listItemTitleFont,
66
+ background: this.configuration?.style?.backgroundColor || AIOptionsStyle.listItemBackground,
67
+ cornerRadius: this.configuration?.style?.buttonBorderRadius || AIOptionsStyle.listItemBorderRadius,
68
+ };
69
+ messageComposerActions.push(newAction);
70
+ return messageComposerActions;
71
+ } else {
72
+ return super.getAIOptions(user, group, theme, id, AIOptionsStyle);
73
+ }
74
+ }
75
+
76
+ onOptionsClick(AIOptionsStyle) {
77
+ if (this.bots?.length > 1) {
78
+ this.openBotList(AIOptionsStyle);
79
+ } else {
80
+ this.openBotChat(this.bots[0]);
81
+ }
82
+ }
83
+
84
+ openBotList(AIOptionsStyle) {
85
+ const botList = this.bots.map((bot) => {
86
+ return ({
87
+ title: bot.getName(),
88
+ onPress: () => { this.openBotChat(bot) },
89
+ id: bot?.getUid(),
90
+ iconURL: '',
91
+ iconTint: '',
92
+ titleColor: this.configuration?.style?.buttonTextColor || AIOptionsStyle.listItemTitleColor,
93
+ titleFont: this.configuration?.style?.buttonTextFont || AIOptionsStyle.listItemTitleFont,
94
+ background: this.configuration?.style?.backgroundColor || AIOptionsStyle.listItemBackground,
95
+ cornerRadius: this.configuration?.style?.buttonBorderRadius || AIOptionsStyle.listItemBorderRadius,
96
+ });
97
+ });
98
+
99
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccToggleBottomSheet, {
100
+ bots: botList
101
+ });
102
+ }
103
+
104
+ openBotChat(bot) {
105
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccToggleBottomSheet, {
106
+ botView: true,
107
+ child: () => <AIAssistBotView
108
+ bot={bot}
109
+ closeCallback={this.closeAIOption}
110
+ configuration={this.configuration}
111
+ title={bot.getName()}
112
+ onSend={this.getBotReply.bind(this)}
113
+ sender={this.loggedInUser}
114
+ />
115
+ });
116
+ }
117
+
118
+ closeAIOption() {
119
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccToggleBottomSheet, {
120
+ botView: true,
121
+ child: () => (null)
122
+ });
123
+ }
124
+
125
+ async getBotReply(question: string, bot: CometChat.User): Promise<string> {
126
+ let configuration: any;
127
+ const receiverId = this.group?.getGuid() || this.user?.getUid();
128
+ const receiverType = this.group?.getGuid()
129
+ ? CometChat.RECEIVER_TYPE.GROUP
130
+ : CometChat.RECEIVER_TYPE.USER;
131
+
132
+ try {
133
+ configuration = await this.configuration.apiConfiguration(bot, this.user, this.group) || {}
134
+ } catch (err) {
135
+ configuration = {}
136
+ }
137
+
138
+ const answer = await CometChat.askBot(
139
+ receiverId,
140
+ receiverType,
141
+ bot?.getUid(),
142
+ question,
143
+ configuration
144
+ );
145
+ return answer;
146
+ }
147
+
148
+ private addMessageListener(): void {
149
+ CometChat.getLoggedinUser().then((user: CometChat.User | null) => {
150
+ if (user) {
151
+ this.loggedInUser = user;
152
+ }
153
+ });
154
+
155
+ CometChatUIEventHandler.addMessageListener(
156
+ MessageEvents.ccActiveChatChanged,
157
+ {
158
+ ccActiveChatChanged: (data) => {
159
+
160
+ },
161
+ }
162
+ );
163
+ }
164
+ }
@@ -0,0 +1,22 @@
1
+ import { ChatConfigurator } from "../../shared";
2
+ import { AIExtensionDataSource } from "../AIExtensionDataSource";
3
+ import { AIAssistBotDecorator } from "./AIAssistBotDecorator";
4
+ import { AIAssistBotConfiguration } from "./configuration";
5
+ export class AIAssistBotExtension extends AIExtensionDataSource {
6
+ private configuration?: AIAssistBotConfiguration;
7
+
8
+ constructor(configuration?: AIAssistBotConfiguration) {
9
+ super();
10
+ this.configuration = configuration;
11
+ }
12
+
13
+ override addExtension(): void {
14
+ ChatConfigurator.enable((dataSource: any) => new AIAssistBotDecorator(dataSource, this.configuration));
15
+ }
16
+
17
+ override getExtensionId(): string {
18
+ return "bots";
19
+ }
20
+
21
+
22
+ }
@@ -0,0 +1,43 @@
1
+ import { FontStyle } from "../../shared";
2
+ import { AIBaseStyle } from "../AIBaseStyle";
3
+
4
+ export class AIAssistBotStyle extends AIBaseStyle {
5
+ titleFont?: FontStyle;
6
+ titleColor?: string = "";
7
+ subtitleFont: FontStyle;
8
+ subtitleColor: string;
9
+ closeIconTint?: string = "";
10
+ sendIconTint?: string = "";
11
+ buttonTextColor?: string = "";
12
+ buttonTextFont?: FontStyle;
13
+ buttonBackground?: string = "";
14
+ buttonBorderRadius?: number;
15
+
16
+ constructor(props: Partial<AIAssistBotStyle>) {
17
+ super({});
18
+ Object.assign(this, props);
19
+ }
20
+ }
21
+
22
+ class AITextMessageBubbleStyle extends AIBaseStyle {
23
+ textFont?: string = "";
24
+ textColor?: string = "";
25
+ constructor(props: Partial<AITextMessageBubbleStyle>) {
26
+ super({});
27
+ Object.assign(this, props);
28
+ }
29
+ }
30
+
31
+ export class AIBotMessageBubbleStyle extends AITextMessageBubbleStyle {
32
+ constructor(props: Partial<AIBotMessageBubbleStyle>) {
33
+ super({});
34
+ Object.assign(this, props);
35
+ }
36
+ }
37
+
38
+ export class AISenderMessageBubbleStyle extends AITextMessageBubbleStyle {
39
+ constructor(props: Partial<AISenderMessageBubbleStyle>) {
40
+ super({});
41
+ Object.assign(this, props);
42
+ }
43
+ }
@@ -0,0 +1,294 @@
1
+ import React, { useContext, useState, useEffect, useCallback } from 'react'
2
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
3
+ import { View, Text, TextInput, Dimensions, TouchableOpacity, Image, FlatList } from 'react-native'
4
+ import { AIAssistBotConfiguration } from './configuration';
5
+ import { CometChatBottomSheet, CometChatContext, CometChatContextType, CometChatDate, CometChatListItem, CometChatReceipt, CometChatTextBubble, CometChatTheme, localize } from '../../shared';
6
+ import { CloseIcon } from './resources';
7
+ import { ICONS } from '../../shared/framework/resources';
8
+ import { ICONS as MessageIcons } from '../../shared/assets/images';
9
+ import { getUnixTimestamp } from '../../shared/utils/CometChatMessageHelper';
10
+ import { CometChatMessageBubble } from '../../shared/views/CometChatMessageBubble';
11
+ import { MessageBubbleAlignmentType, ReceiverTypeConstants } from '../../shared/constants/UIKitConstants';
12
+ import { AIBotMessageBubbleStyle, AISenderMessageBubbleStyle } from './AIAssistBotStyle';
13
+
14
+ interface AIAssistBotViewProps {
15
+ title: string;
16
+ configuration: AIAssistBotConfiguration;
17
+ closeCallback: () => void,
18
+ bot: CometChat.User,
19
+ sender: CometChat.User,
20
+ onSend: (question: string, bot: CometChat.User) => Promise<any>
21
+ }
22
+
23
+ const AIAssistBotView = (props: AIAssistBotViewProps) => {
24
+ const { height } = Dimensions.get('window');
25
+ const { title, bot, sender, closeCallback, configuration, onSend } = props;
26
+ const { theme } = useContext<CometChatContextType>(CometChatContext);
27
+
28
+ const [question, setQuestion] = useState("");
29
+ const [messages, setMessages] = useState([]);
30
+
31
+ const style = {
32
+ titleColor: configuration?.style?.titleColor || theme.palette.getAccent(),
33
+ titleFont: configuration?.style?.titleFont || theme.typography.name,
34
+ closeIconTint: configuration?.style?.closeIconTint || theme.palette.getAccent(),
35
+ sendIconTint: configuration?.style?.sendIconTint || question ? theme.palette.getPrimary() : theme.palette.getAccent600(),
36
+ messageInputStyle: configuration?.messageInputStyle || {},
37
+ subtitleColor: configuration?.style?.subtitleColor || theme.palette.getAccent500(),
38
+ subtitleFont: configuration?.style?.subtitleFont || theme.typography.subtitle2,
39
+ ...configuration?.style
40
+ };
41
+
42
+ const {
43
+ titleColor,
44
+ titleFont,
45
+ closeIconTint,
46
+ sendIconTint,
47
+ subtitleColor,
48
+ subtitleFont
49
+ } = style;
50
+
51
+ useEffect(() => {
52
+ let botFirstMessage = "";
53
+ if (configuration?.botFirstMessageText) {
54
+ botFirstMessage = configuration.botFirstMessageText(bot);
55
+ } else {
56
+ botFirstMessage = localize("COMETCHAT_BOT_FIRST_MESSAGE");
57
+ }
58
+
59
+ const message = new CometChat.TextMessage(
60
+ sender?.getUid(),
61
+ botFirstMessage,
62
+ ReceiverTypeConstants.user
63
+ );
64
+ message.setSentAt(getUnixTimestamp());
65
+ message.setMuid(String(getUnixTimestamp()));
66
+ message.setSender(bot);
67
+
68
+ let newMessages = [...messages];
69
+ newMessages.unshift(message);
70
+
71
+ setMessages(newMessages);
72
+
73
+ }, [])
74
+
75
+ const onClose = () => {
76
+ closeCallback && closeCallback()
77
+ }
78
+
79
+ const onChangeText = (value: string) => {
80
+ setQuestion(value)
81
+ }
82
+
83
+ const onMsgSend = () => {
84
+ if (!question) return;
85
+ if (messages[0]?.sender?.getUid() === sender?.getUid()) return;
86
+
87
+ let newMessages = [...messages];
88
+
89
+ const MUID = String(getUnixTimestamp());
90
+ const message = new CometChat.TextMessage(
91
+ bot.getUid(),
92
+ question,
93
+ ReceiverTypeConstants.user
94
+ );
95
+ message.setSentAt(getUnixTimestamp());
96
+ message.setMuid(MUID);
97
+ message.setSender(sender);
98
+ message.setStatus("WAIT");
99
+
100
+ newMessages.unshift(message);
101
+ setMessages(newMessages);
102
+
103
+ onSend(question, bot)
104
+ .then(botReply => {
105
+ const message = new CometChat.TextMessage(
106
+ sender?.getUid(),
107
+ botReply,
108
+ ReceiverTypeConstants.user
109
+ );
110
+ message.setSentAt(getUnixTimestamp());
111
+ message.setMuid(String(getUnixTimestamp()));
112
+ message.setSender(bot);
113
+ message.setStatus(undefined);
114
+
115
+ const messageList = newMessages.map((message) => {
116
+ if (message.getMuid() === MUID) {
117
+ message.setStatus(undefined);
118
+ }
119
+ return message;
120
+ });
121
+
122
+ messageList.unshift(message);
123
+ setMessages(messageList);
124
+ })
125
+ .catch(err => {
126
+ const messageList = newMessages.map((message) => {
127
+ if (message.getMuid() === MUID) {
128
+ message.setStatus("ERROR");
129
+ }
130
+ return message;
131
+ });
132
+ setMessages(messageList);
133
+ });
134
+
135
+ setQuestion("")
136
+ }
137
+
138
+ const RenderMessageItem = ({ item, index }) => {
139
+ const contentView = (message: any,
140
+ theme: CometChatTheme,
141
+ alignment: MessageBubbleAlignmentType,
142
+ configuration: AIAssistBotConfiguration): JSX.Element => {
143
+ let style: AIBotMessageBubbleStyle | AISenderMessageBubbleStyle = {};
144
+
145
+ if (alignment === "right") {
146
+ style = configuration?.senderMessageBubbleStyle || {};
147
+ } else {
148
+ style = configuration?.botMessageBubbleStyle || {};
149
+ }
150
+
151
+ const defaultStyle: any = {
152
+ textFont: style?.textFont || theme.typography.text1,
153
+ borderRadius: style?.borderRadius || 12,
154
+ width: style?.width || "100%",
155
+ };
156
+ if (alignment === "right") {
157
+ defaultStyle["textColor"] = style?.textColor || theme.palette.getSecondary();
158
+ defaultStyle["backgroundColor"] = style?.backgroundColor || theme.palette.getPrimary()
159
+ } else {
160
+ defaultStyle["textColor"] = style?.textColor || theme.palette.getAccent();
161
+ defaultStyle["backgroundColor"] = style?.backgroundColor || theme.palette.getSecondary()
162
+ }
163
+
164
+ return (
165
+ <CometChatTextBubble
166
+ text={item.text}
167
+ style={defaultStyle}
168
+ textContainerStyle={defaultStyle}
169
+ />
170
+ )
171
+ }
172
+ function getBubbleAlignment(
173
+ message: any,
174
+ sender: CometChat.User
175
+ ): MessageBubbleAlignmentType {
176
+ if (message.sender?.getUid() === sender?.getUid()) {
177
+ return "right";
178
+ } else {
179
+ return "left";
180
+ }
181
+ }
182
+ function getMessageBubbleStyle(message: CometChat.TextMessage, theme: CometChatTheme, sender: CometChat.User, configuration: AIAssistBotConfiguration): any {
183
+ if (message.sender?.getUid() === sender?.getUid()) {
184
+ const style = configuration?.senderMessageBubbleStyle || {};
185
+ return {
186
+ background: style.backgroundColor || theme.palette.getPrimary(),
187
+ borderRadius: style.borderRadius || 12,
188
+ border: style.border || undefined,
189
+ }
190
+ } else {
191
+ const style = configuration?.botMessageBubbleStyle || {};
192
+ if (configuration?.botMessageBubbleStyle) {
193
+ return configuration?.botMessageBubbleStyle;
194
+ }
195
+ return {
196
+ background: style.backgroundColor || theme.palette.getSecondary(),
197
+ borderRadius: style.borderRadius || 12,
198
+ border: style.border || undefined,
199
+ };
200
+ }
201
+ };
202
+
203
+ const getFooterView = (item: CometChat.BaseMessage, bubbleAlignment: MessageBubbleAlignmentType): JSX.Element => {
204
+
205
+ let isSender = (item.getSender()?.getUid() || item['sender']['uid']) == (sender?.getUid() || sender['uid']);
206
+
207
+ return <View style={[{ flexDirection: "row", justifyContent: bubbleAlignment === "right" ? "flex-end" : "flex-start" }]}>
208
+ <CometChatDate
209
+ timeStamp={((item.getDeletedAt() || item.getReadAt() || item.getDeliveredAt() || item.getSentAt()) * 1000)}
210
+ style={{ textColor: theme?.palette?.getAccent600() }}
211
+ pattern={"timeFormat"}
212
+ />
213
+ {
214
+ isSender ?
215
+ <CometChatReceipt
216
+ receipt={item.getStatus()}
217
+ waitIcon={configuration?.loadingIconURL || MessageIcons.WAITING}
218
+ errorIcon={configuration?.errorIconURL || MessageIcons.ERROR_TICK}
219
+ /> :
220
+ null
221
+ }
222
+ </View>
223
+ }
224
+
225
+ return (
226
+ <View style={{ marginBottom: 15, marginHorizontal: 2 }} key={index}>
227
+ <CometChatMessageBubble
228
+ id={`${item.id}`}
229
+ ContentView={() => contentView(item, theme, getBubbleAlignment(item, sender), configuration)}
230
+ FooterView={() => getFooterView(item, getBubbleAlignment(item, sender))}
231
+ alignment={getBubbleAlignment(item, sender)}
232
+ style={getMessageBubbleStyle(item, theme, sender, configuration)}
233
+ />
234
+ </View>
235
+ )
236
+ }
237
+
238
+ const keyExtractor = useCallback((item) => `${item.getMuid()}`, [])
239
+
240
+ return (
241
+ <CometChatBottomSheet
242
+ onClose={onClose}
243
+ style={{
244
+ lineHeight: 15,
245
+ borderRadius: 20
246
+ }}
247
+ >
248
+ <View style={{ height: height * .5, }}>
249
+ <CometChatListItem
250
+ id={bot.getUid()}
251
+ title={title || bot.getName()}
252
+ avatarStyle={configuration?.avatarStyle}
253
+ avatarName={title || bot.getName()}
254
+ avatarURL={bot.getAvatar() ? { uri: bot.getAvatar() } : undefined}
255
+ SubtitleView={() => <Text style={[{ color: subtitleColor }, subtitleFont]}>{localize("COMETCHAT_ASK_BOT_SUBTITLE")}</Text>}
256
+ TailView={() => <TouchableOpacity onPress={onClose}>
257
+ <Image style={{ width: 20, height: 20, tintColor: closeIconTint }} source={configuration?.closeIconURL || CloseIcon} />
258
+ </TouchableOpacity>}
259
+ listItemStyle={{
260
+ titleColor, titleFont,
261
+ }}
262
+ />
263
+ <View style={{ flex: 1 }}>
264
+ <FlatList
265
+ inverted={true}
266
+ data={messages}
267
+ keyExtractor={keyExtractor}
268
+ renderItem={RenderMessageItem}
269
+ />
270
+ </View>
271
+ <View style={{
272
+ flexDirection: "row", alignItems: "center", justifyContent: "center", paddingTop: 10,
273
+ borderTopWidth: 1, borderColor: style?.messageInputStyle?.dividerTint || theme.palette.getAccent200()
274
+ }}>
275
+ <TextInput
276
+ placeholder={localize('ENTER_YOUR_MESSAGE_HERE')}
277
+ placeholderTextColor={style?.messageInputStyle?.placeholderTextColor}
278
+ value={question}
279
+ style={[{
280
+ padding: 8, flex: 1, borderWidth: 1, borderColor: theme.palette.getAccent500(), borderRadius: 20,
281
+ marginLeft: 10, color: style.messageInputStyle.textColor,
282
+ }, style.messageInputStyle.placeholderTextFont, style.messageInputStyle.textFont]}
283
+ onChangeText={onChangeText}
284
+ />
285
+ <TouchableOpacity activeOpacity={!question && 1} onPress={onMsgSend}>
286
+ <Image style={{ width: 30, height: 30, tintColor: sendIconTint, marginHorizontal: 10 }} source={configuration?.sendIconURL || ICONS.SEND} />
287
+ </TouchableOpacity>
288
+ </View>
289
+ </View>
290
+ </CometChatBottomSheet>
291
+ )
292
+ }
293
+
294
+ export default AIAssistBotView
@@ -0,0 +1,22 @@
1
+ import { CometChat } from '@cometchat/chat-sdk-react-native'
2
+ import { AIAssistBotStyle, AIBotMessageBubbleStyle, AISenderMessageBubbleStyle } from './AIAssistBotStyle';
3
+ import { ICONS } from '../../shared/assets/images';
4
+ import { AvatarStyle, CometChatMessageInputStyleInterface } from '../../shared';
5
+
6
+ export class AIAssistBotConfiguration {
7
+ apiConfiguration?: (bot: CometChat.User, user?: CometChat.User, group?: CometChat.Group) => Promise<Object>;
8
+ title: (bot: CometChat.User) => string;
9
+ botFirstMessageText: (bot: CometChat.User) => string;
10
+ closeIconURL: string;
11
+ sendIconURL: string;
12
+ botMessageBubbleStyle: AIBotMessageBubbleStyle;
13
+ senderMessageBubbleStyle: AISenderMessageBubbleStyle;
14
+ avatarStyle?: AvatarStyle;
15
+ messageInputStyle?: CometChatMessageInputStyleInterface;
16
+ style: AIAssistBotStyle;
17
+ loadingIconURL?: string = ICONS.WAITING;
18
+ errorIconURL?: string = ICONS.ERROR_TICK;
19
+ constructor(props: Partial<AIAssistBotConfiguration>) {
20
+ Object.assign(this, props);
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ import CloseIcon from "./CloseIcon.png";
2
+
3
+ export {
4
+ CloseIcon
5
+ }
@@ -1,17 +1,14 @@
1
- import { CardStyle, CardViewStyle } from "./CardViewStyle";
2
1
  import {CometChat} from '@cometchat/chat-sdk-react-native'
3
2
  import { emptyIcon, errorIcon, loadingIcon } from "./resources";
4
- export class AIEnablerConfiguration {
5
- listStyle?: CardViewStyle;
6
- listItemStyle?:CardStyle;
7
- buttonIconURL?: string = "";
3
+ export class AIBaseConfiguration {
4
+ apiConfiguration?: (user?: CometChat.User, group?: CometChat.Group) => Promise<Object>;
8
5
  ErrorStateView?: (e?: CometChat.CometChatException) => JSX.Element;
9
6
  EmptyStateView?: () => JSX.Element;
10
7
  LoadingStateView?: () => JSX.Element;
11
8
  loadingIconURL?:string = loadingIcon;
12
9
  errorIconURL?:string = errorIcon;
13
10
  emptyIconURL?:string = emptyIcon;
14
- constructor(props: Partial<AIEnablerConfiguration>) {
11
+ constructor(props: Partial<AIBaseConfiguration>) {
15
12
  Object.assign(this, props);
16
13
  }
17
14
  }
@@ -0,0 +1,58 @@
1
+ import { BaseStyle, FontStyle } from "../shared";
2
+
3
+ export interface AIBaseStyleInterface extends BaseStyle {
4
+ emptyStateTextFont?: FontStyle;
5
+ emptyStateTextColor?: string;
6
+ loadingStateTextFont?: FontStyle;
7
+ loadingStateTextColor?: string;
8
+ errorStateTextFont?: FontStyle;
9
+ errorStateTextColor?: string;
10
+ loadingIconTint?: string;
11
+ emptyIconTint?: string;
12
+ errorIconTint?: string;
13
+ }
14
+
15
+ export class AIBaseStyle extends BaseStyle {
16
+ emptyStateTextFont?: FontStyle;
17
+ emptyStateTextColor?: string;
18
+ loadingStateTextFont?: FontStyle;
19
+ loadingStateTextColor?: string;
20
+ errorStateTextFont?: FontStyle;
21
+ errorStateTextColor?: string;
22
+ loadingIconTint?: string;
23
+ emptyIconTint?: string;
24
+ errorIconTint?: string;
25
+ constructor({
26
+ emptyIconTint,
27
+ emptyStateTextColor,
28
+ emptyStateTextFont,
29
+ errorIconTint,
30
+ errorStateTextColor,
31
+ errorStateTextFont,
32
+ loadingIconTint,
33
+ loadingStateTextColor,
34
+ loadingStateTextFont,
35
+ backgroundColor,
36
+ border,
37
+ borderRadius,
38
+ height,
39
+ width
40
+ }: AIBaseStyleInterface) {
41
+ super({
42
+ backgroundColor,
43
+ border,
44
+ borderRadius,
45
+ height,
46
+ width
47
+ })
48
+ this.emptyIconTint = emptyIconTint;
49
+ this.emptyStateTextColor = emptyStateTextColor;
50
+ this.emptyStateTextFont = emptyStateTextFont;
51
+ this.errorIconTint = errorIconTint;
52
+ this.errorStateTextColor = errorStateTextColor;
53
+ this.errorStateTextFont = errorStateTextFont;
54
+ this.loadingIconTint = loadingIconTint;
55
+ this.loadingStateTextColor = loadingStateTextColor;
56
+ this.loadingStateTextFont = loadingStateTextFont;
57
+ }
58
+ }