React Native SDK API Reference
HydraCore Class APIs
SignUp
static signUp(
userDetails: HydraUserDetails,
customAttributes: Record<string, any> | null = null
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
userDetails | HydraUserDetails | required | Read more about this class here |
customAttributes | Record<string, any> | optional | You can pass custom attributes that can be used for analytics |
Returns: Promise<boolean>
indicating if sign up was successfully requested
Usage:
HydraCore.signUp(userDetails, customAttributesObj)
.then((res: any) => {
console.log('HydraCore.signUp success', res);
})
.catch((err: any) => {
console.log('HydraCore.signUp error', err);
});
Sign In
static signIn(
userDetails: HydraUserDetails,
customAttributes: Record<string, any> | null = null
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
userDetails | HydraUserDetails | required | Read more about this class here |
customAttributes | Record<string, any> | optional | You can pass custom attributes that can be used for analytics |
Returns: Promise<boolean>
indicating if sign in was successfully requested
Usage:
HydraCore.signIn(userDetails, customAttributesObj)
.then((res: any) => {
console.log('HydraCore.signIn success', res);
})
.catch((err: any) => {
console.log('HydraCore.signIn error', err);
});
Update User
static updateUser(
userDetails: HydraUserDetails,
customAttributes: Record<string, any> | null = null,
subscriptions: Object[] | null = null
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
userDetails | HydraUserDetails | required | Read more about this class here |
customAttributes | Record<string, any> | optional | You can pass custom attributes that can be used for analytics |
subscriptions | Object[] | optional | List of Subscriptions which include channel, accountId, priority, type and sourcename |
Returns: Promise<boolean>
indicating if update was successfully requested
Usage:
HydraCore.updateUser(userDetails, customAttributesObj, subscriptionsObj)
.then((res: any) => {
console.log('HydraCore.updateUser', res);
})
.catch((err: any) => {
console.log('HydraCore.updateUser', err);
});
Update Geo Config
static updateGeoConfig(geoConfig: HydraGeoConfig): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
geoConfig | HydraGeoConfig | required | Read more about this class here |
Returns: Promise<boolean>
indicating if geo config update was successful
Usage:
HydraCore.updateGeoConfig(geoConfig).then((updateRequested) => {
console.log('Geo config update requested = ', updateRequested);
}).catch((err: any) => {
console.log('HydraCore.updateGeoConfig', err);
});
Sign Out
static signOut(customerId: string): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
customerId | string | required | Customer id of the user to sign out |
Returns: Promise<boolean>
indicating if sign out was successful
Usage:
HydraCore.signOut(customerId)
.then((signOutRequested) => {
console.log('Signed Out');
})
.catch((err: any) => {
console.log('HydraCore.signOut', err);
});
Update User Push Preferences
static updatePushPreferences(
customerId: string,
preferences: HydraPushPreferences
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
customerId | string | required | Customer id of the user to update push preferences |
preferences | HydraPushPreferences | required | Read more about this class here |
Returns: Promise<boolean>
indicating if preferences update was successful
Usage:
HydraCore.updatePushPreferences(customerId, pushPreferences)
.then((res: any) => {
console.log('HydraCore.updatePushPreferences success', res);
})
.catch((err: any) => {
console.log('HydraCore.updatePushPreferences error', err);
});
Report custom user events
static reportUserEvent(
eventName: string,
attributes: Record<string, any> | null = null
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
eventName | string | required | Name of the event you want to report |
attributes | Record<string, any> | optional | List of key value pairs for additional data with the event |
Returns: Promise<boolean>
indicating if event reporting was successful
Usage:
HydraCore.reportUserEvent('test_event', {
testKey: 'testValue',
})
.then((res: any) => {
console.log('HydraCore.reportUserEvent success', res);
})
.catch((err: any) => {
console.log('HydraCore.reportUserEvent error', err);
});
HydraPushNotification class APIs
Get FCM Token
static getFCMToken(): Promise<string>;
Returns: Promise<string>
containing FCM token (throws error if unavailable)
Usage:
HydraPushNotification.getFCMToken().then((token) => {
console.log('FCM Token - ', token);
}).catch((err: any) => {
console.log('HydraPushNotification.getFCMToken', err);
});
Request Permission for Push notifications
static requestPermission(): Promise<boolean>;
Returns: Promise<boolean>
indicating if permission was granted
Usage:
HydraPushNotification.requestPermission()
.then((status) => {
console.log('Notification permission status - ', status);
})
.catch((err: any) => {
console.log('HydraPushNotification.requestPermission', err);
});
HydraInbox class APIs
Get list of Hydra Notifications
static async getInboxMessages(): Promise<HydraNotification[]>;
Returns: Promise<HydraNotification[]>
Usage:
HydraInbox.getInboxMessages().then((messages) => {
if (messages.length > 0) {
console.log('Inbox message first - ', messages[0]);
} else {
console.log('No messages in inbox');
}
});
Get Unread Hydra Notifications Count
static getUnreadMessagesCount(): Promise<number>;
Returns: Promise<number>
with unread count
Usage:
HydraInbox.getUnreadMessagesCount().then((count) => {
console.log('Unread count - ', count);
});
Mark a Hydra Notification as read
static markInboxMessageAsRead(
hydraNotification: HydraNotification
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
hydraNotification | HydraNotification | required | Hydra Notification to mark as read from the list of Hydra Notification obtained here |
Returns: Promise<boolean>
indicating success
Usage:
HydraInbox.markInboxMessageAsRead(hydraNotification).then((res) => {
console.log('Marked as read - ', res);
});
Delete a Hydra Notification
static deleteInboxMessage(
hydraNotification: HydraNotification
): Promise<boolean>;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
hydraNotification | HydraNotification | required | Hydra Notification to delete from the list of Hydra Notification obtained here |
Returns: Promise<boolean>
indicating success
Usage:
HydraInbox.deleteInboxMessage(hydranotification).then((deleted) => {
console.log('Deleted message - ', deleted);
});
Delete all Hydra Notifications
static deleteAllInboxMessages(): Promise<boolean>;
Returns: Promise<boolean>
indicating success
Usage:
HydraInbox.deleteAllInboxMessages().then((deleted) => {
console.log('All messages deleted - ', deleted);
});
HydraInboxUI class APIs
Show In-Built Notification Center
static showNotificationCenter(): Promise<void>;
Usage:
HydraInboxUI.showNotificationCenter();
Hide In-Built Notification Center if Showing
static hideNotificationCenterIfShowing(): Promise<void>;
Usage:
HydraInboxUI.hideNotificationCenterIfShowing().then(() => {
console.log('Notification Center hidden');
});
HydraNativeEventEmitter class APIs
Get Singleton Instance
static getInstance(): HydraNativeEventEmitter;
Returns: Singleton Instance of HydraNativeEventEmitter to invoke all other functions of this class
Usage:
HydraNativeEventEmitter.getInstance();
Get callback for Hydra SDK initialization result
HydraNativeEventEmitter.addHydraSdkInitializationResultListener(
listener: (success: boolean, errorMessage: string | null) => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | (success: boolean, errorMessage: string | null) => void | required | A function which accepts a boolean if the initialization was successful or not, the function also has an optional string to pass errorMessage when initialization fails |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const hydraSdkIntializationResultSubscription =
HydraNativeEventEmitter.getInstance().addHydraSdkInitializationResultListener(
(result, message) => {}
);
Get callback when a new FCM token is available
HydraNativeEventEmitter.addTokenAvailableListener(
listener: (token: string) => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | (token: string) => void | required | A function which accepts a string parameter for FCM token |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const tokenAvailableSubscription =
HydraNativeEventEmitter.getInstance().addTokenAvailableListener(
(token) => {
console.log('>>> onTokenAvailable:', token);
}
);
Get callback when a Hydra Notification is received
HydraNativeEventEmitter.addHydraNotificationReceivedListener(
listener: (notification: HydraNotification) => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | (notification: HydraNotification) => void | required | A function which accepts a HydraNotification parameter for received notification |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const notificationReceivedSubscription = HydraNativeEventEmitter.getInstance().addHydraNotificationReceivedListener((notification : HydraNotification) => {
console.log('>>>>>>> Notification received >>>>>> ', notification);
});
Get a callback for notification click
HydraNativeEventEmitter.addHydraNotificationClickedListener(
listener: (notification: HydraNotification | null, cta: HydraNotificationCta) => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | (notification: HydraNotification | null, cta: HydraNotificationCta) => void | required | A function which accepts an optional HydraNotification parameter for received notification and required HydraNotificationCta parameter for CTA that was clicked |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
function onHydraNotificationClicked(
notification: HydraNotification | null,
cta: HydraNotificationCta
) {
console.log(
'>>>>>>>>> onHydraNotificationClicked',
notification, 'cta', cta);
if (cta.type === HydraNotificationCtaType.external) {
if (cta.action) {
}
} else if (cta.type === HydraNotificationCtaType.deepLink) {
console.log('DeepLink clicked', cta.action);
}
}
const notificationClickedSubscription = HydraNativeEventEmitter.getInstance().addHydraNotificationClickedListener( onHydraNotificationClicked );
Callback when Hydra Notification is Shown
HydraNativeEventEmitter.addHydraNotificationShownListener(
listener: (notification: HydraNotification) => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | (notification: HydraNotification) => void | required | A function which accepts a HydraNotification parameter for shown notification |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const notificationShownSubscription =
HydraNativeEventEmitter.getInstance().addHydraNotificationShownListener(
(notification: HydraNotification) => {
console.log('>>>>>>>>> onHydraNotificationShown', notification);
}
);
Callback when user dismisses a hydra notification
HydraNativeEventEmitter.addHydraNotificationDismissedListener(
listener: (notification: HydraNotification) => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | (notification: HydraNotification) => void | required | A function which accepts a HydraNotification parameter for dismissed notification |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const notificationDismissedSubscription = HydraNativeEventEmitter.getInstance().addHydraNotificationDismissedListener(
(notification: HydraNotification) => {
console.log('>>>>>>>>> onHydraNotificationDismissed', notification);
}
);
Callback when In-Built notification center is dismissed
HydraNativeEventEmitter.addNotificationCenterDismissedListener(
listener: () => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | () => void | required | A function without any parameters |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const notificationCenterDismissedSubscription =
HydraNativeEventEmitter.getInstance().addNotificationCenterDismissedListener(
() => {
console.log('>>>>>>> Notification center dismissed >>>>>>');
}
);
Callback when the inbox is updated
HydraNativeEventEmitter.addInboxUpdatedListener(
listener: () => void
): EmitterSubscription;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
listener | () => void | required | A function without any parameters |
Returns: subscription object of type EmitterSubscription, this should be saved if you want to remove the listener later
Usage:
const inboxUpdatedSubscription =
HydraNativeEventEmitter.getInstance().addInboxUpdatedListener(() => {
console.log('>>>>>>> Inbox updated >>>>>>');
});
Remove an added listener
HydraNativeEventEmitter.removeListener(
emitterSubscription: EmitterSubscription
): void;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
emitterSubscription | EmitterSubscription | required | Subscription returned when adding the listener |
Returns: void
Usage:
HydraNativeEventEmitter.getInstance().removeListener(
inboxUpdatedSubscription
);
HydraCore Model Classes and Enumerations
HydraUserDetails
constructor HydraUserDetails(
customerId: string,
firstName?: string | null,
lastName?: string | null,
email?: string | null,
phone?: string | null
): HydraUserDetails;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
customerId | string | required | customerId can be mobile, email, InTouchUserId, externalId or FCMToken. It depends on how your app is configured on capillary CRM dashboard in Organisation settings -> Omni Channel Settings -> Channel Configurations -> MAPP_SDK Look for Account Linking Identifier |
firstName | string | optional | First name of the user |
lastName | string | optional | Last name of the user |
string | optional | Email of the user | |
phone | string | optional | Phone number of the user |
Usage:
const userDetails = new HydraUserDetails(
'8888888888',
'FirstName',
'LastName',
'[email protected]',
'918888888888',
);
HydraGeoConfig
constructor HydraGeoConfig(
city: string,
country: string,
countryCode: string,
timezone?: string | null
): HydraGeoConfig;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
city | string | required | City of the user |
country | string | required | Country of the user |
countryCode | string | required | CountryCode for mobile number |
timezone | string | optional | User's timezone |
Usage:
const geoConfig = new HydraGeoConfig(
'Bangalore',
'India',
'IN',
'Asia/Kolkata'
);
HydraPushPreferences
constructor HydraPushPreferences(
promPushOpted: boolean,
transPushOpted: boolean
): HydraPushPreferences;
Parameters
Parameter | Type | Required/Optional | Description |
---|---|---|---|
promPushOpted | boolean | required | Enable/disable promotional push notifications |
transPushOpted | boolean | required | Enable/disable transactional push notifications |
Usage:
const pushPreferences = new HydraPushPreferences(
true,
true
);
HydraLogLevel
enum HydraLogLevel {
off = 0,
error = 1,
warn = 2,
info = 3,
debug = 4,
verbose = 5,
}
This enumeration defines the constants used to set the console and remote log levels in hydra configuration. The higher level includes all the levels below that.
HydraNotification Model Classes and Enumerations
HydraNotification Structure
class HydraNotification {
readonly cuid: string | null;
readonly scope: string | null;
readonly campaignId: string | null;
readonly variationId: string | null;
readonly senderId: string | null;
readonly senderSource: string | null;
readonly custom: string | null;
readonly customData: Record<string, any> | null;
readonly priority: string | null;
readonly validity: string | null;
readonly messageId: string | null;
readonly gateway: HydraNotificationGateway | null;
readonly body: HydraNotificationBody | null;
readonly expandableDetails: HydraNotificationExpandedDetails | null;
readonly isRead: boolean | null;
readonly imageIdentifier: string | null;
readonly accountId: string | null;
readonly channelId: string | null;
readonly payload: string | null;
readonly createdAt: Date | null;
readonly isExpanded: boolean | null;
readonly isMessageEllipsized: boolean | null;
readonly isTitleEllipsized: boolean | null;
readonly showArrow: boolean | null;
}
HydraNotificationBody
class HydraNotificationBody {
readonly title: string | null;
readonly message: string | null;
readonly cta: HydraNotificationCta | null;
readonly image: string | null;
}
HydraNotificationCta
class HydraNotificationCta {
readonly type: HydraNotificationCtaType | null;
readonly action: string | null;
readonly actionText: string | null;
}
HydraNotificationCtaType Enum
enum HydraNotificationCtaType {
external,
deepLink,
rating,
feedback,
appRating,
unknown,
}
HydraNotificationExpandedDetails
class HydraNotificationExpandedDetails {
readonly ctas: HydraNotificationCta[] | null;
readonly message: string | null;
readonly image: string | null;
readonly style: string | null;
}
HydraNotificationGateway Enum
enum HydraNotificationGateway {
fcm,
xiaomi,
unknown,
}
Updated 6 days ago