2016-07-18 02:03:03 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
2016-09-22 04:04:46 +08:00
|
|
|
import { Observable } from 'rxjs/Observable';
|
2016-07-18 02:03:03 +08:00
|
|
|
|
2016-07-08 01:19:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name OneSignal
|
|
|
|
* @description
|
|
|
|
* The OneSignal plugin is an client implementation for using the [OneSignal](https://onesignal.com/) Service.
|
|
|
|
* OneSignal is a simple implementation for delivering push notifications.
|
|
|
|
*
|
|
|
|
* Requires Cordova plugin: `onesignal-cordova-plugin`. For more info, please see the [OneSignal Cordova Docs](https://documentation.onesignal.com/docs/phonegap-sdk-installation).
|
|
|
|
*
|
|
|
|
* @usage
|
2016-07-20 23:17:09 +08:00
|
|
|
* ```typescript
|
|
|
|
* import { OneSignal } from 'ionic-native';
|
2016-07-08 01:19:00 +08:00
|
|
|
*
|
2016-10-11 16:12:43 +08:00
|
|
|
* OneSignal.startInit('b2f7f966-d8cc-11e4-bed1-df8f05be55ba', '703322744261');
|
2016-07-18 02:03:03 +08:00
|
|
|
*
|
2016-07-08 01:19:00 +08:00
|
|
|
* OneSignal.enableInAppAlertNotification(true);
|
2016-10-11 16:12:43 +08:00
|
|
|
*
|
|
|
|
* OneSignal.handleNotificationReceived().subscribe(() => {
|
|
|
|
* // do something when notification is received
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* OneSignal.handleNotificationOpened().subscribe(() => {
|
|
|
|
* // do something when a notification is opened
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* OneSignal.endInit();
|
2016-07-08 01:19:00 +08:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-07-18 02:03:03 +08:00
|
|
|
plugin: 'onesignal-cordova-plugin',
|
|
|
|
pluginRef: 'plugins.OneSignal',
|
2016-07-25 21:52:17 +08:00
|
|
|
repo: 'https://github.com/OneSignal/OneSignal-Cordova-SDK'
|
2016-07-08 01:19:00 +08:00
|
|
|
})
|
|
|
|
export class OneSignal {
|
|
|
|
|
2016-07-18 02:03:03 +08:00
|
|
|
/**
|
2016-10-11 16:12:43 +08:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
static OSInFocusDisplayOption = {
|
|
|
|
None: 0,
|
|
|
|
InAppAlert : 1,
|
|
|
|
Notification : 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the initialization process. Once you are done configuring OneSignal, call the endInit function.
|
2016-07-08 01:19:00 +08:00
|
|
|
*
|
2016-10-11 16:12:43 +08:00
|
|
|
* @param {string} appId Your AppId from your OneSignal app
|
|
|
|
* @param {string} googleProjectNumber The Google Project Number (which you can get from the Google Developer Portal) and the autoRegister option.
|
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static startInit(appId: string, googleProjectNumber: string): any { return; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to run when a notification is received
|
|
|
|
* @return {Observable<any>}
|
2016-07-08 01:19:00 +08:00
|
|
|
*/
|
2016-10-11 16:12:43 +08:00
|
|
|
@Cordova({
|
|
|
|
observable: true
|
|
|
|
})
|
|
|
|
static handleNotificationReceived(): Observable<any> { return; }
|
2016-07-08 01:19:00 +08:00
|
|
|
|
2016-10-11 16:12:43 +08:00
|
|
|
/**
|
|
|
|
* Callback to run when a notification is opened
|
|
|
|
* @return {Observable<any>}
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true
|
|
|
|
})
|
|
|
|
static handleNotificationOpened(): Observable<any> { return; }
|
2016-07-18 02:03:03 +08:00
|
|
|
|
|
|
|
/**
|
2016-10-11 16:12:43 +08:00
|
|
|
*
|
|
|
|
* @param settings
|
2016-07-18 02:03:03 +08:00
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
2016-10-11 16:12:43 +08:00
|
|
|
static iOSSettings(settings: {
|
|
|
|
kOSSettingsKeyInAppLaunchURL: boolean;
|
|
|
|
kOSSettingsKeyAutoPrompt: boolean;
|
|
|
|
}): any { return; }
|
|
|
|
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static endInit(): any { return; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a list of tags that have been set on the user from the OneSignal server.
|
|
|
|
*
|
|
|
|
* @returns {Promise} Returns a Promise that resolves when tags are recieved.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static getTags(): Promise<any> { return; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lets you retrieve the OneSignal user id and device token.
|
|
|
|
* Your handler is called after the device is successfully registered with OneSignal.
|
|
|
|
*
|
|
|
|
* @returns {Promise} Returns a Promise that reolves if the device was successfully registered.
|
|
|
|
* It returns a JSON with `userId`and `pushToken`.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static getIds(): Promise<any> { return; }
|
2016-07-18 02:03:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com/) to target these users.
|
|
|
|
* Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
|
|
|
|
*
|
2016-10-06 08:32:29 +08:00
|
|
|
* @param {string} Key of your choosing to create or update.
|
|
|
|
* @param {string} Value to set on the key. NOTE: Passing in a blank String deletes the key, you can also call deleteTag.
|
2016-07-18 02:03:03 +08:00
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static sendTag(key: string, value: string): void { }
|
|
|
|
|
|
|
|
/**
|
2016-10-11 16:12:43 +08:00
|
|
|
* Tag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com/) to target these users.
|
|
|
|
* Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
|
|
|
|
*
|
|
|
|
* @param {string} Pass a json object with key/value pairs like: {key: "value", key2: "value2"}
|
|
|
|
*/
|
2016-07-18 02:03:03 +08:00
|
|
|
@Cordova({ sync: true })
|
|
|
|
static sendTags(json: any): void { }
|
|
|
|
|
|
|
|
/**
|
2016-10-11 16:12:43 +08:00
|
|
|
* Deletes a tag that was previously set on a user with `sendTag` or `sendTags`. Use `deleteTags` if you need to delete more than one.
|
|
|
|
*
|
|
|
|
* @param {string} Key to remove.
|
|
|
|
*/
|
2016-07-18 02:03:03 +08:00
|
|
|
@Cordova({ sync: true })
|
|
|
|
static deleteTag(key: string): void { }
|
|
|
|
|
|
|
|
/**
|
2016-10-11 16:12:43 +08:00
|
|
|
* Deletes tags that were previously set on a user with `sendTag` or `sendTags`.
|
|
|
|
*
|
|
|
|
* @param {Array<string>} Keys to remove.
|
|
|
|
*/
|
2016-07-18 02:03:03 +08:00
|
|
|
@Cordova({ sync: true })
|
|
|
|
static deleteTags(keys: string[]): void { }
|
|
|
|
|
|
|
|
/**
|
2016-10-11 16:12:43 +08:00
|
|
|
* Call this when you would like to prompt an iOS user to accept push notifications with the default system prompt.
|
|
|
|
* Only use if you passed false to autoRegister when calling init.
|
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static registerForPushNotifications(): void { }
|
2016-07-18 02:03:03 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Warning:
|
|
|
|
* Only applies to Android and Amazon. You can call this from your UI from a button press for example to give your user's options for your notifications.
|
|
|
|
*
|
|
|
|
* By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode.
|
|
|
|
* Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
|
|
|
|
*
|
2016-10-06 08:32:29 +08:00
|
|
|
* @param {boolean} false to disable vibrate, true to re-enable it.
|
2016-07-18 02:03:03 +08:00
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static enableVibrate(enable: boolean): void { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warning:
|
|
|
|
* Only applies to Android and Amazon. You can call this from your UI from a button press for example to give your user's options for your notifications.
|
|
|
|
*
|
|
|
|
* By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on.
|
|
|
|
* Passing false means that the device will only vibrate unless the device is set to a total silent mode.
|
|
|
|
*
|
2016-10-06 08:32:29 +08:00
|
|
|
* @param {boolean} false to disable sound, true to re-enable it.
|
2016-07-18 02:03:03 +08:00
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static enableSound(enable: boolean): void { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warning:
|
|
|
|
* Only applies to Android and Amazon devices.
|
|
|
|
*
|
|
|
|
* By default this is false and notifications will not be shown when the user is in your app, instead the notificationOpenedCallback is fired.
|
|
|
|
* If set to true notifications will always show in the notification area and notificationOpenedCallback will not fire until the user taps on the notification.
|
|
|
|
*
|
2016-10-06 08:32:29 +08:00
|
|
|
* @param {boolean} enable
|
2016-07-18 02:03:03 +08:00
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static enableNotificationsWhenActive(enable: boolean): void { }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* You can call this method with false to opt users out of receiving all notifications through OneSignal.
|
|
|
|
* You can pass true later to opt users back into notifications.
|
|
|
|
*
|
2016-10-06 08:32:29 +08:00
|
|
|
* @param {boolean} enable
|
2016-07-18 02:03:03 +08:00
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static setSubscription(enable: boolean): void { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {notificationObj} Parameters see POST [documentation](https://documentation.onesignal.com/v2.0/docs/notifications-create-notification)
|
|
|
|
* @returns {Promise} Returns a Promise that resolves if the notification was send successfully.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-10-11 08:10:14 +08:00
|
|
|
static postNotification(notificationObj: OneSignalNotification): Promise<any> { return; }
|
2016-07-18 02:03:03 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prompts the user for location permission to allow geotagging based on the "Location radius" filter on the OneSignal dashboard.
|
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static promptLocation(): void { }
|
|
|
|
|
2016-10-11 16:12:43 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param email {string}
|
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static syncHashedEmail(email: string): void { }
|
|
|
|
|
2016-07-18 02:03:03 +08:00
|
|
|
/**
|
|
|
|
* Enable logging to help debug if you run into an issue setting up OneSignal.
|
|
|
|
* The logging levels are as follows: 0 = None, 1= Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose
|
|
|
|
|
|
|
|
* The higher the value the more information is shown.
|
|
|
|
*
|
|
|
|
* @param {loglevel} contains two properties: logLevel (for console logging) and visualLevel (for dialog messages)
|
|
|
|
*/
|
|
|
|
@Cordova({ sync: true })
|
|
|
|
static setLogLevel(logLevel: {
|
|
|
|
logLevel: number,
|
|
|
|
visualLevel: number
|
|
|
|
}): void { }
|
|
|
|
|
2016-08-23 06:19:43 +08:00
|
|
|
}
|
2016-10-11 08:10:14 +08:00
|
|
|
|
|
|
|
export interface OneSignalNotification {
|
|
|
|
app_id: string;
|
|
|
|
contents: any;
|
|
|
|
headings?: any;
|
|
|
|
isIos?: boolean;
|
|
|
|
isAndroid?: boolean;
|
|
|
|
isWP?: boolean;
|
|
|
|
isWP_WNS?: boolean;
|
|
|
|
isAdm?: boolean;
|
|
|
|
isChrome?: boolean;
|
|
|
|
isChromeWeb?: boolean;
|
|
|
|
isSafari?: boolean;
|
|
|
|
isAnyWeb?: boolean;
|
|
|
|
included_segments?: string[];
|
|
|
|
excluded_segments?: string[];
|
|
|
|
include_player_ids?: string[];
|
|
|
|
include_ios_tokens?: string[];
|
|
|
|
include_android_reg_ids?: string[];
|
|
|
|
include_wp_uris?: string[];
|
|
|
|
include_wp_wns_uris?: string[];
|
|
|
|
include_amazon_reg_ids?: string[];
|
|
|
|
include_chrome_reg_ids?: string[];
|
|
|
|
include_chrome_web_reg_ids?: string[];
|
|
|
|
app_ids?: string[];
|
|
|
|
tags?: any[];
|
|
|
|
ios_badgeType?: string;
|
|
|
|
ios_badgeCount?: number;
|
|
|
|
ios_sound?: string;
|
|
|
|
android_sound?: string;
|
|
|
|
adm_sound?: string;
|
|
|
|
wp_sound?: string;
|
|
|
|
wp_wns_sound?: string;
|
|
|
|
data?: any;
|
|
|
|
buttons?: any;
|
|
|
|
small_icon?: string;
|
|
|
|
large_icon?: string;
|
|
|
|
big_picture?: string;
|
|
|
|
adm_small_icon?: string;
|
|
|
|
adm_large_icon?: string;
|
|
|
|
adm_big_picture?: string;
|
|
|
|
chrome_icon?: string;
|
|
|
|
chrome_big_picture?: string;
|
|
|
|
chrome_web_icon?: string;
|
|
|
|
firefox_icon?: string;
|
|
|
|
url?: string;
|
|
|
|
send_after?: string;
|
|
|
|
delayed_option?: string;
|
|
|
|
delivery_time_of_day?: string;
|
|
|
|
android_led_color?: string;
|
|
|
|
android_accent_color?: string;
|
|
|
|
android_visibility?: number;
|
|
|
|
content_available?: boolean;
|
|
|
|
amazon_background_data?: boolean;
|
|
|
|
template_id?: string;
|
|
|
|
android_group?: string;
|
|
|
|
android_group_message?: any;
|
|
|
|
adm_group?: string;
|
|
|
|
adm_group_message?: any;
|
|
|
|
ttl?: number;
|
|
|
|
priority?: number;
|
2016-10-11 16:12:32 +08:00
|
|
|
ios_category?: string;
|
2016-10-11 08:10:14 +08:00
|
|
|
}
|