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());
});
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");
}
});
Update user details
Use the below function to update the details of the logged in user.
dynamic kmUser = {
'displayName': 'New display name',
'contactNumber': 'New contact number',
'imageLink': 'New pofile image url',
'email': 'New email Id',
'metadata': { //Pass any Key-Value pair(String, String) here. This will be displayed under User Info section in the dashboard
'key1': 'value1',
'key2': 'value2'
}
};
KommunicateFlutterPlugin.updateUserDetail(kmUser)
.then((response) {
print("User details updated successfully : " + response.toString());
}).catchError((error) {
print("Error occurred while update user details : " + error.toString());
});
Note: All the fields in the kmUser object above are optional.
updateUserDetail
function has to be called after conversationBuilder's success
Here is the sample app which implements this SDK: https://github.com/Kommunicate-io/Kommunicate-Flutter-Plugin/tree/master/example
Logout
You can call the logout
method to logout the user from Kommunicate. Use the method as below:
KommunicateFlutterPlugin.logout();