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

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 (134) hide show
  1. package/LICENSE.md +3 -0
  2. package/README.md +1 -1
  3. package/android/src/main/java/com/reactnativecometchatuikit/{RNSoundModule.java → CometChatSoundModule.java} +22 -22
  4. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -1
  5. package/ios/{RNSound.h → CometChatSoundModule.h} +1 -1
  6. package/ios/{RNSound.m → CometChatSoundModule.m} +2 -2
  7. package/package.json +3 -3
  8. package/src/AI/AIConversationStarter/AIConversationStarter.ts +33 -0
  9. package/src/AI/AIConversationStarter/AIConversationStarterDecorator.tsx +231 -0
  10. package/src/AI/AIConversationStarter/AIConversationStarterStyle.ts +8 -0
  11. package/src/AI/AIConversationStarter/configuration.ts +18 -0
  12. package/src/AI/AIConversationStarter/style.ts +76 -0
  13. package/src/AI/AIEnabler.ts +115 -0
  14. package/src/AI/AIEnablerDecorator.tsx +324 -0
  15. package/src/AI/AIExtensionDataSource.ts +12 -0
  16. package/src/AI/AISmartReplies/AISmartReplies.ts +28 -0
  17. package/src/AI/AISmartReplies/AISmartRepliesDecorator.ts +18 -0
  18. package/src/AI/AISmartReplies/AISmartRepliesStyle.ts +16 -0
  19. package/src/AI/AISmartReplies/configuration.ts +17 -0
  20. package/src/AI/CardView.tsx +81 -0
  21. package/src/AI/CardViewStyle.ts +37 -0
  22. package/src/AI/configuration.ts +17 -0
  23. package/src/AI/resources/ai-empty.png +0 -0
  24. package/src/AI/resources/ai-error.png +0 -0
  25. package/src/AI/resources/ai.png +0 -0
  26. package/src/AI/resources/index.ts +11 -0
  27. package/src/AI/resources/spineer.png +0 -0
  28. package/src/AI/style.ts +177 -0
  29. package/src/AI/utils.ts +39 -0
  30. package/src/CometChatConversations/CometChatConversations.tsx +56 -46
  31. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +13 -4
  32. package/src/CometChatMessageHeader/listners.ts +5 -4
  33. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +35 -35
  34. package/src/CometChatMessageList/CometChatMessageList.tsx +274 -158
  35. package/src/CometChatMessages/CometChatMessages.tsx +4 -3
  36. package/src/CometChatTabs/CometChatTabs.tsx +1 -1
  37. package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +4 -10
  38. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
  39. package/src/index.ts +61 -4
  40. package/src/shared/CometChatUiKit/CometChatUIKit.ts +108 -7
  41. package/src/shared/CometChatUiKit/UIKitSettings.ts +8 -0
  42. package/src/shared/constants/UIKitConstants.ts +81 -47
  43. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +46 -0
  44. package/src/shared/events/CometChatUIEventHandler/Listener.ts +66 -3
  45. package/src/shared/events/CometChatUIEvents.ts +1 -0
  46. package/src/shared/events/ListenerInitializer.ts +73 -0
  47. package/src/shared/events/messages.ts +14 -0
  48. package/src/shared/framework/DataSource.ts +12 -1
  49. package/src/shared/framework/DataSourceDecorator.tsx +37 -2
  50. package/src/shared/framework/MessageDataSource.tsx +85 -5
  51. package/src/shared/index.ts +44 -0
  52. package/src/shared/modals/InteractiveData/InteractiveActions/APIAction.ts +118 -0
  53. package/src/shared/modals/InteractiveData/InteractiveActions/CustomAction.ts +19 -0
  54. package/src/shared/modals/InteractiveData/InteractiveActions/URLNavigationAction.ts +34 -0
  55. package/src/shared/modals/InteractiveData/InteractiveActions/index.ts +3 -0
  56. package/src/shared/modals/InteractiveData/InteractiveData/InteractiveCardData.ts +69 -0
  57. package/src/shared/modals/InteractiveData/InteractiveData/InteractiveFormData.ts +119 -0
  58. package/src/shared/modals/InteractiveData/InteractiveData/index.ts +2 -0
  59. package/src/shared/modals/InteractiveData/InteractiveElements/BaseInputElement.ts +102 -0
  60. package/src/shared/modals/InteractiveData/InteractiveElements/BaseInteractiveElement.ts +45 -0
  61. package/src/shared/modals/InteractiveData/InteractiveElements/ButtonElement.ts +61 -0
  62. package/src/shared/modals/InteractiveData/InteractiveElements/CheckboxElement.ts +75 -0
  63. package/src/shared/modals/InteractiveData/InteractiveElements/DropdownElement.ts +83 -0
  64. package/src/shared/modals/InteractiveData/InteractiveElements/LabelElement.ts +32 -0
  65. package/src/shared/modals/InteractiveData/InteractiveElements/OptionElement.ts +39 -0
  66. package/src/shared/modals/InteractiveData/InteractiveElements/RadioButtonElement.ts +76 -0
  67. package/src/shared/modals/InteractiveData/InteractiveElements/SingleSelectElement.ts +76 -0
  68. package/src/shared/modals/InteractiveData/InteractiveElements/TextInputElement.ts +101 -0
  69. package/src/shared/modals/InteractiveData/InteractiveElements/index.ts +10 -0
  70. package/src/shared/modals/InteractiveData/InteractiveEntities/ActionEntity.ts +41 -0
  71. package/src/shared/modals/InteractiveData/InteractiveEntities/ElementEntity.ts +64 -0
  72. package/src/shared/modals/InteractiveData/InteractiveEntities/index.ts +2 -0
  73. package/src/shared/modals/InteractiveData/InteractiveMessage/CardMessage.ts +142 -0
  74. package/src/shared/modals/InteractiveData/InteractiveMessage/CustomInteractiveMessage.ts +38 -0
  75. package/src/shared/modals/InteractiveData/InteractiveMessage/FormMessage.ts +152 -0
  76. package/src/shared/modals/InteractiveData/InteractiveMessage/index.ts +3 -0
  77. package/src/shared/modals/InteractiveData/index.ts +28 -0
  78. package/src/shared/modals/index.ts +19 -0
  79. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +8 -1
  80. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +8 -1
  81. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +8 -1
  82. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +8 -1
  83. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +8 -1
  84. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +8 -1
  85. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +8 -1
  86. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +8 -1
  87. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +8 -1
  88. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +8 -1
  89. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +8 -1
  90. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +8 -1
  91. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +8 -1
  92. package/src/shared/resources/CometChatSoundManager/CometChatSoundManager.js +2 -2
  93. package/src/shared/resources/CometChatSoundManager/sound.js +35 -35
  94. package/src/shared/utils/InteractiveMessageUtils.ts +20 -0
  95. package/src/shared/utils/NetworkUtils.tsx +20 -0
  96. package/src/shared/utils/conversationUtils.ts +9 -6
  97. package/src/shared/views/CometChatButton/CometChatButton.tsx +32 -22
  98. package/src/shared/views/CometChatCardBubble/CardBubbleStyle.tsx +47 -0
  99. package/src/shared/views/CometChatCardBubble/CometChatCardBubble.tsx +173 -0
  100. package/src/shared/views/CometChatCardBubble/index.tsx +1 -0
  101. package/src/shared/views/CometChatCheckBox/CheckBoxStyle.tsx +43 -0
  102. package/src/shared/views/CometChatCheckBox/CometChatCheckBox.tsx +79 -0
  103. package/src/shared/views/CometChatDate/CometChatDate.tsx +2 -3
  104. package/src/shared/views/CometChatDropDown/CometChatDropDown.tsx +126 -0
  105. package/src/shared/views/CometChatDropDown/DropDownStyle.tsx +39 -0
  106. package/src/shared/views/CometChatDropDown/resources/downArrowIcon.png +0 -0
  107. package/src/shared/views/CometChatDropDown/resources/index.js +5 -0
  108. package/src/shared/views/CometChatFormBubble/CometChatFormBubble.tsx +464 -0
  109. package/src/shared/views/CometChatFormBubble/FormBubbleStyle.tsx +91 -0
  110. package/src/shared/views/CometChatFormBubble/index.tsx +1 -0
  111. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +13 -5
  112. package/src/shared/views/CometChatImageBubble/ImageBubbleStyle.ts +14 -3
  113. package/src/shared/views/CometChatLabel/CometChatLabel.tsx +27 -0
  114. package/src/shared/views/CometChatLabel/LabelStyle.ts +19 -0
  115. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +5 -4
  116. package/src/shared/views/CometChatQuickView/CometChatQuickView.tsx +66 -0
  117. package/src/shared/views/CometChatQuickView/QuickViewStyle.ts +55 -0
  118. package/src/shared/views/CometChatRadioButton/CometChatRadioButton.tsx +67 -0
  119. package/src/shared/views/CometChatRadioButton/RadioButtonStyle.tsx +38 -0
  120. package/src/shared/views/CometChatSingleSelect/CometChatSingleSelect.tsx +63 -0
  121. package/src/shared/views/CometChatSingleSelect/SingleStyle.tsx +35 -0
  122. package/src/shared/views/CometChatTextInput/CometChatTextInput.tsx +67 -0
  123. package/src/shared/views/CometChatTextInput/TextInputStyle.tsx +26 -0
  124. package/src/shared/views/index.ts +7 -1
  125. package/LICENSE +0 -21
  126. package/android/.idea/.gitignore +0 -3
  127. package/android/local.properties +0 -8
  128. package/src/.DS_Store +0 -0
  129. package/src/CometChatMessageInformation/.DS_Store +0 -0
  130. package/src/calls/CometChatCallHistory/.DS_Store +0 -0
  131. package/src/shared/framework/.DS_Store +0 -0
  132. package/src/shared/views/.DS_Store +0 -0
  133. package/src/shared/views/CometChatAudioBubble/.DS_Store +0 -0
  134. package/src/shared/views/CometChatFileBubble/.DS_Store +0 -0
@@ -0,0 +1,115 @@
1
+ import { ChatConfigurator, DataSource } from "../shared";
2
+ import { AIConversationStarterExtension } from "./AIConversationStarter/AIConversationStarter";
3
+ import { AIEnablerDecorator } from "./AIEnablerDecorator";
4
+ import { AIExtensionDataSource } from "./AIExtensionDataSource";
5
+ import { AISmartRepliesExtension } from "./AISmartReplies/AISmartReplies";
6
+ import {CometChat} from '@cometchat/chat-sdk-react-native'
7
+ import { AIEnablerConfiguration } from "./configuration";
8
+ export class AIEnabler extends AIExtensionDataSource {
9
+ defaultAIFeatures:AIExtensionDataSource[] | undefined;
10
+ configuration?:AIEnablerConfiguration = {}
11
+ constructor(defaultFeatures?:AIExtensionDataSource[], configuration?:AIEnablerConfiguration){
12
+ super()
13
+ this.configuration = configuration
14
+ this.defaultAIFeatures = defaultFeatures
15
+ }
16
+ override addExtension(): void {
17
+
18
+ }
19
+ override getExtensionId(): string {
20
+ return "ai-enabler";
21
+ }
22
+ override enable(): void {
23
+ let features = {}
24
+ if (this.defaultAIFeatures && this.defaultAIFeatures?.length >= 1) {
25
+ const promiseArray = this.defaultAIFeatures.map((feature) => {
26
+ return new Promise((resolve, reject) => {
27
+ CometChat.isAIFeatureEnabled(feature.getExtensionId())
28
+ .then((response) => {
29
+ if (response) {
30
+
31
+ if (feature.getExtensionId() !== "conversation-starter") {
32
+ feature?.enable();
33
+ features[feature.getExtensionId()] = {
34
+ enabled: true,
35
+ configuration: feature.getConfiguration(),
36
+ enabler: feature,
37
+ };
38
+ }
39
+ else{
40
+ feature.setConfiguration(this.configuration)
41
+ feature.enable();
42
+ }
43
+ }
44
+ resolve(true);
45
+ })
46
+ .catch((err) => {
47
+ console.error(err);
48
+ reject(err);
49
+ });
50
+ });
51
+ });
52
+
53
+ Promise.all(promiseArray)
54
+ .then(() => {
55
+ if (Object.keys(features).length > 0) {
56
+ ChatConfigurator.enable(
57
+ (dataSource: DataSource) =>
58
+ new AIEnablerDecorator(dataSource, features, this.configuration)
59
+ );
60
+ }
61
+ })
62
+ .catch((err) => {
63
+ console.error('An error occurred:', err);
64
+ });
65
+ }
66
+ else if(this.defaultAIFeatures?.length == 0){
67
+ return;
68
+ }
69
+ else{
70
+ let defaultFeatures: AIExtensionDataSource[] = [new AISmartRepliesExtension(), new AIConversationStarterExtension()];
71
+
72
+ const promiseArray = defaultFeatures.map((feature) => {
73
+ return new Promise((resolve, reject) => {
74
+ CometChat.isAIFeatureEnabled(feature.getExtensionId())
75
+ .then((response) => {
76
+ if (response) {
77
+
78
+ if (feature.getExtensionId() !== "conversation-starter") {
79
+ feature?.enable();
80
+ features[feature.getExtensionId()] = {
81
+ enabled: true,
82
+ configuration: feature.getConfiguration(),
83
+ enabler: feature,
84
+ };
85
+ }
86
+ else{
87
+ feature.setConfiguration(this.configuration)
88
+ feature.enable();
89
+ }
90
+ }
91
+ resolve(true);
92
+ })
93
+ .catch((err) => {
94
+ console.error(err);
95
+ reject(err);
96
+ });
97
+ });
98
+ });
99
+
100
+ Promise.all(promiseArray)
101
+ .then(() => {
102
+ if (Object.keys(features).length > 0) {
103
+ ChatConfigurator.enable(
104
+ (dataSource: DataSource) =>
105
+ new AIEnablerDecorator(dataSource, features, this.configuration)
106
+ );
107
+ }
108
+ })
109
+ .catch((err) => {
110
+ console.error('An error occurred:', err);
111
+ });
112
+ }
113
+ }
114
+
115
+ }
@@ -0,0 +1,324 @@
1
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
2
+ import { DataSourceDecorator, DataSource, CometChatTheme, CometChatUIEvents, localize, CometChatUIEventHandler, CometChatBottomSheet, FontStyleInterface, BorderStyleInterface, BaseStyle } from "../shared";
3
+ import { CometChatButton } from "../shared/views/CometChatButton";
4
+
5
+ import { CardView, Card } from "./CardView";
6
+ import { CardViewStyle } from "./CardViewStyle";
7
+ import { getRepliesWrapperStyle, getRepliesStyle, getCardViewStyle, getButtonStyles, getPopoverStyle, defaultViewStyle, viewContainerStyle, emptyLabelStyle, errorLabelStyle, getloadingStateStyle } from "./style";
8
+ import { ReceiverTypeConstants, ViewAlignment } from "../shared/constants/UIKitConstants";
9
+ import { Image, TouchableOpacity, View, Text, ScrollView, Keyboard } from "react-native";
10
+ import React, { useEffect, useRef, useState, JSX ,useContext} from "react";
11
+ import { AIBotIcon,loadingIcon,emptyIcon,errorIcon } from './resources';
12
+ import { CometChatContext } from "../shared/CometChatContext";
13
+ import { AIEnablerConfiguration } from "./configuration";
14
+ import { AIConfigurations, ICard, State } from "./utils";
15
+ import { AIConversationStarterConfiguration } from "./AIConversationStarter/configuration";
16
+ import { AISmartRepliesConfiguration } from "./AISmartReplies/configuration";
17
+
18
+ export class AIEnablerDecorator extends DataSourceDecorator {
19
+ smartReplyConfiguration: AISmartRepliesConfiguration = new AISmartRepliesConfiguration({});
20
+ conversationStarterConfiguration: AIConversationStarterConfiguration = new AIConversationStarterConfiguration({});
21
+ features?: AIConfigurations = {};
22
+ configuration?: AIEnablerConfiguration = new AIEnablerConfiguration({});
23
+ public newDataSource!: DataSource;
24
+ public showAiButton: boolean = false;
25
+ public theme!: CometChatTheme;
26
+ public id: any;
27
+ public user!: CometChat.User;
28
+ public group!: CometChat.Group;
29
+ public loggedInUser!: CometChat.User | null;
30
+ public cardViewStyle: CardViewStyle = {};
31
+ public buttonRef: any;
32
+ public setCallback: any;
33
+ public isPannelVisible:boolean = false;
34
+ public repliesView:JSX.Element;
35
+ public errorStateText:string = localize("SOMETHING_WRONG");
36
+ public emptyStateText:string = localize("NO_MESSAGES_FOUND");
37
+ public keyboardDidShowListener;
38
+ public keyboardDidHideListener;
39
+ onButtonClick = (id: string): void => {
40
+ if (id == "smart-replies") {
41
+ this.showDefaultPanel(State.loading)
42
+ this.getSmartReplies().then((replies) => {
43
+ if(!replies || (replies?.length && replies.length <= 0)){
44
+ this.showDefaultPanel(State.empty)
45
+ }
46
+ else{
47
+ 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 }}>
48
+ <ScrollView style={{ height: "100%", width: "100%" }}>
49
+ {replies}
50
+ </ScrollView>
51
+
52
+
53
+ </View>)
54
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.showPanel, {
55
+ alignment: ViewAlignment.composerBottom,
56
+ child: () => this.repliesView,
57
+ });
58
+ }
59
+
60
+ this.isPannelVisible = true
61
+
62
+ })
63
+ .catch((err) => {
64
+ this.showDefaultPanel(State.error,err)
65
+
66
+ })
67
+ }
68
+ }
69
+ public cardsData: ICard = {}
70
+ constructor(dataSource: DataSource, features?: AIConfigurations, configuration?: AIEnablerConfiguration) {
71
+ super(dataSource);
72
+ this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.hideOnKeyboardShow);
73
+ this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this.showOnKeyboardShow);
74
+ if (configuration) {
75
+ this.configuration = configuration;
76
+ }
77
+ this.newDataSource = dataSource;
78
+ this.features = features;
79
+ CometChat.getLoggedinUser().then(
80
+ (user: CometChat.User | null) => {
81
+ if (user) {
82
+ this.loggedInUser = user
83
+ }
84
+ }
85
+ );
86
+ }
87
+ getDataSource() {
88
+ return this.newDataSource;
89
+ }
90
+ getId(): string {
91
+ return "aienabler";
92
+ }
93
+ hideOnKeyboardShow = () => {
94
+ if(this.isPannelVisible){
95
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
96
+ alignment: ViewAlignment.composerBottom,
97
+ child: () => (null),
98
+ });
99
+ }
100
+ }
101
+ showOnKeyboardShow = () => {
102
+ if(this.isPannelVisible){
103
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
104
+ alignment: ViewAlignment.composerBottom,
105
+ child: () => this.repliesView,
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
+ closeBottomsheet = () => {
120
+ if (this.setCallback) {
121
+ this.setCallback(false)
122
+ }
123
+ }
124
+
125
+ getSmartReplies(): Promise<JSX.Element> {
126
+ return new Promise((resolve, reject) => {
127
+ let receiverId: string = this.user ? this.user?.getUid() : this.group?.getGuid();
128
+ let receiverType: string = this.user ? ReceiverTypeConstants.user : ReceiverTypeConstants.group;
129
+ if (this.smartReplyConfiguration?.customView) {
130
+ CometChat.getSmartReplies(receiverId, receiverType).then((response: any) => {
131
+ this.smartReplyConfiguration.customView(response, this.closeBottomsheet).then((res)=>{
132
+ return resolve((<View>{res}</View>))
133
+
134
+ })
135
+ .catch((err: CometChat.CometChatException) => {
136
+ return reject(err)
137
+ })
138
+
139
+ })
140
+ .catch((err: CometChat.CometChatException) => {
141
+ return reject(err)
142
+ })
143
+ }
144
+ else if (this.smartReplyConfiguration?.onClick) {
145
+ this.smartReplyConfiguration?.onClick(this.user, this.group).then((response: any) => {
146
+ return resolve((<View>{response}</View>))
147
+ })
148
+ .catch((err: CometChat.CometChatException) => {
149
+ return reject(err)
150
+ })
151
+
152
+ }
153
+ else {
154
+ CometChat.getSmartReplies(receiverId, receiverType).then((response: any) => {
155
+ let view: JSX.Element[] = []
156
+ Object.keys(response).forEach((reply) => {
157
+ if (response[reply] && response[reply] != "") {
158
+ view.push(
159
+ (<TouchableOpacity
160
+ style={getRepliesWrapperStyle(this.theme, this.smartReplyConfiguration?.smartRepliesStyle, this.configuration?.listItemStyle)}
161
+ key={response[reply]} // Make sure to set a unique key for each item
162
+ onPress={() => this.editReply(response[reply])}
163
+ >
164
+ <Text style={getRepliesStyle(this.theme, this.smartReplyConfiguration?.smartRepliesStyle, this.configuration?.listItemStyle)}>{response[reply]}</Text>
165
+ </TouchableOpacity>)
166
+
167
+ )
168
+ }
169
+
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
+ showDefaultPanel(state:State = State.loading, error?:CometChat.CometChatException) {
186
+ this.closeBottomsheet()
187
+ let LoadingView:JSX.Element = this.smartReplyConfiguration?.LoadingStateView || this.configuration.LoadingStateView
188
+ let EmptyView:JSX.Element = this.smartReplyConfiguration?.EmptyStateView || this.configuration.EmptyStateView
189
+ let ErrorView:JSX.Element = this.smartReplyConfiguration?.ErrorStateView || this.configuration.ErrorStateView
190
+
191
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.showPanel, {
192
+ alignment: ViewAlignment.composerBottom,
193
+ child: () => (
194
+ <View style={{ width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 160, backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center" }}>
195
+ {state == State.loading ? LoadingView ? <LoadingView/> : <View style={{ width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 160, backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center" }}>
196
+ <Image
197
+ source={this.configuration?.loadingIconURL ?? loadingIcon}
198
+ style={{ height: 32, width: 32,tintColor:this.cardViewStyle?.loadingIconTint}}
199
+ />
200
+ <Text style={getloadingStateStyle(this.theme,this.cardViewStyle, this.smartReplyConfiguration?.smartRepliesStyle)}> {localize("GENERATING_REPLIES")}</Text>
201
+ </View>
202
+
203
+ :
204
+
205
+ state == State.empty ?
206
+ EmptyView ? <EmptyView/> : <View style={{ width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 160, backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center" }}>
207
+ <Image
208
+ source={this.configuration?.emptyIconURL ?? emptyIcon}
209
+ style={{ height: 32, width: 32,tintColor:this.cardViewStyle?.emptyIconTint}}
210
+ />
211
+ <Text style={emptyLabelStyle(this.cardViewStyle,this.smartReplyConfiguration.smartRepliesStyle)} > {this.emptyStateText}</Text>
212
+ </View>
213
+ : ErrorView ? ErrorView(error) :
214
+ <View style={{ width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 160, backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center" }}>
215
+ <Image
216
+ source={this.configuration?.errorIconURL ?? errorIcon}
217
+ style={{ height: 32, width: 32,tintColor:this.cardViewStyle?.errorIconTint}}
218
+ />
219
+ <Text style={errorLabelStyle(this.cardViewStyle,this.smartReplyConfiguration.smartRepliesStyle)} >{this.errorStateText}</Text>
220
+ </View>
221
+
222
+ }
223
+
224
+
225
+ </View>
226
+
227
+ ),
228
+ });
229
+
230
+ this.isPannelVisible = true;
231
+ }
232
+
233
+
234
+ getAuxiliaryOptions(user?: CometChat.User, group?: CometChat.Group, id?: Map<string, any>, theme?: CometChatTheme) {
235
+ let contextTheme = useContext(CometChatContext)
236
+ if(contextTheme?.theme){
237
+ this.theme = contextTheme.theme
238
+ }
239
+ else{
240
+ this.theme = theme || new CometChatTheme({});
241
+ }
242
+ this.cardViewStyle = getCardViewStyle(this.theme, this.configuration?.listStyle,this.smartReplyConfiguration.smartRepliesStyle);
243
+ this.id = id;
244
+ this.user = user!;
245
+ this.group = group!;
246
+ let auxiliaryOptions = super.getAuxiliaryOptions(user, group, id, theme);
247
+ this.cardsData = {
248
+ smartReply: {
249
+ title: localize("SUGGEST_A_REPLIES"),
250
+ onClick: this.onButtonClick,
251
+ id: "smart-replies",
252
+ style: getButtonStyles(this.theme, this.smartReplyConfiguration?.smartRepliesStyle, this.configuration?.listItemStyle)
253
+
254
+ },
255
+ conversationStarter: {
256
+ title: "Conversation Starter",
257
+ onClick: this.onButtonClick,
258
+ id: "conversation-starter",
259
+ style: getButtonStyles(this.theme, this.conversationStarterConfiguration?.conversationStarterStyle)
260
+
261
+ }
262
+ };
263
+
264
+
265
+
266
+ if (!(id as any).parentMessageId || Number((id as any).parentMessageId) <= 0 || (id as any).parentMessageId == undefined) {
267
+
268
+ auxiliaryOptions.unshift(this.getAIAuxiliaryButton(id, user, group, theme));
269
+ }
270
+ return auxiliaryOptions;
271
+ }
272
+
273
+ getAIAuxiliaryButton(id: Map<string, any>, user?: CometChat.User, group?: CometChat.Group, theme?: CometChatTheme): JSX.Element {
274
+ const [aiFeatures, setAiFeatures] = useState(false);
275
+ let cards: Card[] = []
276
+ this.setCallback = setAiFeatures
277
+ if (this.features && Object.keys(this.features).length > 0) {
278
+
279
+ if (this.features?.["smart-replies"]?.enabled) {
280
+ this.smartReplyConfiguration = this.features?.["smart-replies"]?.configuration ?? new AISmartRepliesConfiguration({})
281
+ cards.push(this.cardsData.smartReply!)
282
+ }
283
+
284
+
285
+ }
286
+
287
+ return (<TouchableOpacity onPress={() => {
288
+ CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
289
+ alignment: ViewAlignment.composerBottom,
290
+ child: () => (null),
291
+ });
292
+ if(this.isPannelVisible){
293
+ setAiFeatures(false);
294
+ this.isPannelVisible = false;
295
+ return;
296
+ }
297
+ setAiFeatures(true);
298
+
299
+ }} style={{ justifyContent: "center" }}>
300
+ <Image
301
+ source={this.configuration?.buttonIconURL || AIBotIcon}
302
+ style={{ height: 32, width: 32, marginLeft: 8, marginRight: 8 , color:'red'}}
303
+ />
304
+ {
305
+ <CometChatBottomSheet
306
+ isOpen={aiFeatures}
307
+ sliderMaxHeight={this.cardViewStyle?.height || 350}
308
+ onClose={() => {
309
+ setAiFeatures(false)
310
+ }}
311
+
312
+ >
313
+ <CardView
314
+ cardViewStyle={this.cardViewStyle}
315
+ buttons={cards}
316
+ />
317
+ </CometChatBottomSheet>
318
+ }
319
+ </TouchableOpacity>)
320
+
321
+ }
322
+
323
+ }
324
+
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,28 @@
1
+ import { AISmartRepliesExtensionDecorator } from "./AISmartRepliesDecorator";
2
+ import { ChatConfigurator } from "../../shared";
3
+ import { AIExtensionDataSource } from "../AIExtensionDataSource";
4
+ import { AISmartRepliesConfiguration } from "./configuration";
5
+ export class AISmartRepliesExtension extends AIExtensionDataSource {
6
+
7
+ private configuration?: AISmartRepliesConfiguration;
8
+
9
+ constructor(configuration?: AISmartRepliesConfiguration) {
10
+ super();
11
+ this.configuration = configuration;
12
+ }
13
+ override addExtension(): void {
14
+ ChatConfigurator.enable((dataSource: any) => new AISmartRepliesExtensionDecorator(dataSource,this.configuration));
15
+ }
16
+ override getExtensionId(): string {
17
+ return "smart-replies";
18
+ }
19
+ override enable(): void {
20
+ this.addExtension()
21
+
22
+ }
23
+ override getConfiguration():AISmartRepliesConfiguration{
24
+ return this.configuration;
25
+ }
26
+
27
+
28
+ }
@@ -0,0 +1,18 @@
1
+ import { DataSource,DataSourceDecorator } from "../../shared";
2
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
3
+ import { AIButtonsStyle } from "../utils";
4
+ import { AISmartRepliesConfiguration } from "./configuration";
5
+ export class AISmartRepliesExtensionDecorator extends DataSourceDecorator {
6
+ public configuration?:AISmartRepliesConfiguration;
7
+ constructor(dataSource:DataSource,configuration?:AISmartRepliesConfiguration){
8
+ super(dataSource);
9
+ this.configuration = configuration;
10
+ }
11
+ override getId(): string {
12
+ return "aismartreply";
13
+ }
14
+ }
15
+
16
+
17
+
18
+
@@ -0,0 +1,16 @@
1
+ import { FontStyleInterface, BorderStyleInterface } from "../../shared";
2
+ import { AIButtonsStyle } from "../utils";
3
+
4
+ export class AISmartRepliesStyle extends AIButtonsStyle {
5
+ buttonTextColor?:string;
6
+ buttonTextFont?:FontStyleInterface;
7
+ buttonBorder?:BorderStyleInterface;
8
+ buttonBorderRadius?:string;
9
+ buttonHeight?:string;
10
+ buttonWidth?:string;
11
+ buttonBackgroundColor?:string;
12
+ constructor(props: Partial<AIButtonsStyle>) {
13
+ super({...props})
14
+ Object.assign(this, props);
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ import {CometChat} from '@cometchat/chat-sdk-react-native'
2
+ 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;
7
+ 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;
14
+ constructor(props: Partial<AISmartRepliesConfiguration>) {
15
+ Object.assign(this, props);
16
+ }
17
+ }
@@ -0,0 +1,81 @@
1
+ import { useState } from 'react';
2
+ import { contentContainerStyle, getButtonStyles, getPopoverStyle } from './style';
3
+ import { CardViewStyle } from './CardViewStyle';
4
+ import { CometChatTheme } from '../shared';
5
+ import { TouchableOpacity,Text,ScrollView } from 'react-native';
6
+ import React from 'react';
7
+ import { View } from 'react-native';
8
+ import { AIButtonsStyle } from './utils';
9
+ export type Card = {
10
+ title?: string;
11
+ id?: string;
12
+ onClick?: (id: string) => void;
13
+ style?:AIButtonsStyle;
14
+ };
15
+ interface CardProps {
16
+ buttons?: Card[];
17
+ backCallback?:(callback:()=>void) => void;
18
+ cardViewStyle?:CardViewStyle;
19
+ };
20
+
21
+ const defaultProps:CardProps = {
22
+ buttons: undefined,
23
+ backCallback:undefined,
24
+ cardViewStyle:undefined
25
+ }
26
+
27
+
28
+ export const CardView = (props:CardProps) => {
29
+ const [currentSection, setCurrentSection] = useState<string | null>(null);
30
+
31
+ function fetchButtonContent(button:Card){
32
+
33
+
34
+ setCurrentSection(button?.id!)
35
+ if(button && button.onClick){
36
+ button.onClick(button.id!)
37
+ }
38
+ }
39
+
40
+
41
+
42
+ function getButtons():JSX.Element | null{
43
+ return (
44
+ <View style={{
45
+ width:"100%",
46
+ backgroundColor: "transparent",
47
+ }}>
48
+ {props.buttons.map(item => (
49
+ <TouchableOpacity
50
+ key={item.id} // Make sure to set a unique key for each item
51
+ onPress={() => fetchButtonContent(item)}
52
+
53
+ >
54
+ <Text style={getButtonStyles(new CometChatTheme({}),item?.style)}>{item.title}</Text>
55
+ </TouchableOpacity>
56
+
57
+ ))}
58
+ </View>)
59
+
60
+ }
61
+
62
+ return (
63
+ <View style={getPopoverStyle(props.cardViewStyle)}>
64
+
65
+ <View style={contentContainerStyle}>
66
+ {!currentSection && props.buttons && (
67
+ <ScrollView style={{height:"100%",width:"100%"}}>
68
+
69
+ { getButtons()}
70
+ </ScrollView>
71
+
72
+
73
+ )}
74
+
75
+ </View>
76
+ </View>
77
+ );
78
+ };
79
+
80
+ CardView.defaultProps = defaultProps
81
+ export default CardView;
@@ -0,0 +1,37 @@
1
+ import { BaseStyle, BorderStyleInterface, FontStyleInterface } from "../shared";
2
+
3
+ export class CardViewStyle extends BaseStyle{
4
+ emptyStateTextFont?: FontStyleInterface;
5
+ emptyStateTextColor?: string = "#bcbcbc";
6
+ errorStateTextFont?: FontStyleInterface;
7
+ errorStateTextColor?: string = "#bcbcbc";
8
+ loadingStateTextFont?: FontStyleInterface;
9
+ loadingStateTextColor?: string = "#bcbcbc";
10
+ loadingIconTint?: string = "#bcbcbc";
11
+ errorIconTint?: string = "#bcbcbc";
12
+ emptyIconTint?: string = "#bcbcbc";
13
+ boxShadow?:string;
14
+ constructor(props: Partial<CardViewStyle>) {
15
+ super({})
16
+ Object.assign(this, props);
17
+ }
18
+ }
19
+
20
+ export class CardStyle extends BaseStyle{
21
+ buttonTextColor?:string;
22
+ buttonTextFont?:FontStyleInterface;
23
+ buttonBorder?:BorderStyleInterface;
24
+ buttonBorderRadius?:string;
25
+ buttonHeight?:string;
26
+ buttonWidth?:string;
27
+ buttonBackgroundColor?:string;
28
+ repliesTextFont?:FontStyleInterface;
29
+ repliesTextBorder?:BorderStyleInterface;
30
+ repliesTextBorderRadius?:string;
31
+ repliesTextColor?:string;
32
+ repliesTextBackgroundColor?:string;
33
+ constructor(props: Partial<CardViewStyle>) {
34
+ super({})
35
+ Object.assign(this, props);
36
+ }
37
+ }
@@ -0,0 +1,17 @@
1
+ import { CardStyle, CardViewStyle } from "./CardViewStyle";
2
+ import {CometChat} from '@cometchat/chat-sdk-react-native'
3
+ import { emptyIcon, errorIcon, loadingIcon } from "./resources";
4
+ export class AIEnablerConfiguration {
5
+ listStyle?: CardViewStyle;
6
+ listItemStyle?:CardStyle;
7
+ buttonIconURL?: string = "";
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;
14
+ constructor(props: Partial<AIEnablerConfiguration>) {
15
+ Object.assign(this, props);
16
+ }
17
+ }
Binary file
Binary file
Binary file