import { Injectable } from '@angular/core'; import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; import { Observable } from 'rxjs'; export interface DeviceResponse { device_id?: string; } export interface DeviceInfoResponse extends DeviceResponse { push_token?: string; } export interface PersonResponse { person_key?: string; mdn?: string; external_person_id?: string; } export interface InboxMessage { content?: string; created_at?: string; expires_at?: string; message_uid?: string; read?: boolean; subject?: string; detail?: string; collapse_key?: string; apprefdata?: any; images?: any; inbox_custom_data: any; } /** * @name Vibes * @description * This plugin enables integration with the Vibes Push SDK to your Cordova project with Android and iOS supported. * * @usage * ```typescript * import { Vibes } from '@ionic-native/vibes/ngx'; * * * constructor(private vibes: Vibes) { } * * ... * * * this.vibes.registerDevice() * .then((res: any) => console.log(`device registration success: ${res}`)) // retrieve and save the device_id from `res` JSON object * .catch((error: any) => console.error('Error registering device', error)); * * this.vibes.registerPush() * .then((res: any) => console.log(res)) * .catch((error: any) => console.error('Error registering push', error)); * * this.vibes.getVibesDeviceInfo() * .then((res: any) => console.log(res)) // retrieve the `device_id` and `push_token` from the JSON object * .catch((error: any) => console.error('Error retrieving deviceinfo', error)); * * this.vibes.fetchInboxMessages() * .then((res: any) => console.log(res)) // fetches inbox messages for this person. * .catch((error: any) => console.error('Error fetching inbox messages for this person', error)); * ``` */ @Plugin({ pluginName: 'Vibes', plugin: 'vibes-cordova', pluginRef: 'Vibes', repo: 'https://github.com/vibes/vibes-cordova.git', install: 'ionic cordova plugin add vibes-cordova --variable VIBES_APP_ID=MY_APP_ID --variable VIBES_API_URL=MY_ENVIRONMENT_URL', installVariables: ['VIBES_APP_ID', 'VIBES_API_URL'], platforms: ['Android', 'iOS'], }) @Injectable() export class Vibes extends IonicNativePlugin { /** * Register this device with the Vibes platform * * @return {Promise} */ @Cordova() registerDevice(): Promise { return; } /** * Unregister this device with the Vibes platform * * @return {Promise} */ @Cordova() unregisterDevice(): Promise { return; } /** * Associate an external ID with the current person. * * @param {string} externalPersonId * @return {Promise} */ @Cordova() associatePerson(externalPersonId: string): Promise { return; } /** * Register this device to receive push notifications * * @return {Promise} */ @Cordova() registerPush(): Promise { return; } /** * Unregister the device from receiving push notifications * * @return {Promise} */ @Cordova() unregisterPush(): Promise { return; } /** * Fetches a DeviceInfoResponse with details about the Vibes Device ID and Push Token * * @return {Promise} */ @Cordova() getVibesDeviceInfo(): Promise { return; } /** * Fetches the PersonResponse associated with this device currently * * @return {Promise} */ @Cordova() getPerson(): Promise { return; } /** * Get notified when the user opens a notification * * @return {Observable} */ @Cordova({ observable: true, }) onNotificationOpened(): Observable { return; } /** * Fetches an array of inbox messages for the person associated with this device. * * @return {Promise} */ @Cordova() fetchInboxMessages(): Promise { return; } /** * Fetches a single inbox message by it's id. * * @param {string} message_uid * @return {Promise} */ @Cordova() fetchInboxMessage(message_uid: string): Promise { return; } /** * Marks an inbox message as expired using message_uid and the expiry date supplied. Uses current date if null or invalid date is supplied. * * @param {string} message_uid * @param {string} An ISO-8601 formatted date string. * @return {Promise} an updated version of the InboxMessage with expires_at date updated */ @Cordova() expireInboxMessage(message_uid: string, date: string): Promise { return; } /** * Marks an inbox message as read. * * @param {string} message_uid * @return {Promise} an updated version of the InboxMessage with read field updated */ @Cordova() markInboxMessageAsRead(message_uid: string): Promise { return; } /** * Records an event for when the user opens an inbox message. * * @param inbox_message_stringified stringified version of the InboxMessage * @return {Promise} */ @Cordova() onInboxMessageOpen(inbox_message_stringified: string): Promise { return; } }