From 3af9c48f05d81050c9794da09f720587ebc40f65 Mon Sep 17 00:00:00 2001 From: Konstantin <camoroh13@gmail.com> Date: Thu, 9 Apr 2020 14:34:19 +0300 Subject: [PATCH] feat(MobileMessaging): add support for CustomEvents (#3373) * feat(MobileMessaging): add methods for CustomEvents support * fix(MobileMessaging) change customAttributes type * fix(MobileMessaging): change methods return type Co-authored-by: Konstantin Latypov <Konstantin.Latypov@infobip.com> --- .../plugins/mobile-messaging/index.ts | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/@ionic-native/plugins/mobile-messaging/index.ts b/src/@ionic-native/plugins/mobile-messaging/index.ts index a0b14b3b7..13a53e8e5 100644 --- a/src/@ionic-native/plugins/mobile-messaging/index.ts +++ b/src/@ionic-native/plugins/mobile-messaging/index.ts @@ -16,6 +16,11 @@ export type Event = | 'personalized' | 'depersonalized'; +export interface CustomEvent { + definitionId: string; + properties: Record<string, string | number | boolean>; +} + export interface Configuration { /** * The application code of your Application from Push Portal website @@ -73,7 +78,7 @@ export interface UserData { phones?: string[]; emails?: string[]; tags?: string[]; - customAttributes?: Record<string, string>; + customAttributes?: Record<string, string | number | boolean>; } export interface Installation { @@ -92,7 +97,7 @@ export interface Installation { deviceTimezoneId?: string; applicationUserId?: string; deviceName?: string; - customAttributes?: Record<string, string>; + customAttributes?: Record<string, string | number | boolean>; } export interface UserIdentity { @@ -258,6 +263,53 @@ export class MobileMessaging extends IonicNativePlugin { return; } + /** + * Sends an event to the server eventually, handles possible errors and do retries for you. + * + * @name submitEvent + * @param {Object} eventData. An object containing event data + * { + * definitionId: "eventDefinitionId" + * properties: { + * "stringAttribute": "string", + * "numberAttribute": 1, + * "dateAttribute": "2020-02-26T09:41:57Z", + * "booleanAttribute": true + * } + * } + */ + @Cordova({ + sync: true + }) + submitEvent(event: CustomEvent): void { + return; + } + + + /** + * Sends an event to the server immediately. + * You have to handle possible connection or server errors, do retries yourself. + * + * @name submitEventImmediately + * @param {Object} eventData. An object containing event data + * { + * definitionId: "eventDefinitionId" + * properties: { + * "stringAttribute": "string", + * "numberAttribute": 1, + * "dateAttribute": "2020-02-26T09:41:57Z", + * "booleanAttribute": true + * } + * } + * @param {Function} callback will be called on result, you have to handle error and do retries yourself + */ + @Cordova({ + observable: true + }) + submitEventImmediately(event: CustomEvent): Promise<void> { + return; + } + /** * Saves user data to the server. *