Helpshift Delegates
The Helpshift SDK provides delegate callbacks to help app developers track a user's activities within the help section.
- All the public APIs in the SDK should be called after initializing the SDK via HelpshiftSdk.install() API
- Events invoked before setting
Helpshift.SetHelpshiftEventsListener
cannot be received again
Helpshift Events Listener/Delegate implementation
You can set IHelpshiftEventsListener
implementation by calling the HelpshiftSdk.GetInstance().SetHelpshiftEventsListener()
method.
Step 1: Implement the IHelpshiftEventsListener interface
public class HSEventsListener: IHelpshiftEventsListener
{
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
// all events
}
public void AuthenticationFailedForUser(HelpshiftAuthenticationFailureReason reason)
{
//auth failure event
}
}
Step 2: Set this implementation class by calling Helpshift API
using Helpshift;
//...
//...
private HelpshiftSdk help;
//..
void Awake(){
// install call here
help = HelpshiftSdk.GetInstance();
}
void Start(){
// set the listener
help.SetHelpshiftEventsListener(new HSEventsListener());
}
Events
Helpshift session started event
This event gets fired when the Helpshift session starts
- Event name:
HelpshiftEvent.SDK_SESSION_STARTED
- Event data:
null
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if(eventName.Equals(HelpshiftEvent.SDK_SESSION_STARTED))
{
Debug.Log("Helpshift session started.");
}
}
//...
}
Helpshift session ended event
This event gets fired when the Helpshift session ends.
- Event name:
HelpshiftEvent.SDK_SESSION_ENDED
- Event data:
null
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if(eventName.Equals(HelpshiftEvent.SDK_SESSION_ENDED))
{
Debug.Log("Helpshift session ended.");
}
}
//...
}
Unread Message Count Event
This event gets fired when you call Helpshift.RequestUnreadMessageCount(shouldFetchFromServer)
API to request unread messages count.
- Event name:
HelpshiftEvent.RECEIVED_UNREAD_MESSAGE_COUNT
- Event data:
- Event data:
HelpshiftEvent.DATA_MESSAGE_COUNT
- Type:
int
- Type:
HelpshiftEvent.DATA_MESSAGE_COUNT_FROM_CACHE
- Type:
boolean
- Type:
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if(eventName.Equals(HelpshiftEvent.RECEIVED_UNREAD_MESSAGE_COUNT))
{
if(eventData.ContainsKey(HelpshiftEvent.DATA_MESSAGE_COUNT)) {
Debug.Log("Unread count: " + eventData[HelpshiftEvent.DATA_MESSAGE_COUNT]);
}
if(eventData.ContainsKey(HelpshiftEvent.DATA_MESSAGE_COUNT_FROM_CACHE)) {
Debug.Log("Is Unread count from cache: " + eventData[HelpshiftEvent.DATA_MESSAGE_COUNT_FROM_CACHE]);
}
}
}
//...
}
Conversation Status Event
This event contains information about the current ongoing conversation.
- Event name:
HelpshiftEvent.CONVERSATION_STATUS
- Event data:
- Event data:
HelpshiftEvent.DATA_LATEST_ISSUE_ID
- Type:
string
- Type:
HelpshiftEvent.DATA_LATEST_ISSUE_PUBLISH_ID
- Type:
string
- Type:
HelpshiftEvent.DATA_IS_ISSUE_OPEN
- Type:
boolean
- Type:
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if(eventName.Equals(HelpshiftEvent.CONVERSATION_STATUS))
{
if(eventData.ContainsKey(HelpshiftEvent.DATA_LATEST_ISSUE_ID)) {
Debug.Log("Issue ID : " + eventData[HelpshiftEvent.DATA_LATEST_ISSUE_ID]);
}
if(eventData.ContainsKey(HelpshiftEvent.DATA_LATEST_ISSUE_PUBLISH_ID)) {
Debug.Log("Publish ID : " + eventData[HelpshiftEvent.DATA_LATEST_ISSUE_PUBLISH_ID]);
}
if(eventData.ContainsKey(HelpshiftEvent.DATA_IS_ISSUE_OPEN)) {
Debug.Log("Is issue open : " + eventData[HelpshiftEvent.DATA_IS_ISSUE_OPEN]);
}
}
}
//...
}
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:
- Event name:
HelpshiftEvent.WIDGET_TOGGLE
- Event data:
HelpshiftEvent.DATA_SDK_VISIBLE
- Type:
boolean
- Type:
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if(eventName.Equals(HelpshiftEvent.WIDGET_TOGGLE))
{
if(eventData.ContainsKey(HelpshiftEvent.DATA_SDK_VISIBLE)) {
Debug.Log("Is SDK Visible " + eventData[HelpshiftEvent.DATA_SDK_VISIBLE]);
}
}
}
//...
}
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 :
HelpshiftEvent.ACTION_CLICKED
- Event data:
HelpshiftEvent.DATA_ACTION
HelpshiftEvent.DATA_ACTION_TYPE
HelpshiftEvent.DATA_ACTION_TYPE_CALL
HelpshiftEvent.DATA_ACTION_TYPE_LINK
Key (Constant) | Key (Raw) | Type |
---|---|---|
HelpshiftEvent.ACTION_CLICKED | userClickOnAction | string |
HelpshiftEvent.DATA_ACTION | actionType | string |
HelpshiftEvent.DATA_ACTION_TYPE | actionData | string |
HelpshiftEvent.DATA_ACTION_TYPE_CALL | call | string |
HelpshiftEvent.DATA_ACTION_TYPE_LINK | link | string |
The key constants are available from SDK X 10.3.0 onwards. For older SDK X versions, please use the raw keys instead.
public class HSEventsListener : IHelpshiftEventsListener
{
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.ACTION_CLICKED))
{
// With Key Constants
string actionType = (string) eventData[HelpshiftEvent.DATA_ACTION_TYPE];
string actionData = (string) eventData[HelpshiftEvent.DATA_ACTION];
-------------------- OR --------------------
// With Key Raw Values
string actionType = (string) eventData["actionType"];
string actionData = (string) eventData["actionData"];
if (string.IsNullOrEmpty(actionType) || string.IsNullOrEmpty(actionData))
{
Debug.Log($"Event Received for ${eventName} with actionType or action Data as empty");
return;
}
Debug.Log($"Event Received for ${eventName}. Action type - ${actionType}. Action data - ${actionData}");
}
}
}
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.
- Event name:
HelpshiftEvent.CONVERSATION_START
- Event data:
HelpshiftEvent.DATA_MESSAGE
- Type:
string
- Type:
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.CONVERSATION_START))
{
if(eventData.ContainsKey(HelpshiftEvent.DATA_MESSAGE)) {
Debug.Log("Conversation started with text: " + eventData[HelpshiftEvent.DATA_MESSAGE]);
}
}
}
//...
}
Message Add Event
This event is triggered when the user adds a message in a conversation. It might be a text message, response via bot input, or an attachment. The event data object has type
and body
keys, which indicates the type and body of the message added by the user. For your reference, see the below example.
- Event name:
HelpshiftEvent.MESSAGE_ADD
- Event data:
HelpshiftEvent.DATA_MESSAGE_TYPE
- Values:
HelpshiftEvent.DATA_MESSAGE_TYPE_ATTACHMENT
,HelpshiftEvent.DATA_MESSAGE_TYPE_TEXT
- Values:
HelpshiftEvent.DATA_MESSAGE_BODY
- Type:
string
- Type:
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.MESSAGE_ADD))
{
if(eventData.ContainsKey(HelpshiftEvent.DATA_MESSAGE_BODY)) {
Debug.Log("New message added with body: " + eventData[HelpshiftEvent.DATA_MESSAGE_BODY]);
}
if(eventData.ContainsKey(HelpshiftEvent.DATA_MESSAGE_TYPE)) {
Debug.Log("New message added with type: " + eventData[HelpshiftEvent.DATA_MESSAGE_TYPE]);
}
}
}
//...
}
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 :
HelpshiftEvent.AGENT_MESSAGE_RECEIVED
Event data:
Key Type Value HelpshiftEvent.DATA_PUBLISH_ID string Conversation ID of the ongoing issue HelpshiftEvent.DATA_MESSAGE_TYPE string Message Type of the message HelpshiftEvent.DATA_MESSAGE_BODY string The actual message sent by the agent or empty HelpshiftEvent.DATA_CREATED_TIME long Unix epoch timestamp in ms HelpshiftEvent.DATA_ATTACHMENTS Dictionary<string, object>> Attachments, if they are present HelpshiftEvent.DATA_URL string URL of the attachment HelpshiftEvent.DATA_CONTENT_TYPE string MIME type of the attachment HelpshiftEvent.DATA_FILE_NAME string File name of the attachment HelpshiftEvent.DATA_SIZE integer Size of the attachment in bytes
- This delegate is available from 10.3.0 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
HelpshiftEvent.DATA_CONTENT_TYPE
is absent from the payload. For such cases, file type can be inferred from extension from file name - HelpshiftEvent.DATA_MESSAGE_TYPE has following types :
- HelpshiftEvent.DATA_MESSAGE_TYPE_APP_REVIEW_REQUEST
- HelpshiftEvent.DATA_MESSAGE_TYPE_SCREENSHOT_REQUEST
- HelpshiftEvent.DATA_MESSAGE_TYPE_TEXT
public class HSEventsListener : IHelpshiftEventsListener
{
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.AGENT_MESSAGE_RECEIVED))
{
string publishId = (string)eventData[HelpshiftEvent.DATA_PUBLISH_ID];
string type = (string)eventData[HelpshiftEvent.DATA_MESSAGE_TYPE];
string body = (string)eventData[HelpshiftEvent.DATA_MESSAGE_BODY];
long? createdTs = (long?)eventData[HelpshiftEvent.DATA_CREATED_TIME];
if (string.IsNullOrEmpty(publishId) && string.IsNullOrEmpty(type) && string.IsNullOrEmpty(body) && createdTs == null)
{
Debug.Log(TAG, "Received no data");
return;
}
Debug.Log($"publishId {publishId}, type {type}, body {body}, createdTs {createdTs}");
List<object> attachments = (List<object>)eventData[HelpshiftEvent.DATA_ATTACHMENTS];
if (Utils.isEmpty(attachments))
{
Debug.Log("No attachments received in message");
}
else
{
for (int i = 0; i < attachments.Count; i++)
{
Dictionary<string, object> attachment = (Dictionary<string, object>)attachments[i];
string url = (string)attachment[HelpshiftEvent.DATA_URL];
string contentType = (string)attachment[HelpshiftEvent.DATA_CONTENT_TYPE];
string fileName = (string)attachment[HelpshiftEvent.DATA_FILE_NAME];
int? size = (int?)attachment[HelpshiftEvent.DATA_SIZE];
if (string.IsNullOrEmpty(url) && string.IsNullOrEmpty(fileName) && size == null)
{
Debug.Log($"Received no data for attachment {i + 1}");
continue;
}
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(fileName) || size == null)
{
Debug.Log($"Received incomplete data for attachment {i + 1}");
continue;
}
Debug.Log($"Attachment No. : {i + 1}, url: {url}, contentType: {contentType}, fileName: {fileName}, size: {size}");
}
}
}
}
}
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.
- Event name:
HelpshiftEvent.CSAT_SUBMIT
- Event data:
HelpshiftEvent.DATA_CSAT_RATING
- Type:
int
- Type:
HelpshiftEvent.DATA_ADDITIONAL_FEEDBACK
- Type:
string
- Type:
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.CSAT_SUBMIT))
{
if(eventData.ContainsKey(HelpshiftEvent.DATA_CSAT_RATING)) {
Debug.Log("CSAT submitted with rating: " + eventData[HelpshiftEvent.DATA_CSAT_RATING]);
}
if(eventData.ContainsKey(HelpshiftEvent.DATA_ADDITIONAL_FEEDBACK)) {
Debug.Log("CSAT feedback: " + eventData[HelpshiftEvent.DATA_ADDITIONAL_FEEDBACK]);
}
}
}
//...
}
Conversation End Event
This event is triggered when the conversation ends (resolved or rejected) and it cannot be reopened.
- Event name:
HelpshiftEvent.CONVERSATION_END
- Event Data:
null
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.CONVERSATION_END))
{
Debug.Log("Conversation Ended");
}
}
//...
}
Conversation Rejected Event
This event is triggered when an agent rejects the conversation.
- Event name:
HelpshiftEvent.CONVERSATION_REJECTED
- Event data:
null
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.CONVERSATION_REJECTED))
{
Debug.Log("Conversation Rejected");
}
}
//...
}
Conversation Resolved Event
This event is triggered when an agent resolves the conversation.
- Event name:
HelpshiftEvent.CONVERSATION_RESOLVED
- Event data:
null
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.CONVERSATION_RESOLVED))
{
Debug.Log("Conversation Resolved");
}
}
//...
}
Conversation Reopened Event
When 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.
- Event name:
HelpshiftEvent.CONVERSATION_REOPENED
- Event data:
null
public class HSEventsListener : IHelpshiftEventsListener
{
// ...
public void HandleHelpshiftEvent(string eventName, Dictionary<string, object> eventData)
{
if (eventName.Equals(HelpshiftEvent.CONVERSATION_REOPENED))
{
Debug.Log("Conversation Reopened");
}
}
//...
}
User Authentication Failed Event
If you have user authentication feature
enabled on the Dashboard and if you pass an invalid token in the HelpshiftSdk.GetInstance().Login(userDataMap)
, then you will receive this event with reason string. Check here for more info
Reason type :
HelpshiftAuthenticationFailureReason.INVALID_AUTH_TOKEN
HelpshiftAuthenticationFailureReason.AUTH_TOKEN_NOT_PROVIDED
HelpshiftAuthenticationFailureReason.UNKNOWN
public class HSEventsListener: IHelpshiftEventsListener
{
// HandleHelpshiftEvent
public void AuthenticationFailedForUser(HelpshiftAuthenticationFailureReason reason)
{
Debug.Log("Authentication Failed for reason " + reason.ToString());
}
}