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 For example:
import { helpshiftEmitter } from "helpshift-plugin-sdkx-react-native";

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);
}
}
});

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);
}
}
});

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");
}
});