API

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


Sections in this article

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
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;
	}
}

function arrowchatGetUser() {
	window.setTimeout(function() {
		if (typeof(jqac.arrowchat) !== "undefined") {
			jqac.arrowchat.getUser('53','userdetails');
		} else {
			arrowchatGetUser();
		}
	}, 50);
}

window.addEventListener('load', (event) => {
	arrowchatGetUser();
});

In the example above, the arrowchatGetUser function is sometimes necessary to ensure that ArrowChat has loaded before calling the API. All the function is doing is checking to see if ArrowChat is loaded before calling the API.


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.addEventListener('load', (event) => {
	setTimeout(function() {
		jqac.arrowchat.getUser('53','userdetails');
	}, 100);
});

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>