Skip to content

Commit f96b758

Browse files
kostap13Konstantin Latypov
andauthored
feat(mobile-messaging): add chat methods (#4231)
Co-authored-by: Konstantin Latypov <[email protected]>
1 parent 7a528b4 commit f96b758

File tree

1 file changed

+119
-5
lines changed
  • src/@awesome-cordova-plugins/plugins/mobile-messaging

1 file changed

+119
-5
lines changed

src/@awesome-cordova-plugins/plugins/mobile-messaging/index.ts

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type Event =
1515
| 'userUpdated'
1616
| 'personalized'
1717
| 'depersonalized'
18+
| 'inAppChat.availabilityUpdated'
19+
| 'inAppChat.unreadMessageCounterUpdated'
1820
| 'deeplink';
1921

2022
export interface CustomEvent {
@@ -32,7 +34,7 @@ export interface Configuration {
3234
/**
3335
* Message storage save callback
3436
*/
35-
messageStorage?: string;
37+
messageStorage?: CustomMessageStorage;
3638
defaultMessageStorage?: boolean;
3739
ios?: {
3840
notificationTypes?: string[]; // ['alert', 'badge', 'sound']
@@ -43,6 +45,15 @@ export interface Configuration {
4345
notificationIcon?: string; // a resource name for a status bar icon (without extension), located in '/platforms/android/app/src/main/res/mipmap'
4446
multipleNotifications?: boolean; // set to 'true' to enable multiple notifications
4547
notificationAccentColor?: string; // set to hex color value in format '#RRGGBB' or '#AARRGGBB'
48+
firebaseOptions?: {
49+
apiKey: string;
50+
applicationId: string;
51+
databaseUrl?: string;
52+
gaTrackingId?: string;
53+
gcmSenderId?: string;
54+
storageBucket?: string;
55+
projectId: string;
56+
};
4657
};
4758
privacySettings?: {
4859
applicationCodePersistingDisabled?: boolean;
@@ -52,10 +63,10 @@ export interface Configuration {
5263
};
5364
notificationCategories?: [
5465
{
55-
identifier?: string;
66+
identifier: string;
5667
actions?: [
5768
{
58-
identifier?: string;
69+
identifier: string;
5970
title?: string;
6071
foreground?: boolean;
6172
authenticationRequired?: boolean;
@@ -71,7 +82,7 @@ export interface Configuration {
7182
}
7283

7384
export interface UserData {
74-
externalUserId: string;
85+
externalUserId?: string;
7586
firstName?: string;
7687
lastName?: string;
7788
middleName?: string;
@@ -117,6 +128,22 @@ export interface PersonalizeContext {
117128
forceDepersonalize?: boolean;
118129
}
119130

131+
export interface GeoData {
132+
area: GeoArea;
133+
}
134+
135+
export interface GeoArea {
136+
id: string;
137+
center: GeoCenter;
138+
radius: number;
139+
title: string;
140+
}
141+
142+
export interface GeoCenter {
143+
lat: number;
144+
lon: number;
145+
}
146+
120147
export interface Message {
121148
messageId: string;
122149
title?: string;
@@ -138,12 +165,14 @@ export interface Message {
138165
browserUrl?: string;
139166
deeplink?: string;
140167
webViewUrl?: string;
168+
inAppOpenTitle?: string | undefined;
141169
inAppDismissTitle?: string;
142170
}
143171

144172
export interface MobileMessagingError {
145173
code: string;
146-
message: string;
174+
description: string;
175+
domain?: string;
147176
}
148177

149178
export interface ChatConfig {
@@ -174,6 +203,62 @@ export class DefaultMessageStorage {
174203
}
175204
}
176205

206+
export class CustomMessageStorage {
207+
/**
208+
* Will be called by the plugin when messages are received and it's time to save them to the storage
209+
*
210+
* @param array of message objects to save to storage
211+
*/
212+
@Cordova({ sync: true })
213+
save(messages: Message[]) {
214+
return;
215+
}
216+
217+
/**
218+
* Will be called by the plugin to find a message by message id
219+
*
220+
* @param callback has to be called on completion with one parameter - found message object
221+
*/
222+
@Cordova({ sync: true })
223+
find(messageId: string, callback: (message: Message) => void) {
224+
return;
225+
}
226+
227+
/**
228+
* Will be called by the plugin to find all messages in the storage
229+
*
230+
* @param callback has to be called on completion with one parameter - an array of available messages
231+
*/
232+
@Cordova({ sync: true })
233+
findAll(callback: (messages: Message[]) => void) {
234+
return;
235+
}
236+
237+
/**
238+
* Will be called by the plugin when its time to initialize the storage
239+
*/
240+
@Cordova({ sync: true })
241+
start() {
242+
return;
243+
}
244+
245+
/**
246+
* Will be called by the plugin when its time to deinitialize the storage
247+
*/
248+
@Cordova({ sync: true })
249+
stop() {
250+
return;
251+
}
252+
}
253+
254+
export interface ChatSettingsIOS {
255+
title: string;
256+
sendButtonColor: string;
257+
navigationBarItemsColor: string;
258+
navigationBarColor: string;
259+
navigationBarTitleColor: string;
260+
}
261+
177262
/**
178263
* @name Mobile Messaging
179264
* @description
@@ -472,4 +557,33 @@ export class MobileMessaging extends AwesomeCordovaNativePlugin {
472557
showChat(config?: ChatConfig): Promise<any> {
473558
return;
474559
}
560+
561+
/**
562+
* Setup chat settings for iOS only
563+
*
564+
* @param settings
565+
*/
566+
@Cordova()
567+
setupiOSChatSettings(settings: ChatSettingsIOS): Promise<any> {
568+
return;
569+
}
570+
571+
/**
572+
* Returns unread in-app chat push messages counter.
573+
* The counter increments each time the application receives in-app chat push message
574+
* (this usually happens when chat screen is inactive or the application is in background/terminated state).
575+
*/
576+
@Cordova({ sync: true })
577+
getMessageCounter(onResult: (counter: number) => void) {
578+
return;
579+
}
580+
581+
/**
582+
* MobileMessaging plugin automatically resets the counter to 0 whenever user opens the in-app chat screen.
583+
* However, use the following API in case you need to manually reset the counter.
584+
*/
585+
@Cordova()
586+
resetMessageCounter() {
587+
return;
588+
}
475589
}

0 commit comments

Comments
 (0)