JS & REST Chat API Integration

JAVASCRIPT API

The Javascript API is available with all plans. Click here to check the REST API Docs

Summary


User Login and Profile Sync


First of all you need to generate this code right before the Flyzoo main script (the one you can get from the dashboard under the SETUP > INSTALLATION option).
The main script will detect this code and use to create/update the user profile and authenticate the user into the chat if needed.

<script type="text/javascript">
var FlyzooApi = FlyzooApi || {};
FlyzooApi.UserId = " user id from your system ";
FlyzooApi.UserName = " user name from your db ";
FlyzooApi.Avatar = " link to avatar if available i.e. http://mysite.com/avatar.jpg ";
FlyzooApi.Email = " user email ";
FlyzooApi.AccessRoles = " user roles i.e. paid, pro, ... "; (optional)
FlyzooApi.Friends = ["friend-id-", "friend-id-", "friend-id",...]; (optional)
FlyzooApi.Profile = " link to profile i.e. http://mysite.com/profiles/username "; (optional)
FlyzooApi.Signature = "sha256 signature (see instructions)"
</script>

FRIENDS LIST

friend-id-* are local user IDs, for instance:

FlyzooApi.Friends = ["435","1123"];

NOTES

The widget will automatically sync data only when a change in the UserName, Avatar, AccessRoles, Friends or Profile field is detected.

SIGNATURE

Starting from January, 1st 2016 all API login requests must provide a valid FlyzooApi.Signature.

You MUST generate the signature on your server by following these simple steps:

  • Trim and lower case the (A) local user id and (B) user email fields
  • Chain A+B into a string (C)
  • Create a SHA256 hash for (C) using the API Secret Key you can retrieve from the dashboard

PHP EXAMPLE:

$payload = trim(strtolower($userId)).trim(strtolower($userEmail));

$signature = hash_hmac("sha256", $payload, $ApiSecretKey);


Start a private chat


SYNTAX

FlyzooApi.startChat(LocalUserId, SuccessCallback(), FailCallback())

Success and fail callbacks are helpful for various scenarios.
For example you could show a spinning loader inside a "CHAT WITH USER X" button and then hide it after the chat is loaded.

NOTE: pass function() { } if you don't wont to perform any action on callback.

Possible Fail messages:

not-found -> user not found
cant-chat-with-yourself -> you are sending your same current id
local-userid-not-provided -> id set to blank
access-token-missing -> authorization error
system-error -> connection issues and other api errors.

EXAMPLE

<a id="btnStartChat" href="#"
onclick="javascript:FlyzooApi.startChat(1002, startSuccess, startFail)">
start chat with other user </a>
<script type="text/javascript">
function startSuccess(e) { alert("success"); };
function startFail(e) { alert("fail with message:" + e); };
</script>

Open a group chat


To launch a group chat you need to know the Group Chat Id. You can retrieve that Id from the dashboard, under the SETUP > GROUP CHATS settings.

SYNTAX

FlyzooApi.startGroupChat(GroupChatId)

EXAMPLE

var groupChatId = “371c4135c59c353ef5069b27”;
var groupChatLabel = “The amazing group chat”;
FlyzooApi.startGroupChat(groupChatId, groupChatLabel);

Get user status


SYNTAX

FlyzooApi.getUserStatus(LocalUserId,SuccessCallback(),FailCallback())

EXAMPLE

var UserID = “1001”;
var UserName = “Jake”;
FlyzooApi.getUserStatus(UserID,
function(e) { alert(UserName + " is "+ e) },
function(e) { alert("error: " + e) }) );

User logout


SYNTAX

FlyzooApi.resetSession()

EXAMPLE

$(“#logoutButton”).click(function() {
// custom logout logic here
FlyzooApi.resetSession();
// redirect the user to the home page
window.location.href = “url to exit page here….”;
}

REST API

The REST API is available for the ULTRA plan and all Enterprise Plans.

This API allows you to create a deep integration with your website.

DOCS & EXAMPLES

Here you can download the documentation and a sample php project designed to help you integrate Flyzoo with your project in no time!

REST API V1.1 Docs - Release 2

PHP API Examples Kit