UNPKG

15.7 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2export interface OSNotification {
3 /**
4 * Was app in focus.
5 */
6 isAppInFocus: boolean;
7 /**
8 * Was notification shown to the user. Will be false for silent notifications.
9 */
10 shown: boolean;
11 /**
12 * **ANDROID** - Android Notification assigned to the notification. Can be used to cancel or replace the notification.
13 */
14 androidNotificationId?: number;
15 /**
16 * Payload received from OneSignal.
17 */
18 payload: OSNotificationPayload;
19 /**
20 * How the notification was displayed to the user. Can be set to `Notification`, `InAppAlert`, or `None` if it was not displayed.
21 */
22 displayType: OSDisplayType;
23 /**
24 * **ANDROID** - Notification is a summary notification for a group this will contain all notification payloads it was created from.
25 */
26 groupedNotifications?: OSNotificationPayload[];
27 app_id?: string;
28 contents: any;
29 headings?: any;
30 isIos?: boolean;
31 isAndroid?: boolean;
32 isWP?: boolean;
33 isWP_WNS?: boolean;
34 isAdm?: boolean;
35 isChrome?: boolean;
36 isChromeWeb?: boolean;
37 isSafari?: boolean;
38 isAnyWeb?: boolean;
39 included_segments?: string[];
40 excluded_segments?: string[];
41 include_player_ids?: string[];
42 include_ios_tokens?: string[];
43 include_android_reg_ids?: string[];
44 include_wp_uris?: string[];
45 include_wp_wns_uris?: string[];
46 include_amazon_reg_ids?: string[];
47 include_chrome_reg_ids?: string[];
48 include_chrome_web_reg_ids?: string[];
49 app_ids?: string[];
50 tags?: any[];
51 ios_badgeType?: string;
52 ios_badgeCount?: number;
53 ios_sound?: string;
54 android_sound?: string;
55 adm_sound?: string;
56 wp_sound?: string;
57 wp_wns_sound?: string;
58 data?: any;
59 buttons?: any;
60 small_icon?: string;
61 large_icon?: string;
62 big_picture?: string;
63 adm_small_icon?: string;
64 adm_large_icon?: string;
65 adm_big_picture?: string;
66 chrome_icon?: string;
67 chrome_big_picture?: string;
68 chrome_web_icon?: string;
69 firefox_icon?: string;
70 url?: string;
71 send_after?: string;
72 delayed_option?: string;
73 delivery_time_of_day?: string;
74 android_led_color?: string;
75 android_accent_color?: string;
76 android_visibility?: number;
77 content_available?: boolean;
78 amazon_background_data?: boolean;
79 template_id?: string;
80 android_group?: string;
81 android_group_message?: any;
82 adm_group?: string;
83 adm_group_message?: any;
84 ttl?: number;
85 priority?: number;
86 ios_category?: string;
87}
88/**
89 * **ANDROID** - Privacy setting for how the notification should be shown on the lockscreen of Android 5+ devices.
90 */
91export declare enum OSLockScreenVisibility {
92 /**
93 * Fully visible (default)
94 */
95 Public = 1,
96 /**
97 * Contents are hidden
98 */
99 Private = 0,
100 /**
101 * Not shown
102 */
103 Secret = -1,
104}
105/**
106 * How the notification was displayed to the user. Part of OSNotification. See inFocusDisplaying for more information on how this is used.
107 */
108export declare enum OSDisplayType {
109 /**
110 * notification is silent, or inFocusDisplaying is disabled.
111 */
112 None = 0,
113 /**
114 * (**DEFAULT**) - native alert dialog display.
115 */
116 InAppAlert = 1,
117 /**
118 * native notification display.
119 */
120 Notification = 2,
121}
122/**
123 * Contents and settings of the notification the user received.
124 */
125export interface OSNotificationPayload {
126 /**
127 * OneSignal notification UUID.
128 */
129 notificationID: string;
130 /**
131 * Title of the notification.
132 */
133 title: string;
134 /**
135 * Body of the notification.
136 */
137 body: string;
138 /**
139 * Custom additional data that was sent with the notification. Set on the dashboard under Options > Additional Data
140 * or with the 'data' field on the REST API.
141 */
142 additionalData?: any;
143 /**
144 * **ANDROID** - Small icon resource name set on the notification.
145 */
146 smallIcon?: string;
147 /**
148 * **ANDROID** - Large icon set on the notification.
149 */
150 largeIcon?: string;
151 /**
152 * **ANDROID** - Big picture image set on the notification.
153 */
154 bigPicture?: string;
155 /**
156 * **ANDROID** - Accent color shown around small notification icon on Android 5+ devices. ARGB format.
157 */
158 smallIconAccentColor?: string;
159 /**
160 * URL to open when opening the notification.
161 */
162 launchUrl?: string;
163 /**
164 * Sound resource to play when the notification is shown.
165 */
166 sound: string;
167 /**
168 * **ANDROID** - Devices that have a notification LED will blink in this color. ARGB format.
169 */
170 ledColor?: string;
171 lockScreenVisibility?: OSLockScreenVisibility;
172 /**
173 * **ANDROID** - Notifications with this same key will be grouped together as a single summary notification.
174 */
175 groupKey?: string;
176 /**
177 * **ANDROID** - Summary text displayed in the summary notification.
178 */
179 groupMessage?: string;
180 /**
181 * List of action buttons on the notification.
182 */
183 actionButtons: OSActionButton[];
184 /**
185 * **ANDROID** - The Google project number the notification was sent under.
186 */
187 fromProjectNumber?: string;
188 /**
189 * **ANDROID** - If a background image was set this object will be available.
190 */
191 backgroundImageLayout?: OSBackgroundImageLayout;
192 priority?: number;
193 /**
194 * List of action buttons on the notification.
195 */
196 rawPayload: string;
197}
198/**
199 * List of action buttons on the notification.
200 */
201export interface OSActionButton {
202 /**
203 * Id assigned to the button.
204 */
205 id: string;
206 /**
207 * Text show on the button to the user.
208 */
209 text: string;
210 /**
211 * **ANDROID** - Icon shown on the button.
212 */
213 icon: string;
214}
215/**
216 * **ANDROID** - If a background image was set, this object will be available.
217 */
218export interface OSBackgroundImageLayout {
219 /**
220 * Image URL or name used as the background image.
221 */
222 image: string;
223 /**
224 * Text color of the title on the notification. ARGB Format.
225 */
226 titleTextColor: string;
227 /**
228 * Text color of the body on the notification. ARGB Format.
229 */
230 bodyTextColor: string;
231}
232/**
233 * The information returned from a notification the user received.
234 */
235export interface OSNotificationOpenedResult {
236 action: {
237 /**
238 * Was the notification opened normally (`Opened`) or was a button pressed on the notification (`ActionTaken`).
239 */
240 type: OSActionType;
241 /**
242 * If `type` == `ActionTaken` then this will contain the id of the button pressed.
243 */
244 actionID?: string;
245 };
246 notification: OSNotification;
247}
248export declare enum OSActionType {
249 Opened = 0,
250 ActionTake = 1,
251}
252/**
253 * @name OneSignal
254 * @description
255 * The OneSignal plugin is an client implementation for using the [OneSignal](https://onesignal.com/) Service.
256 * OneSignal is a simple implementation for delivering push notifications.
257 *
258 * Requires Cordova plugin: `onesignal-cordova-plugin`. For more info, please see the [OneSignal Cordova Docs](https://documentation.onesignal.com/docs/phonegap-sdk-installation).
259 *
260 * @usage
261 * ```typescript
262 * import { OneSignal } from 'ionic-native';
263 *
264 * OneSignal.startInit('b2f7f966-d8cc-11e4-bed1-df8f05be55ba', '703322744261');
265 *
266 * OneSignal.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.InAppAlert);
267 *
268 * OneSignal.handleNotificationReceived().subscribe(() => {
269 * // do something when notification is received
270 * });
271 *
272 * OneSignal.handleNotificationOpened().subscribe(() => {
273 * // do something when a notification is opened
274 * });
275 *
276 * OneSignal.endInit();
277 * ```
278 * @interfaces
279 * OSNotification
280 * OSLockScreenVisibility
281 * OSDisplayType
282 * OSNotificationPayload
283 * OSActionButton
284 * OSBackgroundImageLayout
285 * OSNotificationOpenedResult
286 * OSActionType
287 */
288export declare class OneSignal {
289 /**
290 * constants to use in inFocusDisplaying()
291 */
292 static OSInFocusDisplayOption: {
293 None: number;
294 InAppAlert: number;
295 Notification: number;
296 };
297 /**
298 * Start the initialization process. Once you are done configuring OneSignal, call the `endInit` function.
299 *
300 * @param {string} appId Your OneSignal app id
301 * @param {string} googleProjectNumber **ANDROID** - your Google project number; only required for Android GCM/FCM pushes.
302 * @returns {any}
303 */
304 static startInit(appId: string, googleProjectNumber?: string): any;
305 /**
306 * Callback to run when a notification is received, whether it was displayed or not.
307 *
308 * @return {Observable<OneSignalReceivedNotification>}
309 */
310 static handleNotificationReceived(): Observable<OSNotification>;
311 /**
312 * Callback to run when a notification is tapped on from the notification shade (**ANDROID**) or notification
313 * center (**iOS**), or when closing an Alert notification shown in the app (if InAppAlert is enabled in
314 * inFocusDisplaying).
315 *
316 * @return {Observable<OneSignalOpenedNotification>}
317 */
318 static handleNotificationOpened(): Observable<OSNotificationOpenedResult>;
319 /**
320 * **iOS** - Settings for iOS apps
321 *
322 * @param settings
323 * kOSSettingsKeyAutoPrompt: boolean = true
324 * Auto prompt user for notification permissions.
325 *
326 * kOSSettingsKeyInAppLaunchURL: boolean = false
327 * Launch notifications with a launch URL as an in app webview.
328 * @returns {any}
329 */
330 static iOSSettings(settings: {
331 kOSSettingsKeyAutoPrompt: boolean;
332 kOSSettingsKeyInAppLaunchURL: boolean;
333 }): any;
334 /**
335 * Must be called after `startInit` to complete initialization of OneSignal.
336 *
337 * @returns {any}
338 */
339 static endInit(): any;
340 /**
341 * Retrieve a list of tags that have been set on the user from the OneSignal server.
342 *
343 * @returns {Promise<any>} Returns a Promise that resolves when tags are recieved.
344 */
345 static getTags(): Promise<any>;
346 /**
347 * Lets you retrieve the OneSignal user id and device token.
348 * Your handler is called after the device is successfully registered with OneSignal.
349 *
350 * @returns {Promise<Object>} Returns a Promise that resolves if the device was successfully registered.
351 *
352 * userId {string} OneSignal userId is a UUID formatted string. (unique per device per app)
353 *
354 * pushToken {string} A push token is a Google/Apple assigned identifier(unique per device per app).
355 */
356 static getIds(): Promise<{
357 userId: string;
358 pushToken: string;
359 }>;
360 /**
361 * 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.
362 * Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
363 *
364 * @param {string} Key of your choosing to create or update.
365 * @param {string} Value to set on the key. NOTE: Passing in a blank String deletes the key, you can also call deleteTag.
366 */
367 static sendTag(key: string, value: string): void;
368 /**
369 * 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.
370 * Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
371 *
372 * @param {string} Pass a json object with key/value pairs like: {key: "value", key2: "value2"}
373 */
374 static sendTags(json: any): void;
375 /**
376 * Deletes a tag that was previously set on a user with `sendTag` or `sendTags`. Use `deleteTags` if you need to delete more than one.
377 *
378 * @param {string} Key to remove.
379 */
380 static deleteTag(key: string): void;
381 /**
382 * Deletes tags that were previously set on a user with `sendTag` or `sendTags`.
383 *
384 * @param {Array<string>} Keys to remove.
385 */
386 static deleteTags(keys: string[]): void;
387 /**
388 * Call this when you would like to prompt an iOS user to accept push notifications with the default system prompt.
389 * Only works if you set `kOSSettingsAutoPrompt` to `false` in `iOSSettings`
390 */
391 static registerForPushNotifications(): void;
392 /**
393 * Warning:
394 * 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.
395 *
396 * By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode.
397 * Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
398 *
399 * @param {boolean} false to disable vibrate, true to re-enable it.
400 */
401 static enableVibrate(enable: boolean): void;
402 /**
403 * Warning:
404 * 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.
405 *
406 * By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on.
407 * Passing false means that the device will only vibrate unless the device is set to a total silent mode.
408 *
409 * @param {boolean} false to disable sound, true to re-enable it.
410 */
411 static enableSound(enable: boolean): void;
412 /**
413 *
414 * Setting to control how OneSignal notifications will be shown when one is received while your app is in focus. By default this is set to inAppAlert, which can be helpful during development.
415 *
416 * @param {DisplayType} displayOption
417 * @returns {any}
418 */
419 static inFocusDisplaying(displayOption: OSDisplayType): any;
420 /**
421 * You can call this method with false to opt users out of receiving all notifications through OneSignal.
422 * You can pass true later to opt users back into notifications.
423 *
424 * @param {boolean} enable
425 */
426 static setSubscription(enable: boolean): void;
427 /**
428 *
429 * @param {notificationObj} Parameters see POST [documentation](https://documentation.onesignal.com/v2.0/docs/notifications-create-notification)
430 * @returns {Promise<any>} Returns a Promise that resolves if the notification was send successfully.
431 */
432 static postNotification(notificationObj: OSNotification): Promise<any>;
433 /**
434 * Prompts the user for location permission to allow geotagging based on the "Location radius" filter on the OneSignal dashboard.
435 */
436 static promptLocation(): void;
437 /**
438 *
439 * @param email {string}
440 */
441 static syncHashedEmail(email: string): void;
442 /**
443 * Enable logging to help debug if you run into an issue setting up OneSignal.
444 * The logging levels are as follows: 0 = None, 1= Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose
445
446 * The higher the value the more information is shown.
447 *
448 * @param {loglevel} contains two properties: logLevel (for console logging) and visualLevel (for dialog messages)
449 */
450 static setLogLevel(logLevel: {
451 logLevel: number;
452 visualLevel: number;
453 }): void;
454}