import { Injectable } from '@angular/core'; import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; import { Observable } from 'rxjs'; export type OS = 'Android' | 'iOS'; export type Gender = 'Male' | 'Female'; export type Event = | 'messageReceived' | 'notificationTapped' | 'tokenReceived' | 'registrationUpdated' | 'geofenceEntered' | 'actionTapped' | 'installationUpdated' | 'userUpdated' | 'personalized' | 'depersonalized'; export interface CustomEvent { definitionId: string; properties: Record; } export interface Configuration { /** * The application code of your Application from Push Portal website */ applicationCode: string; geofencingEnabled?: boolean; /** * Message storage save callback */ messageStorage?: string; defaultMessageStorage?: boolean; ios?: { notificationTypes?: string[]; forceCleanup?: boolean; logging?: boolean; }; android?: { notificationIcon: string; // a resource name for a status bar icon (without extension), located in '/platforms/android/app/src/main/res/mipmap' multipleNotifications: boolean; notificationAccentColor: string; }; privacySettings?: { applicationCodePersistingDisabled?: boolean; userDataPersistingDisabled?: boolean; carrierInfoSendingDisabled?: boolean; systemInfoSendingDisabled?: boolean; }; notificationCategories?: [ { identifier?: string; actions?: [ { identifier?: string; title?: string; foreground?: boolean; authenticationRequired?: boolean; moRequired?: boolean; destructive?: boolean; icon?: string; textInputActionButtonTitle?: string; textInputPlaceholder?: string; } ]; } ]; } export interface UserData { externalUserId: string; firstName?: string; lastName?: string; middleName?: string; gender?: Gender; birthday?: Date; phones?: string[]; emails?: string[]; tags?: string[]; customAttributes?: Record; } export interface Installation { isPrimaryDevice?: boolean; isPushRegistrationEnabled?: boolean; notificationsEnabled?: boolean; geoEnabled?: boolean; sdkVersion?: string; appVersion?: string; os?: OS; osVersion: string; deviceManufacturer?: string; deviceModel?: string; deviceSecure?: boolean; language?: string; deviceTimezoneId?: string; applicationUserId?: string; deviceName?: string; customAttributes?: Record; } export interface UserIdentity { phones?: string[]; emails?: string[]; externalUserId: string; } export interface PersonalizeContext { userIdentity: UserIdentity; userAttributes?: Record; forceDepersonalize?: boolean; } export interface Message { messageId: string; title?: string; body?: string; sound?: string; silent?: boolean; customPayload?: Record; internalData?: string; receivedTimestamp?: number; seenDate?: number; contentUrl?: string; seen?: boolean; geo?: boolean; originalPayload?: Record; // iOS only vibrate?: boolean; // Android only icon?: string; // Android only category?: string; // Android only } export interface MobileMessagingError { code: string; message: string; } export class DefaultMessageStorage { @Cordova({ sync: true }) find(messageId: string, callback: (message: Message) => void) { return; } @Cordova({ sync: true }) findAll(callback: (messages: Message[]) => void) { return; } @Cordova({ sync: true }) delete(messageId: string, callback: () => void) { return; } @Cordova({ sync: true }) deleteAll(callback: () => void) { return; } } /** * @name Mobile Messaging * @description * Mobile Messaging SDK is designed and developed to easily enable push notification channel in your mobile application. * In almost no time of implementation you get push notification in your application and access to the features of [Infobip IP Messaging Platform](https://portal.infobip.com/push/). * This document describes library integration steps for your Cordova project. * * For more info see [Cordova plugin docs](https://github.com/infobip/mobile-messaging-cordova-plugin) * * @usage * ```typescript * import { MobileMessaging } from '@ionic-native/mobile-messaging/ngx'; * * * constructor(private mobileMessaging: MobileMessaging) { } * * ... * * * this.mobileMessaging.init({ * applicationCode: '', * geofencingEnabled: '', * defaultMessageStorage: '', * ios: { * notificationTypes: ['alert', 'badge', 'sound'] * }, * android: { * notificationIcon: , * multipleNotifications: , * notificationAccentColor: * }}, (err) => { * ... * }); * * this.mobileMessaging.register('messageReceived').subscribe((message: Message) => { * ... * }); * * ``` */ @Plugin({ pluginName: 'MobileMessaging', plugin: 'com-infobip-plugins-mobilemessaging', pluginRef: 'MobileMessaging', repo: 'https://github.com/infobip/mobile-messaging-cordova-plugin', platforms: ['Android', 'iOS'], }) @Injectable() export class MobileMessaging extends IonicNativePlugin { /** * Starts a new Mobile Messaging session. * * @name init * @param config. Configuration for Mobile Messaging * @param {Function} onInitError. Error callback */ @Cordova({ sync: true }) init(config: Configuration, onInitError?: (error: MobileMessagingError) => void) { return; } /** * Register to event coming from MobileMessaging library. * * @name register * @param event */ @Cordova({ observable: true, }) register(event: Event): Observable { return; } @Cordova({ observable: true, }) on(event: Event): Observable { return; } /** * Un register from MobileMessaging library event. * * @name unregister * @param {String} eventName * @param {Function} handler will be unregistered from event */ @Cordova({ observable: true, }) unregister(event: Event): Observable { return; } @Cordova({ observable: true, }) off(event: Event): Observable { 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 { return; } /** * Saves user data to the server. * * @name saveUser * @param {Object} userData. An object containing user data */ @Cordova() saveUser(userData: UserData): Promise { return; } /** * Fetch user data from the server. * * @name fetchUser */ @Cordova() fetchUser(): Promise { return; } /** * Gets user data from the locally stored cache. * * @name getUser */ @Cordova() getUser(): Promise { return; } /** * Saves installation to the server. * * @name saveInstallation * @param {Object} installation. An object containing installation data */ @Cordova() saveInstallation(installation: Installation): Promise { return; } /** * Fetches installation from the server. * * @name fetchInstallation */ @Cordova() fetchInstallation(): Promise { return; } /** * Gets locally cached installation. * * @name getInstallation */ @Cordova() getInstallation(): Promise { return; } /** * Sets any installation as primary for this user. * * @name setInstallationAsPrimary * @param {String} pushRegistrationId of an installation * @param {Boolean} primary or not */ @Cordova() setInstallationAsPrimary(pushRegistrationId: string, primary: boolean): Promise { return; } /** * Performs personalization of the current installation on the platform. * * @name personalize * @param {Object} context. An object containing user identity information as well as additional user attributes. */ @Cordova() personalize(context: PersonalizeContext): Promise { return; } /** * Performs depersonalization of the current installation on the platform. * * @name depersonalize */ @Cordova() depersonalize(): Promise { return; } /** * Performs depersonalization of the installation referenced by pushRegistrationId. * * @param {String} pushRegistrationId of the remote installation to depersonalize */ @Cordova() depersonalizeInstallation(pushRegistrationId: string): Promise { return; } /** * Mark messages as seen * * @name markMessagesSeen * @param {Array} messageIds of identifiers of message to mark as seen */ @Cordova() markMessagesSeen(messageIds: string[]): Promise { return; } /** * Displays built-in error dialog so that user can resolve errors during sdk initialization. * * @name showDialogForError * @param {Number} errorCode to display dialog for */ @Cordova() showDialogForError(errorCode: number): Promise { return; } @Cordova({ sync: true }) defaultMessageStorage(): DefaultMessageStorage | undefined { return; } }