Skip to main content

Helpshift Delegates

The Helpshift SDK provides delegate callbacks to help app developers track a user's activities within the help section.

Helpshift Delegate implementation

  • To use Helpshift Delegate please import helpshiftEmitter
  • To use Helpshift Delegate constants please import helpshiftConstants

For example:

import { helpshiftEmitter , helpshiftConstants } from "helpshift-plugin-sdkx-react-native";
Note

helpshiftConstants is available from SDK X 10.3.1 onwards. For older SDK X versions, please use the raw keys instead.

To handle helpshift events, you can use following listener.

const handleCallbacks = () => {
helpshiftEmitter.addListener("onEventOccurred", (data) => {
//handle helpshift events using data.eventname
});
helpshiftEmitter.addListener("onUserAuthenticationFailure", (data) => {
//your code here
});
};

We need add a listener with helpshiftEmitter for "onEventOccurred" and "onUserAuthenticationFailure".

Events

Helpshift session started event

This event gets fired when the Helpshift session starts

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "helpshiftSessionStarted") {
//Your code here.
}
});

Helpshift session ended event

This event gets fired when the Helpshift session ends.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "helpshiftSessionEnded") {
//Your code here.
}
});

Unread Message Count Event

If you want a count of all new messages received in an existing conversation, you can call this API requestUnreadMessageCount(shouldFetchFromServer: boolean). The count of the number of messages will be conveyed to your app via this event.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "receivedUnreadMessageCount") {
try {
let countData =
Platform.OS == "ios" ? data.eventData : JSON.parse(data.eventData);
console.log(countData.count);
} catch (err) {
console.error("Parsing Error", err);
}
}
});

Conversation Status Event

This event contains information about the current ongoing conversation.

helpshiftEmitter.addListener('onEventOccurred', (data) => {
if (data.eventName == 'conversationStatus') {
try {
let eventData =
Platform.OS == 'ios' ? data.eventData : JSON.parse(data.eventData);
if(eventData.hasOwnProperty('latestIssueId')){
console.log(eventData.latestIssueId);
}
if(eventData.hasOwnProperty('latestIssuePublishId'){
console.log(eventData.latestIssuePublishId);
}
if(eventData.hasOwnProperty('open'){
console.log(eventData.open);
}
} catch (err) {
console.error('Parsing Error', err);
}
}
});

Widget Toggle Event

This event is triggered when the user opens or exits the chat screen. This event is triggered with a boolean value of "visible" key. For your reference, see the below example:

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "widgetToggle") {
try {
let eventData =
Platform.OS == "ios" ? data.eventData : JSON.parse(data.eventData);
if (eventData.hasOwnProperty("visible")) {
console.log(eventData.visible);
}
} catch (err) {
console.error("Parsing Error", err);
}
}
});

User Click On Action Event

This event is triggered when the user clicks on the link or call action of an action card message.

  • Event Name : helpshiftConstants.HELPSHIFT_EVENT_NAME_USER_CLICK_ON_ACTION
  • Event data:
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_DATA
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPE
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPE_CALL
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPE_LINK
Key (Constant)Key (Raw)Type
helpshiftConstants.HELPSHIFT_EVENT_NAME_USER_CLICK_ON_ACTIONuserClickOnActionstring
helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPEactionTypestring
helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_DATAactionDatastring
helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPE_CALLcallstring
helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPE_LINKlinkstring
Note

The key constants are available from SDK X 10.3.1 onwards. For older SDK X versions, please use the raw keys instead.

helpshiftEmitter.addListener(
helpshiftConstants.HANDLE_HELPSHIFT_EVENT,
(data) => {
if (data.eventName == helpshiftConstants.HELPSHIFT_EVENT_NAME_USER_CLICK_ON_ACTION) {
try {
let eventActionType =
eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_TYPE];
let eventActionData =
eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_ACTION_DATA];

console.log('Event Receivd for ' + data.eventName + ' action type : ' + eventActionType + ' action data ' + eventActionData );
} catch (err) {
console.error('Parsing Error', err);
}
}
}
);

Conversation Start Event

This event triggers when the user sends the first message in a conversation. The event data object has a key, message, which includes the message string the end-user sent to start the conversation. For your reference, see the below example.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "conversationStart") {
try {
let eventData =
Platform.OS == "ios" ? data.eventData : JSON.parse(data.eventData);
if (eventData.hasOwnProperty("message")) {
console.log(eventData.message);
}
} catch (err) {
console.error("Parsing Error", err);
}
}
});

Message Add Event

This event is triggered when the user adds a message to a conversation. It might be a text message, a response via bot input, or an attachment. The event data object has the type and body keys, which indicate the type and body of the message added by the user. For your reference, see the below example.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "messageAdd") {
try {
let eventData =
Platform.OS == "ios" ? data.eventData : JSON.parse(data.eventData);
if (eventData.hasOwnProperty("body")) {
console.log(eventData.body);
}
if (eventData.hasOwnProperty("type")) {
console.log(eventData.type);
}
} catch (err) {
console.error("Parsing Error", err);
}
}
});

Agent Message Received Event

This event is triggered when the user receives any message from an agent in a conversation. This delegate is not triggered for bot messages or messages sent via automations.

  • Event name : helpshiftConstants.HELPSHIFT_EVENT_NAME_AGENT_MESSAGE_RECEIVED

  • Event data:

    KeyTypeValue
    helpshiftConstants.HELPSHIFT_EVENT_DATA_PUBLISH_IDstringConversation ID of the ongoing issue
    helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_TYPEstringMessage Type of the message
    helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_BODYstringThe actual message sent by the agent or empty
    helpshiftConstants.HELPSHIFT_EVENT_DATA_CREATED_TIMEnumberUnix epoch timestamp in ms
    helpshiftConstants.HELPSHIFT_EVENT_DATA_ATTACHMENTSobjectAttachments, if they are present
    helpshiftConstants.HELPSHIFT_EVENT_DATA_URLstringURL of the attachment
    helpshiftConstants.HELPSHIFT_EVENT_DATA_CONTENT_TYPEstringMIME type of the attachment
    helpshiftConstants.HELPSHIFT_EVENT_DATA_FILE_NAMEstringFile name of the attachment
    helpshiftConstants.HELPSHIFT_EVENT_DATA_SIZEnumberSize of the attachment in bytes
Note
  • This delegate is available from 10.3.1 and above versions
  • The attachments key is only present if the agent has sent attachments.
  • Since attachments sent by agents may not have the necessary MIME type or name, it is possible that helpshiftConstants.HELPSHIFT_EVENT_DATA_CONTENT_TYPE is absent from the payload. For such cases, file type can be inferred from extension from file name
  • helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_TYPE has following types :
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_TYPE_APP_REVIEW_REQUEST
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_TYPE_SCREENSHOT_REQUEST
    • helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_TYPE_TEXT
helpshiftEmitter.addListener(
helpshiftConstants.HANDLE_HELPSHIFT_EVENT,
(data) => {
if (data.eventName == helpshiftConstants.HELPSHIFT_EVENT_NAME_AGENT_MESSAGE_RECEIVED) {
try {
let publishId = eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_PUBLISH_ID];
let type = eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_TYPE];
let body = eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_MESSAGE_BODY];
let createdTs = eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_CREATED_TIME];

// isEmpty is undefined and empty check
if (isEmpty(publishId) && isEmpty(type) && isEmpty(body) && createdTs == null) {
console.log('Received no data');
return;
}

console.log('publishId ' + publishId + ' type ' + type + ' body ' + body + ' createdTs ' + createdTs);
let attachments = eventData[helpshiftConstants.HELPSHIFT_EVENT_DATA_ATTACHMENTS];

if (attachments && attachments.length > 0) {
attachments.forEach((attachment, index) => {
let url = attachment[helpshiftConstants.HELPSHIFT_EVENT_DATA_URL];
let contentType = attachment[helpshiftConstants.HELPSHIFT_EVENT_DATA_CONTENT_TYPE];
let fileName = attachment[helpshiftConstants.HELPSHIFT_EVENT_DATA_FILE_NAME];
let size =attachment[helpshiftConstants.HELPSHIFT_EVENT_DATA_SIZE];

if (isEmpty(url) && isEmpty(fileName) && size == null) {
console.log('Received no data for attachment ' + (index + 1));
}

if (isEmpty(url) || isEmpty(fileName) || size == null) {
console.log('Received incomplete data for attachment ' + (index + 1));
}

console.log('Attachment No. : ' + (index + 1) + ', url: ' + url + ', contentType: ' + contentType + ', fileName: ' + fileName + ', size: ' + size );
});
} else {
console.log('No attachments received in message');
}
} catch (err) {
console.error('Parsing Error', err);
}
}
}
);

CSAT Submit Event

This event is triggered when the user submits a CSAT rating after the conversation ends. The event data object has rating and additionalFeedback keys, which indicates the (star) rating and the additional comments provided by the user with the CSAT form. For your reference, see the below example.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "csatSubmit") {
try {
let eventData =
Platform.OS == "ios" ? data.eventData : JSON.parse(data.eventData);
if (eventData.hasOwnProperty("rating")) {
console.log(eventData.rating);
}
if (eventData.hasOwnProperty("additionalFeedback")) {
console.log(eventData.additionalFeedback);
}
} catch (err) {
console.error("Parsing Error", err);
}
}
});

Conversation End Event

This event is triggered when the conversation ends (resolved or rejected) and it cannot be reopened.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "conversationEnd") {
console.log("Conversation Ended");
}
});

Conversation Rejected Event

This event is triggered when an agent rejects the conversation.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "conversationRejected") {
console.log("Conversation Rejected");
}
});

Conversation Resolved Event

This event is triggered when an agent resolves the conversation.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "conversationResolved") {
console.log("Conversation Resolved");
}
});

Conversation Reopened Event

When the resolution question is enabled, the users are asked if they're satisfied with the resolution. If the user rejects it and sends a new message, then the conversation is reopened and the Conversation Reopened event is triggered.

helpshiftEmitter.addListener("onEventOccurred", (data) => {
if (data.eventName == "conversationReopened") {
console.log("Conversation Reopened");
}
});

User Authentication Failed Event

If you have User Authentication enabled on the Dashboard and if you pass an invalid token in the login(userDataMap), then you will receive this event with reason string. Check here for more info

You need add a listener with helpshiftEmitter for "onUserAuthenticationFailure".

You will receive various string name on onUserAuthenticationFailure event as shown in example.

helpshiftEmitter.addListener("onUserAuthenticationFailure", (data) => {
if (data.eventName == "REASON_AUTH_TOKEN_NOT_PROVIDED") {
console.log("no user authentication token provided");
} else if (data.eventName == "REASON_INVALID_AUTH_TOKEN") {
console.log("user authentication token is invalid");
} else if (data.eventName == "UNKNOWN") {
console.log("the reason for the authentication failure is unknown");
}
});