Skip to main content

Starting Online Help

Diyalog Platform provides live assistance service to your customers through your mobile application with messaging.

You can download full simple online help android project from SimpleOnlineHelp link.

First of all, you need to know the flow about online help in Diyalog platform.

The flow is like below :

You should first create and get a transaction hash data in Diyalog server by calling Diyalog server's rest api from your application server. Diyalog server will create a transactionHash and then you could start an online help by using this transaction hash. This step is important for security.

  1. Your mobile app should call your application server to get transactionHash with the customer and device hash.
  2. Your application server should create and get transactionHash in Diyalog Server by calling gettransactionhashforonlinehelp rest api. Only server with valid credentials can call this api in Diyalog server and generate transactionHash. You can get the credential information for your server from the Diyalog admin.
  3. Diyalog server creates and return transactionHash to your server.
  4. Your app server return transactionHash to your mobile app.
  5. After getting transactionHash from the server, your mobile app can call startAnonymousOnlineHelp method in the DiyalogSDK with it.
  6. DiyalogSDK call Diyalog server and initiate online help and then waits until other party (agent) to connect.
  7. Diyalog server create online help and then return OK to mobile app. If there is an error, server will return error to mobile app.
  8. DiyalodSDK will return response of startAnonymousOnlineHelp method to your app. Then you can show wait screen in your app if you manage wait screen. If not, DiyalogSDK will show default wait screen.
  9. When this process starts, a request should have been sent to the call system queue for online help from your own system. When an agent (representative) open a customer from the queue, he initiates the online help chat with the customer through the Diyalog application.
  10. Diyalog server starts online help with each parties who are agent and customer.
  11. After online help startted with customer and agent. Diyalog SDK will send online help state to your app via callback function that you subcscribe. These states can be "STARTED", "CHAT_INPROGRESS", "CHAT_ENDED" and "N0_CHAT"
  12. DiyalogSDK will update your app by all changings in the online help states.

An online help can be started at the relevant stage of your application as follows. When you call the following method, Diyalog first performs the necessary security checks for the relevant customer according to the transactionHash, deviceHash and customer number trio and starts the live help for the relevant customer.

Waiting screen should be shown to the customer until the live help is started by the customer representative. You can manage the waiting screen in your own application or use Diyalog SDK's waiting screen if you prefer.

@objc open func startAnonymousOnlineHelp(
customerId : String,
customerName : String,
idNumber : Int64 = 0,
customerPhone : Int64 = 0,
email : String = "",
helpType : String,
transactionHash : String,
isLoggedIn : Bool,
isBackground : Bool,
waitDisplayText : String,
result: @escaping (Bool, ACOnlineHelpStartError?) -> Void)
Parameters
customerId (String) Customer id number.
customerName (String) Name of the customer.
idNumber (Long)
National ID number of the customer. It is not must. You can set 0 for it.
customerPhone (Long)
Opsiyoneldir.
Phone number of the customer. This paramater is optional. It can be set null.
email (Long)
Optional
Email address of the customer. This paramater is optional. It can be set null.
helpType (String) This parameter is used to define help type. It can be "chat", "video_call", "voice_call".
transactionHash (String) It is the transactionHash value that you create in the Dialog server through your own application server.
waitDisplayText (String)
Optional
It is the text information that will be displayed on the waiting screen. This parameter is used only if Diyalog SDK will manage waiting screen.
isLoggedIn (boolean)It is the flag that show customer is logged in ot not into main app.
isBackground (boolean)It is the flag that show waiting screen will be managed by Diyalog SDK ot not.
result (Bool, ACOnlineHelpStartError?) startAnonymousOnlineHelp method is an asynchronous method and sends the result (information that the online help has been started) to your application with this callback method.
If Bool value return true, the method successfull and means waiting in background to connect a repsresentative
If Bool value return false, the method failed. And You can check failure reason from ACOnlineHelpStartError

After getting success from startAnonymousOnlineHelp method, you can listen state of online help by subscribing the onlineHelpState. You can use following method for it.

@objc open func subscribeToOnlineHelpChatStateEvent(listener: @escaping (_ value: String) -> Void)

You can unsubscribe from the event with the following method.

@objc open func unsubscribeToOnlineHelpChatStateEvent()

Online help state is a string and can have following values.

"NO_CHAT" : Default and initial value. There is no active chat.
"STARTED" : Online help started and Diyalog wait screen is shwing. If you handle wait screen, this state will not return.
"CHAT_INPROGRESS" : Agent ve customer started to conversation.
"CHAT_ENDED" : Conversation completed.

You can see complete code sample that you need to implement below.

// 1. Get Diyalog device hash from Diyalog sdk
let deviceHash : String = DiyalogEngine.diyalogInstance().getDeviceHash();
print("deviceHash : \(deviceHash)")
// 2. Call Diyalog server gettransactionhashforonlinehelp service from your app server with customerId
// and this deviceHash.
// below code assume that transactionHash recieved from server.
let transactionHash : String = "4222f1c04f35dc6b419f4ef5a0c9f2aadc26fc34";
let customerId : String = "123458"
let customerName : String = "Name of Customer" // Name and surname
let customerIdNo : Int64 = Int64(0) // National id number. It is optional. You can set 0L.
let customerPhoneNumber : Int64 = Int64(0) // Optional
let customerEmail : String = "" // Optional
let helpType : String = "chat" // "chat", "video_call", "voice_call"
// message in wait screen. If you handle wait screen in your app. You can set it empty;
let waitDisplayText : String = "Please wait. Our representative will start video call soon."
let isLoggedIn : Bool = false; // this parameter say user logged in to your app or not. Itis not processeing in Diyalog for now. It will be use later.
let isBackground : Bool = true; // true : Your app handle wait screen. false: Diyalog will handle wait screen
DiyalogEngine.diyalogInstance().startAnonymousOnlineHelp(
customerId: customerId,
customerName : customerName,
idNumber : customerIdNo,
customerPhone : customerPhoneNumber,
email : customerEmail,
helpType : helpType,
transactionHash : transactionHash,
isLoggedIn : isLoggedIn,
isBackground : isBackground,
waitDisplayText: waitDisplayText,
result: { (success, error) in
if(success)
{
print("Success")
self.showWait()
DiyalogEngine.diyalogInstance().subscribeToOnlineHelpChatStateEvent(listener: {(chatState : String?) -> Void in
if chatState != nil {
print("Online help chat state changed to " + chatState!)
// Online help states
//"NO_CHAT" : Default and initial value. There is no active chat
//"STARTED" : Online help started and Diyalog wait screen is shwing. If you handle wait screen, this state will not return.
//"CHAT_INPROGRESS" : Agent ve customer started to conversation.
//"CHAT_ENDED" : Conversation completed.
if (chatState == "CHAT_ENDED"){
DiyalogEngine.diyalogInstance().unsubscribeToOnlineHelpChatStateEvent()
self.showStartAgain()
}
}
})
}else{
print("there is an error. ErrCode : \(String(describing: error?.getCode())). Error Msg: \(String(describing: error?.getMsg()))")
}
})

If startAnonymousOnlineHelp method return successfull and you showed wait screen to customer and the customer press cancel button in your wait screen before agent start online help, you should call closeMessaging method to stop process

DiyalogEngine.diyalogInstance().closeMessaging();

Done :)

You can download full simple online help android project from SimpleOnlineHelp link.