API

In this article, we'll help you interact with ArrowChat on your site using our JavaScript API.


Sections in this article

Application Tab Toggle


The openCloseApp('{APP FOLDER}') API will toggle between the open and close state of an application's window.


Parameters
App Folder This is the application's folder name that you want to open/close.

Example
<a href="javascript:;" onClick="jqac.arrowchat.openCloseApp('facebook');">Open/Close Facebook App</a>

Application Image


The changeAppImage('{APP FOLDER}', '{IMAGE PATH}') API will change an application's image temporarily.


Parameters
App Folder This is the application's folder name that you want to change the image on.
Image Path This is the path of the image relative to the ArrowChat folder.

Example
<a href="javascript:;" onClick="jqac.arrowchat.changeAppImage('facebook', 'themes/new_facebook_full/images/icons/notification_comment.png');">Change the Facebook Fan Page Image</a>
Change the Facebook Fan Page Image
<a href="javascript:;" id="changeImage">Change the Facebook Fan Page Image</a>
						
$(document).ready(function() {
	$("#changeImage").click(function() {
		jqac.arrowchat.changeAppImage('facebook', 'themes/new_facebook_full/images/icons/notification_comment.png');
	});
});

Application Alert


The addAppAlert('{APP FOLDER}', '{NUMBER}') API will add a red bubble notification next to the application's tab.


Parameters
App Folder This is the application's folder name that you want to attach the bubble to.
Number This is the number of new notifications you want to display.

Example
Click Here to add a "2" notification alert to our Facebook Fan Page app.
window.onload = function() {
	jqac.arrowchat.addAppAlert('facebook', '2');
}

User Details


The getUser('{USER ID}', '{CALLBACK FUNCTION}') API will allow you to retrieve details about a specific user.


Parameters
User ID This is the user's ID that you want to get details about.
Callback Function This is the name of the function that you want to execute after.

Return JSON Data
s The user status (available, away, busy (for mobile users), offline)
n The name of the user
a The avatar path of the user
l The user's profile link

Example
window.onload = function() {
   jqac.arrowchat.getUser('53','userdetails');
}

function userdetails(data) {
	if (data) {
		if (data.s == 'available' || data.s == 'away' || data.s == 'busy') {
			document.getElementById("user-details").innerHTML = '<a href="javascript:;" onClick="jqac.arrowchat.chatWith(\'53\');">Chat With Me</a>';
		} else {
			document.getElementById("user-details").innerHTML = 'User Offline';
		}
		document.getElementById("user-details").innerHTML += '<br /><b>Name:</b> ' + data.n + '<br /><b>Avatar:</b> ' + data.a + '<br /><b>Profile Link:</b> ' + data.l;
	}
}

Open Private Chat


The chatWith('{USER ID}') API will allow you to create a link on your page that will open up a conversation with a speific user. Because the user ID will most likely be a variable, you'll need to write some code to change the user ID based on the page the user is on.


Parameters
User ID This is the user's ID that you want to initiate the chat with.

Example
<a href="javascript:;" onClick="jqac.arrowchat.chatWith('53');">Chat With Me</a>
<a href="javascript:;" onClick="jqac.arrowchat.chatWith('<?php echo getUserDetails()->user_id; ?>');">Chat With Me</a>

This example code will check if the user is online before displaying a chat with me link. It combines both the getUser('{USER ID}', '{CALLBACK FUNCTION}') and chatWith('{USER ID}') APIs.

window.onload = function() {
   jqac.arrowchat.getUser('53','userdetails');
}

function userdetails(data) {
	if (data.s == 'available') {
		document.getElementById("message-user").innerHTML = '<a href="javascript:;" onClick="jqac.arrowchat.chatWith(\'53\');">Chat With Me</a>';
	} else {
		document.getElementById("message-user").innerHTML = 'User Offline';
	}
}
<div id="message-user"></div>

Send a Message


The sendMessage('{USER ID}', '{MESSAGE}') API will instantly send a message to the user ID that you specify.


Parameters
User ID This is the user's ID that you want to send the message to.
Message The message that you want to send. This accepts HTML but be sure to escape characters.

Example
<a href="javascript:;" onClick="jqac.arrowchat.sendMessage('53', 'You have been warned by an Admin');">Warn User</a>
<a href="javascript:;" onClick="jqac.arrowchat.sendMessage('<?php echo getUserDetails()->user_id; ?>', 'You have been warned by an Admin');">Warn User</a>

Open Chat Room


The chatroom('{CHAT ROOM ID}') API will automatically open a chat room window with a specific ID.


Parameters
Chat Room ID This is the chat room ID that you want to open.

Example
<a href="javascript:;" onClick="jqac.arrowchat.chatroom('1');">Open Chat Room</a>

Video Chat


The videoWith('{RANDOM ROOM ID}') API will automatically open a video chat window with a specific ID. You can pair this with the sendMessage('{USER ID}', '{MESSAGE}') API in order to invite someone to a video chat.


Parameters
Random Room ID This is a random video chat room ID that you make up. We suggest letters and numbers only.

Example
<a href="javascript:;" onClick="jqac.arrowchat.videoWith('1048365839');">Video Chat With Me</a>

Logout


The logout() API will allow you to instantly turn the ArrowChat bar into a logged out state.


Example
<a href="javascript:;" onClick="jqac.arrowchat.logout();">Logout</a>