Token Base Authentication

Token base auth is system that customer can register into Diyalog sdk with their application User Info, and can chat between thier application user.

With DiyalogSDK User can register in forground mode as well as background mode. Before authentication user need to init DiyalogSDK as below.

DiyalogEngine.diyalogInstance().Initialize(getApplicationContext());
DiyalogEngine.diyalogInstance().waitForReady();

Domain Customer User

a. Foreground method

For customer user registration client need to call below method with necessary information. After successfully register on server it will create session in Diyalog SDK and can start messaging. Using below method if user already created session in Diyalog SDK, then it will directly open that session and user can start messaging.

DiyalogEngine.diyalogInstance().startTokenAuth(context,dlgToken,deviceId,
customerId,customerName, customerPhone, customerEmail);

context - Activity context

dlgToken - Main application server will return Diyalog Token when user will login into main application DeviceId - domain specific device id. this is for domain validation

CustId - domain customer id

CustName - customer name

CustPhone - customer phone number (Optional)

CustEmail – customer email address (Optional)

b. Background method

When customer user will call background method then it will be register on server and after successfully register, it will create session into sdk. And when user will click on Diyalog chat icon from main application to open sdk, it will directly open that session. user does not wait for register. And In background method if there is any failure then it will pass error message into failure callback.

DiyalogEngine.diyalogInstance().startTokenAuthInBackground(context,dlgToken,deviceId,
customerId,customerName, customerPhone, customerEmail, new TokenAuthResponse() {
@Override
public void success() {
Log.e("Auth In Bakground","==>> Success ");
}
@Override
public void failure(TokenAuthError tokenAuthError) {
Log.e("Auth In Bakground", "==>> Error Message: " + tokenAuthError.getErrorMsg());
Log.e("Auth In Bakground", "==>> Error Code: "+ tokenAuthError.getErrorCode());
}
}) ;

Domain Staff User

a. Foreground method

For staff user registration client need to call below method with necessary information. After successfully register on server it will create session in Diyalog SDK and can start messaging. Using below method if user already created session in Diyalog SDK, then it will directly open that session and user can start messaging.

DiyalogEngine.diyalogInstance().startDomainUserTokenAuth( context, dlgToken, sessionId,
userId,
userName,
userPhone,
userEmail);

context - Activity context

dlgToken - Main application server will return Diyalog Token when user will login into main application

sessionId – Staff user's sessionId

userId - Staff user's UserID

UserName - Staff user's UserName

userPhone - Staff user's PhoneNumber(Optional)

userEmail - Staff user's EmailID (Optional)

b. Background method When staff user will call background method then it will be register on server and after successfully register, it will create session into sdk. And when user will click on Diyalog chat icon from main application to open sdk, it will directly open that session. user does not wait for register. And In background method if there is any failure then it will pass error message into failure callback.

DiyalogEngine.diyalogInstance().startDomainUserTokenAuthInBackground(context, dlgToken, sessionId, userId,
userName, userPhone, userEmail, new TokenAuthResponse() {
@Override
public void success() {
Log.e("Auth In Bakground","==>> Success ");
}
@Override
public void failure(TokenAuthError tokenAuthError) {
Log.e("Auth In Bakground", "==>> Error Message: " + tokenAuthError.getErrorMsg());
Log.e("Auth In Bakground", "==>> Error Code: "+ tokenAuthError.getErrorCode());
}
}) ;

Get Active sessions

User can get all sessions list those already registered in diyalog SDK. This method will be use for both Domain customer user and staff user.

ArrayList<AccountVo> sessionList = DiyalogEngine.diyalogInstance().getActiveSessions();

This method will return list of saved session from sdk. It will contain userInfo as below:

  • ApplicationUserID
  • AuthID
  • UserName
  • User Image.
  • User is active or not
  • Unread message count

Messaging from specific User

User can start messaging from specific user. If session already saved into Diyalog SDK then user can start messaging with thier UserID.

DiyalogEngine.diyalogInstance().startMessagingWithUserId(context,customerId);

context - Activity context

customerId - domain customer id

This method will be use for both Domain customer user and staff user.

Delete session of user

Client can delete session of diyalog sdk for any user.

boolean isDelted = DiyalogEngine.diyalogInstance().deleteSessionOfUser(customerId);

Get total unread count into main application.

Client can get total no of unread message count into main application, so they can set unread badge count into main application. Client need to subscribe unread count event as below:

DiyalogEngine.diyalogInstance().subscribeToTotalUnreadCountEvent(new ValueChangedListener<Integer>() {
@Override
public void onChanged(Integer val, Value<Integer> valueModel) {
unreadCount.setText(String.valueOf(val)); // unreadCount is textview for display unread message count.
}
});