There are a couple ways in which CometChat can sync with your existing users. The quickest is to use the On-the-fly Method.
On-the-fly
You can create users on-the-fly and log them into CometChat. Add the below code to your site template. Be sure to modify the variables to out the information programmatically.
<!-- USER MANAGEMENT CODE -->
<script>
var chat_name = 'John Doe';
var chat_id = '1';
var chat_avatar = 'https://www.yoursite.com/avatars/1.png';
var chat_link = 'https://www.yoursite.com/john-doe';
</script>
<!-- LAUNCH COMETCHAT CODE -->
<!-- Refer to Launch CometChat page for this code -->
Variable | Description | Mandatory |
---|---|---|
chat_name | Display name of the logged-in user | Yes |
chat_id | Unique ID of the logged-in user | Yes |
chat_avatar | Avatar image URL of the logged-in user | |
chat_link | Profile page URL of the logged-in user |
For example, if you are using PHP, in most cases this information will be stored in your session variable after logging in the user. So your code will be similar to:
<!-- USER MANAGEMENT CODE BELOW -->
<script>
var chat_name = '<?php echo $_SESSION['name'];?>';
var chat_id = '<?php echo $_SESSION['id'];?>';
var chat_avatar = '<?php echo $_SESSION['avatar'];?>';
var chat_link = '<?php echo $_SESSION['profile'];?>';
</script>
<!-- LAUNCH COMETCHAT CODE BELOW -->
<!-- Refer to Launch CometChat page for this code -->
Via Restful API
You can use the createUser
API in our Restful API to create users using your server code. Typically, you should create them when the user signs up.
<!-- USER MANAGEMENT CODE -->
<script>
var chat_id = '1';
</script>
<!-- LAUNCH COMETCHAT CODE -->
<!-- Refer to Launch CometChat page for this code -->
Via Admin Panel
If you do not wish to sync your users with CometChat, you can use our Admin Panel to manually manage your users. Visit CometChat Admin Panel
-> Users
-> Add New User
to create a new user.
<!-- USER MANAGEMENT CODE -->
<script>
var chat_id = '1';
</script>
<!-- LAUNCH COMETCHAT CODE -->
<!-- Refer to Launch CometChat page for this code -->
Updated about a year ago
What's Next
Once you've synced your users, you can further enhance it using the following guides:
Friends Synchronization |
Role Based Access Control |