Authentication
To authenticate a user, create a user object and then pass it to the login
function. The User object has the following properties:
parameters | description |
---|---|
userId | Unique ID for the user |
displayName | Display name of the user. Agents will identify users by this display name |
Email ID of logged in user | |
password | User's password |
imageLink | The image of the end-user, which will be visible to the agents in the kommunicate dashboard |
authenticationTypeId | Pass 1 for authentication from kommunicate |
APP_ID | Pass your APP_ID here |
deviceApnsType | 0 for development, 1 for release |
There are 2 ways to Login:
1. Visitors
Login the user anonymously as below:
KommunicateFlutterPlugin.loginAsVisitor(APP_ID).then((result) {
print("Login as visitor successful : " + result.toString());
}).catchError((error) {
print("Login as visitor failed : " + error.toString());
});
2. Existing Users
If you have the user details, then pass the user details to create a user object:
dynamic user = {
'userId': <USER_ID>, //unique userId
'password': <PASWWORD>, //password is optional
'appId': APP_ID
};
Then pass the user object in the login function as below:
KommunicateFlutterPlugin.login(user).then((result) {
print("Login successful : " + result.toString());
}).catchError((error) {
print("Login failed : " + error.toString());
});
Verify User Login
If the user is logged in or not, one can check by calling the 'isLoggedIn' function:
KommunicateFlutterPlugin.isLoggedIn().then((value) {
if (value) {
print("User is already logged in");
} else {
print("User is not logged in");
}
});
Show or Hide ChatWidget
To control the visibility of the Chat widget on specific pages, you'll need to use this code snippet to show or hide it. Initially, it will be hidden after login.
KommunicateFlutterPlugin.isChatWidgetVisible(true);
// pass false if you don’t want to show the chat widget.
Logout
To perform logout, you can use this function that will remove the Kommunicate chat widget (only on the web) and log out the current user.
KommunicateFlutterPlugin.logout().then((value) {
print("Logout successful : " + value);
}).catchError((error, stack) =>
print("Logout failed : " + error.toString())
);