# Applozic Cordova PhoneGap Chat Plugin
## Using
Install the plugin
## Android
If you see gradle wrapper error then open gradle/wrapper/gradle-wrapper.properties
Change distributionUrl to point to 2.14.1-all
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
## iOS
Remove duplicate entry from "Linked Framework and Libraries" if any.
### Steps to integrate:
#### Login/Register User
```js
var alUser = {
'userId' : userId, //Replace it with the userId of the logged in user
'password' : password, //Put password here
'authenticationTypeId' : 1,
'applicationId' : 'applozic-sample-app',
'deviceApnsType' : 0 //Set 0 for Development and 1 for Distribution (Release)
};
applozic.login(alUser, function() {
applozic.registerPushNotification(function() {}, function(){});
applozic.launchChat(function() {}, function() {});
}, function() {});
```
#### Launch Chat
##### Main Chat screen
```
applozic.launchChat(function() {console.log("success");}, function () {console.log("error");});
```
##### Launch Chat with a specific User
```
applozic.launchChatWithUserId(userId, function() {console.log("success");}, function () {console.log("error");});
```
##### Launch Chat with specific Group
```
applozic.launchChatWithGroupId(groupId, function() {console.log("success");}, function () {console.log("error");});
```
```
applozic.showAllRegisteredUsers(false, function() {}, function() {});
{'userId' : 'adarsh', 'displayName' : 'Adarsh Kumar'},
{'userId' : 'ranjeet', 'displayName' : 'Ranjeet Priyadarshi'}
];
```
##### Android
Set the following in applozic-settings.json properties file.
```
```
#### Push Notification Setup
##### Android
Add the following under buildscript -> dependencies
```
classpath 'com.google.gms:google-services:3.0.0'
```
Add the following at the bottom of the file:
```
apply plugin: 'com.google.gms.google-services'
```
After adding, it will look something like this:
```
buildscript {
repositories {
mavenCentral()
jcenter()
}
// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: 'com.google.gms.google-services'
```
From login success callback, call applozic.registerPushNotification(function() {}, function(){});
For push notifications, you must have a Firebase account:
Go to Applozic Dashboard, update the FCM/GCM Server Key from Firebase account to your Applozic application.
"Edit Application -> Push Notification -> Android -> FCM/GCM Server Key"
##### iOS
Add code as mentioned in the following documentation:
#### Group
##### Create Group
```
var group = {
'groupName': 'hey',
'groupMemberList': ['userid1', 'userid2', 'userid3'], // Pass list of user Ids in groupMemberList
'type' : 1, //'type' : 1, //(required) 1:private, 2:public, 5:broadcast,7:GroupofTwo
'key1' : 'value1',
'key2' : 'value2'
}
};
applozic.createGroup(group, function() {}, function() {});
```
#### Logout
```
applozic.logout(function() {console.log("success");}, function () {console.log("error");});
```
Run the code
cordova run
## More Info