podchat
Version:
Javascript SDK to use POD's Chat Service
1,429 lines (1,249 loc) • 75.4 kB
HTML
<!DOCTYPE html>
<html>
<head>
<title>podChat</title>
<link href="http://fams.fanapsoft.com/TSK/favicon.ico" rel="icon" type="image/x-icon"/>
<!-- Development Mode -->
<script type="text/javascript" src="../src/utility/utility.js"></script>
<script type="text/javascript" src="../node_modules/podasync/src/utility/utility.js"></script>
<script type="text/javascript" src="../node_modules/podasync/src/network/socket.js"></script>
<script type="text/javascript" src="../node_modules/podasync/src/network/async.js"></script>
<script type="text/javascript" src="../node_modules/crypto-js/crypto-js.js"></script>
<script type="text/javascript" src="../node_modules/dexie/dist/dexie.min.js"></script>
<script type="text/javascript" src="../src/chat.js"></script>
<!-- Production Mode -->
<!--<script type="text/javascript" src="podchat.js"></script>-->
<!--<script type="text/javascript" src="podchat-browser.min.js"></script>-->
<script type="text/javascript">
// Developement
var PodChat = window.POD.Chat;
// Production
// var PodChat = window.PodChat;
var params = {
appId: new Date().getTime(),
/**
* ActiveMQ Config
*/
// protocol: "queue",
// queueHost: "10.56.16.25",
// queuePort: "61613",
// queueUsername: "root",
// queuePassword: "zalzalak",
// queueReceive: "queue-in-amjadi-stomp",
// queueSend: "queue-out-amjadi-stomp",
// queueConnectionTimeout: 20000,
// serverName: "chat-server",
/**
* Main Server
*/
// socketAddress: 'wss://msg.pod.ir/ws', // {**REQUIRED**} Socket Address
// ssoHost: 'https://accounts.pod.ir', // {**REQUIRED**} Socket Address
// platformHost: 'https://api.pod.ir/srv/core', // {**REQUIRED**} Platform Core Address
// fileServer: 'https://core.pod.ir', // {**REQUIRED**} File Server Address
// podSpaceFileServer: 'https://podspace.pod.ir', // {**REQUIRED**} File Server Address
// serverName: 'chat-server', // {**REQUIRED**} Server to to register on
/**
* Sand Box
*/
socketAddress: "wss://chat-sandbox.pod.ir/ws",
ssoHost: "https://accounts.pod.ir",
platformHost: "https://sandbox.pod.ir:8043/srv/basic-platform",
fileServer: 'https://core.pod.ir',
podSpaceFileServer: 'https://podspace.pod.ir',
serverName: "chat-server",
/**
* PodSpace test
*/
// socketAddress: "ws://pardisbus.pod.ir/ws", // {**REQUIRED**} Socket Address
// ssoHost: "https://accounts.pod.ir", // {**REQUIRED**} Socket Address
// platformHost: "https://sandbox.pod.ir:8043/srv/basic-platform", // {**REQUIRED**} Platform Core Address
// fileServer: 'https://core.pod.ir', // {**REQUIRED**} File Server Address
// podSpaceFileServer: 'https://podspace.pod.ir', // {**REQUIRED**} File Server Address
// serverName: "chatlocal-space", // {**REQUIRED**} Server to to register on
/**
* Integration
*/
// socketAddress: "ws://172.16.110.235:8003/ws",
// ssoHost: "http://172.16.110.76",
// platformHost: "http://172.16.110.235:8003/srv/bptest-core",
// fileServer: 'https://core.pod.ir',
// podSpaceFileServer: 'http://172.16.110.61:8780/podspace',
// serverName: "chatlocal",
grantDeviceIdFromSSO: false,
enableCache: false, // Enable Client side caching
fullResponseObject: false,
mapApiKey: '8b77db18704aa646ee5aaea13e7370f4f88b9e8c',
// typeCode: "talk",
token: "cfe592f32c084770a7af20222a19dd65",
// token: "f19933ae1b1e424db9965a243bf3bcd3", // {**REQUIRED**} SSO Token ZiZi
// token: "81025b3fbc1a4f7184c3600a2f874673", // {**REQUIRED**} SSO Token JiJi
// token: "3c4d62b6068043aa898cf7426d5cae68", // {**REQUIRED**} SSO Token FiFi
// token: "49c1a43116764ae2ab965a6c40bb46d3", // {**REQUIRED**} SSO Token Masoud
// token: "bebc31c4ead6458c90b607496dae25c6", // {**REQUIRED**} SSO Token Alexi
// token: "e4f1d5da7b254d9381d0487387eabb0a", // {**REQUIRED**} SSO Token Felfeli
// token: "6f5b9aba52414efaa0073a1178c5881f", // maBOT
wsConnectionWaitTime: 500, // Time out to wait for socket to get ready after open
connectionRetryInterval: 5000, // Time interval to retry registering device or registering server
connectionCheckTimeout: 10000, // Socket connection live time on server
messageTtl: 24 * 60 * 60, // Message time to live (1 day in seonds)
reconnectOnClose: true, // auto connect to socket after socket close
httpRequestTimeout: 30000,
httpUploadRequestTimeout: 0, // 0 means No timeout
asyncLogging: {
onFunction: true, // log main actions on console
// onMessageReceive: true, // log received messages on console
// onMessageSend: true, // log sent messaged on console
// actualTiming: true // log actual functions running time
}
};
var chatAgent = new PodChat(params),
PID,
P2P_THREAD_ID = 293;
chatAgent.on("chatReady", function () {
/*******************************************************
* U S E R *
*******************************************************/
// console.log('sending seen');
// chatAgent.seen({
// messageId: 109291,
// ownerId: 254
// })
// chatAgent.getAllUnreadMessagesCount({}, function(result){
// console.log('All unread messages count is: ', result);
// });
/**
* Get User Info
*/
// getUserInfo();
// chatAgent.startTyping({
// threadId: 4441
// });
//
// setTimeout(function () {
// chatAgent.stopTyping();
// }, 15000);
/*******************************************************
* T H R E A D S *
*******************************************************/
/**
* GET THREADS
* @param count
* @param offset
* @param threadIds
* @param name
*/
// getThreads({
// count: 50,
// offset: 0,
// // threadIds: [312, 1210],
// threadName: "فرهاد"
// });
/**
* CREATE THREAD (Creates Group)
* @param invitees
* @param threadType
*/
// createThread([{
// id: 581,
// type: "TO_BE_USER_CONTACT_ID"
// }, {
// id: 582,
// type: "TO_BE_USER_CONTACT_ID"
// }], "NORMAL");
/**
* CREATE THREAD (Creates P2P Chat with a specific user)
* @param contactId
*/
// createThread({id: 121, type: "TO_BE_USER_ID"});
/**
* GET THREAD PARTICIPANTS
* @param threadId
*/
// getThreadParticipants(293);
/**
* ADD PARTICIPANTS
* @param threadId
* @param contacts {Array} CONTACT ID
*/
// addParticipants(8088, 'contact', [7741]);
// addParticipants(8088, 'username', ['poddraw']);
// addParticipants(7548, 'coreuserid', [919]); //15508?
/**
* REMOVE PARTICIPANTS
* @param threadId
* @param participants {Array} USER ID
*/
// removeParticipants(3, [4]);
/**
* LEAVE THREAD
* @param threadId
*/
// leaveThread(3);
/**
* GET THREAD HISTORY
* @param count
* @param offset
* @param threadId
* @param firstMessageId
* @param lastMessageId
* @param metaQuery
* @param query
*/
// getHistory({
// count: 50,
// offset: 0,
// threadId: 47596,
// // firstMessageId: 17035,
// // order: "ASC",
// // lastMessageId: 17052,
// // metadataCriteria: {
// // "field": "type",
// // "has": "BOT_",
// // "and": [{
// // "field": "id",
// // "is": "1534835339446"
// // }]
// // },
// // query: "query",
// messageType: 'voice'
// });
/**
* GET SINGLE MESSAGE
* @param threadId
* @param messageId
*/
// getSingleMessage(293, 13698);
/**
* MUTE THREAD
* @param threadId
*/
// muteThread(3);
/**
* UNMUTE THREAD
* @param threadId
*/
// unMuteThread(3);
/**
* UPDATE THREAD INFO
* @param threadId
*/
// TODO: Check the image property
// chatAgent.updateThreadInfo({
// threadId: 51163,
// image: JSON.stringify({
// fileHash: "16e37b412fe-0.9111035145050199",
// link: "https://core.pod.ir/nzh/image?imageId=333415&hashCode=16e37b412fe-0.9111035145050199"
// }),
// description: "توضیحات ترد جدید",
// title: "عنوان ترد",
// metadata: {
// id: 1152,
// owner: "masoudmanson",
// name: "John Doe"
// }
// }, function(result) {
// console.log(result);
// });
/**
* SPAM P2P THREAD
* @param threadId
*/
// chatAgent.spamPvThread({
// threadId: 1020
// }, function(result) {
// console.log(result);
// });
/*******************************************************
* C O N T A C T S *
*******************************************************/
/**
* GET CONTACTS
*/
// getContacts({
// // contactId: "7741",
// // cellphoneNumber: "912",
// // email: "gmail.com",
// // query: "بهنام",
// // uniqueId: "672803e8-455f-4201-b0d6-64216b19679a"
// });
/**
* BLOCK CONTACT
* @param contactId
*/
// blockContact(563);
/**
* GET BLOCKED CONTACTS LIST
* @param count
* @param offset
*/
// getBlockedList();
/**
* UNBLOCK CONTACT
* @param blockId
*/
// unblockContact(83);
/**
* ADD CONTACTS
* @param firstName
* @param lastName
* @param cellphoneNumber
* @param email
*/
// var addContactInstantResult = chatAgent.addContacts({
// firstName: "حامد",
// lastName: "مهرآرا",
// cellphoneNumber: "09188644304",
// email: "hamed.m844a@gmail.com"
// }, function(result) {
// console.log(result);
// });
/**
* UPDATE CONTACTS
* @param id
* @param firstName
* @param lastName
* @param cellphoneNumber
* @param email
*/
// chatAgent.updateContacts({
// id: "716",
// firstName: "حامد",
// lastName: "مهرآرا",
// cellphoneNumber: "09122903204",
// email: "h.mehrara@fanap.ir"
// }, function (result) {
// console.log(result.result);
// });
/**
* REMOVE CONTACTS
* @param id
*/
// chatAgent.removeContacts({
// id: "1821"
// }, function(result) {
// console.log(result);
// });
/**
* SEARCH CONTACTS
* @link http://sandbox.pod.land:8080/apidocs/swagger-ui.html?srv=/nzh/listContacts
*/
// chatAgent.searchContacts({
// // cellphoneNumber: "0912", // LIKE
// // id: 563, // EXACT
// // firstName: "Hamid", // LIKE
// // lastName: "ra", // LIKE
// // email: "m", // LIKE
// // uniqueId: "f10c94f7-3013-4e34-9b3e-6a3bd25ce2a6", // EXACT
// // q: "v" // LIKE in firstName, lastName, email
// }, function (result) {
// if (!result.hasError) {
// console.log(result);
// }
// });
/*******************************************************
* M E S S A G E S *
*******************************************************/
/**
* SEND MESSAGE IN THREAD
* @param threadId
* @param newMessage
* @param metadata
*/
// sendMessage(15, "PooPoo This is a Sample Message at " + new Date(), {
// id: new Date().getTime(),
// type: "BOT_MESSAGE",
// owner: "Masoud"
// });
/**
* SEND FILE MESSAGE IN THREAD
* @param threadId
* @param file
* @param caption
* @param metadata
*/
// sendFileMessageUsecase(15, __dirname + "/test/image.jpg", "Sample file description", {
// custom_name: "John Doe"
// });
/**
* SEND BOT MESSAGE IN THREAD
* @param messageId
* @param receiverId
* @param newMessage
*/
// sendBotMessage(14954, 121, {
// command: "reverse",
// lat: "35.7003510",
// lng: "51.3376472"
// });
/**
* EDIT MESSAGE IN THREAD
* @param messageId 325 editable: false
* @param newMessage
*/
// editMessage(1, "This message has been edited at " + new Date());
/**
* DELETE MESSAGE IN THREAD
* @param {int} messageId
* @param {boolean} deleteForAll
*/
// deleteMessage(15672, true);
/**
* REPLY TO MESSAGE
* @param threadId
* @param messageId
*/
// replyMessage(6848, 108287, "This is a reply to message #108287 at " + new Date());
/**
* FORWARD MESSAGE
* @param destination
* @param messageIds
*/
// forwardMessage(1431, [17259, 17258]);
/**
* GET MESSAGE SEEN LIST
* @param messageId
*/
// chatAgent.getMessageSeenList({
// messageId: 19623
// }, function(seenList) {
// console.log("Seen list", seenList);
// });
/**
* GET MESSAGE DELIVERED LIST
* @param messageId
*/
// chatAgent.getMessageDeliveredList({
// messageId: 19623
// }, function(seenList) {
// console.log("Delivery list", seenList);
// });
/*******************************************************
* F I L E U P L O A D S *
*******************************************************/
/**
* UPLOAD IMAGE
* @param {string} image Image path
* @param {int} xC Crop start x coordinates
* @param {int} yC Crop start y coordinates
* @param {int} hC Crop height
* @param {int} wC Crop width
*/
// uploadImage(__dirname + "/test/test.jpeg", 0, 0, 400, 400);
/**
* GET IMAGE
* @param {int} imageId Image ID
* @param {string} hashCode Hash Code
*/
// getImage(2531, '1649d4e932a-0.8852815409984853');
/**
* UPLOAD FILE
* @param {string} file File path
*/
// uploadFile(__dirname + "/test/test.txt");
/**
* GET FILE
* @param {int} fileId Image ID
* @param {string} hashCode Hash Code
* @param {boolean} downloadable Downloadable link or not?
*/
// getFile(344, '196CHI61NUROW8S1', true);
/*******************************************************
* N E S H A N M A P *
*******************************************************/
/**
* Get Address of a GeoLocation point
*
* @param {float} lat Latitute of the Location
* @param {float} lng Longtitute of the Location
*/
// chatAgent.mapReverse({
// lat: 35.7003508,
// lng: 51.3376460
// }, function(result) {
// console.log(result);
// });
/**
* Get nearby places names as "term" keyword
* around the given GeoLocation
*
* @param {float} lat Latitute of the Location
* @param {float} lng Longtitute of the Location
* @param {string} term Search term to be searched
*/
// chatAgent.mapSearch({
// lat: 35.7003508,
// lng: 51.3376460,
// term: "فروشگاه"
// }, function(result) {
// console.log(result);
// });
/**
* Get routing between two given GeoLocations
*
* @param {object} origin Lat & Lng of Origin as a JSON
* @param {object} destination Lat & Lng of Destination as a JSON
* @param {boolean} alternative Give Alternative Routs too
*/
// chatAgent.mapRouting({
// origin: {
// lat: 35.7003508,
// lng: 51.3376460
// },
// destination: {
// lat: 35.7343510,
// lng: 50.3376472
// },
// alternative: true
// }, function(result) {
// console.log(result);
// });
/**
* Get Static Image of a GeoLocation
*
* @param {string} type Map style (default standard-night)
* @param {int} zoom Map zoom (default 15)
* @param {object} center Lat & Lng of Map center as a JSON
* @param {int} width width of image in pixels (default 800px)
* @param {int} height height of image in pixels (default 600px)
*/
// chatAgent.mapStaticImage({
// type: "standard-night",
// zoom: 15,
// center: {
// lat: 35.7003508,
// lng: 51.3376462
// },
// width: 800,
// height: 500
// }, function(result) {
// console.log(result);
// });
// var sendLocationMessageInstantResponse = chatAgent.sendLocationMessage({
// mapType: "standard-night",
// mapZoom: 16,
// mapCenter: {
// lat: 35.7034534,
// lng: 51.3776390
// },
// mapWidth: 1200,
// mapHeight: 500,
// threadId: 54436,
// userGroupHash: '5GW93QH695O7HC',
// caption: "This is the Address on map!",
// systemMetadata: {
// time: new Date()
// }
// }, function(result) {
// console.log(result);
// });
//
// console.log('sendLocationMessageInstantResponse', sendLocationMessageInstantResponse);
/*
* Create Bot
*/
// chatAgent.createBot({
// botName: 'metalBOT'
// }, (result) => {
// console.log('createBot ersult in index', result.result);
// });
/*
* Define Bot Commands
*/
// chatAgent.defineBotCommand({
// botName: 'metalBOT',
// commandList: ['start']//'hola', 'adios', 'gracias', 'denada']
// }, function(result) {
// console.log('Define Bot Command result', result);
// });
// chatAgent.getThreadParticipants({
// threadId: 42076
// }, function(result) {
// console.log(result);
// });
// addParticipants(42076, 'username', ['spanishBOT']);
/*
* Start Bot
*/
// chatAgent.startBot({
// botName: 'spanishBOT',
// threadId: 42076
// }, (result) => {
// console.log('Start Bot result', result);
// });
/*
* Stop Bot
*/
// chatAgent.stopBot({
// botName: 'yoBOT',
// threadId: 7411
// }, (result) => {
// console.log('Stop Bot result', result);
// });
});
/**
* Listen to Error Messages
*/
chatAgent.on("error", function (error) {
console.log("Error ", error);
// console.log("Error ", error.error);
});
/**
* Listen to Chat State Changes
*/
chatAgent.on("chatState", function (chatState) {
});
/**
* Listen to File Upload Events
*/
chatAgent.on("fileUploadEvents", function (event) {
var type = event.type;
console.log(event);
});
chatAgent.on("contactEvents", function (event) {
if (event.type == 'CONTACTS_SYNCED') {
console.log('Core contacts have been successfully synced with chat server.');
}
});
/**
* Listen to Thread Events
*/
chatAgent.on("threadEvents", function (event) {
var type = event.type;
console.log(event);
switch (type) {
case "THREAD_LAST_ACTIVITY_TIME":
break;
case "THREAD_NEW":
break;
case "THREAD_ADD_PARTICIPANTS":
break;
case "THREAD_REMOVE_PARTICIPANTS":
break;
case "THREAD_LEAVE_PARTICIPANT":
break;
case "THREAD_REMOVED_FROM":
break;
case "THREAD_RENAME":
break;
case "THREAD_MUTE":
break;
case "THREAD_UNMUTE":
break;
case "THREAD_INFO_UPDATED":
break;
case "THREAD_UNREAD_COUNT_UPDATED":
break;
default:
break;
}
});
/**
* Listen to Message Events
*/
var chatOnMessageEventsObject = chatAgent.on("messageEvents", function (event) {
var type = event.type,
message = event.result.message;
console.log(event);
switch (type) {
case "MESSAGE_NEW":
/**
* Sending Message Seen to Sender after 5 secs
*/
setTimeout(function () {
chatAgent.seen({
messageId: message.id,
ownerId: message.ownerId
});
}, 5000);
break;
case "MESSAGE_EDIT":
break;
case "MESSAGE_DELIVERY":
break;
case "MESSAGE_SEEN":
break;
default:
break;
}
});
/**
* Listen to System Events
*/
chatAgent.on("systemEvents", function (event) {
var type = event.type;
console.log(event);
switch (type) {
case "IS_TYPING":
console.log(event.result.user.user + " is typing in thread #" + event.result.thread);
break;
default:
break;
}
});
/**
* Listen to User Events
*/
chatAgent.on('userEvents', function (event) {
var type = event.type;
console.log(event);
switch (type) {
case 'CHAT_PROFILE_UPDATED':
console.log('Chat Profile Has Been Updated', event);
break;
default:
break;
}
});
/**
* Local Functions
*/
function getUserInfo() {
chatAgent.getUserInfo(function (userInfo) {
console.log(userInfo);
});
}
function getThreads(params) {
var instantResult = chatAgent.getThreads(params, function (threadsResult) {
if (!threadsResult.hasError) {
var threadsCount = threadsResult.result.contentCount;
var threads = threadsResult.result.threads;
console.log(threadsResult);
}
});
// console.log(instantResult);
}
function getThreadParticipants(threadId) {
var getParticipantsParams = {
count: 50,
offset: 0,
threadId: threadId,
// name: "مهیار"
};
chatAgent.getThreadParticipants(getParticipantsParams, function (participantsResult) {
if (!participantsResult.hasError) {
console.log(participantsResult);
}
});
}
function addParticipants(threadId, type, participants) {
switch (type) {
case 'contact':
chatAgent.addParticipants({
threadId: threadId,
contacts: participants
}, function (result) {
console.log(result);
});
break;
case 'username':
chatAgent.addParticipants({
threadId: threadId,
usernames: participants
}, function (result) {
console.log(result);
});
case 'coreuserid':
chatAgent.addParticipants({
threadId: threadId,
coreuserids: participants
}, function (result) {
console.log(result);
});
break;
}
}
function removeParticipants(threadId, participants) {
chatAgent.removeParticipants({
threadId: threadId,
participants: participants
}, function (result) {
// console.log(result);
});
}
function leaveThread(threadId) {
chatAgent.leaveThread({
threadId: threadId
}, function (result) {
// console.log(result);
});
}
function getContacts(params) {
chatAgent.getContacts(params, function (contactsResult) {
if (!contactsResult.hasError) {
console.log(contactsResult);
}
});
}
function getSingleMessage(threadId, messageId) {
chatAgent.getHistory({
offset: 0,
threadId: threadId,
id: messageId
}, function (historyResult) {
if (!historyResult.hasError) {
console.log(historyResult.result.history);
}
});
}
function getHistory(params) {
var test = chatAgent.getHistory(params, function (historyResult) {
if (!historyResult.hasError) {
console.log(historyResult);
// for(var i=0; i<historyResult.result.history.length; i++) {
// console.log(historyResult.result.history[i].id, historyResult.result.history[i].systemMetadata);
// }
}
});
// console.log(test);
}
function sendMessage(threadId, message, metadata) {
sendChatParams = {
threadId: threadId,
textMessage: message,
messageType: 0,
systemMetadata: metadata
};
var sentMesageUniqueId = chatAgent.sendTextMessage(sendChatParams, {
onSent: function (result) {
console.log(result.uniqueId + ' \t has been Sent!');
},
onDeliver: function (result) {
console.log(result.uniqueId + ' \t has been Delivered!');
},
onSeen: function (result) {
console.log(result.uniqueId + ' \t has been Seen!');
}
});
}
function sendFileMessageUsecase(threadId, file, caption, metadata) {
var instantResult = chatAgent.sendFileMessage({
threadId: threadId,
file: file,
content: caption,
systemMetadata: metadata
}, {
onSent: function (result) {
console.log(result.uniqueId + " \t has been Sent!");
},
onDeliver: function (result) {
console.log(result.uniqueId + " \t has been Delivered!");
},
onSeen: function (result) {
console.log(result.uniqueId + " \t has been Seen!");
}
});
console.log("\nInstant Result For sendFileMessage:\n", instantResult);
}
function sendBotMessage(messageId, receiverId, message, metadata) {
sendChatParams = {
messageId: messageId,
content: message,
receiver: receiverId,
systemMetadata: metadata
};
var mim = chatAgent.sendBotMessage(sendChatParams, {
onSent: function (result) {
console.log(result.uniqueId + " \t has been Sent!");
},
onDeliver: function (result) {
console.log(result.uniqueId + " \t has been Delivered!");
}
});
console.log(mim);
}
function editMessage(messageId, newMessage) {
editChatParams = {
messageId: messageId,
content: newMessage
};
chatAgent.editMessage(editChatParams, function (result) {
console.log(result);
});
}
function deleteMessage(messageId, deleteForAll) {
if (typeof deleteForAll == "undefined") {
deleteForAll = false;
}
chatAgent.deleteMessage({
messageId: messageId,
deleteForAll: deleteForAll
}, function (result) {
console.log(result);
});
}
function replyMessage(threadId, messageId, message) {
replyChatParams = {
threadId: threadId,
repliedTo: messageId,
content: message,
systemMetadata: {id: 1, name: "Masoud"},
metadata: {id: 2, name: "Pooria"}
};
chatAgent.replyTextMessage(replyChatParams, {
onSent: function (result) {
console.log(result.uniqueId + " \t has been Sent! (Reply)");
},
onDeliver: function (result) {
console.log(result.uniqueId + " \t has been Delivered! (Reply)");
},
onSeen: function (result) {
console.log(result.uniqueId + " \t has been Seen! (Reply)");
}
});
}
function forwardMessage(destination, messageIds) {
chatAgent.forwardMessage({
subjectId: destination,
content: JSON.stringify(messageIds)
}, {
onSent: function (result) {
console.log(result.uniqueId + " \t has been Sent! (FORWARD)");
},
onDeliver: function (result) {
console.log(result.uniqueId + " \t has been Delivered! (FORWARD)");
},
onSeen: function (result) {
console.log(result.uniqueId + " \t has been Seen! (FORWARD)");
}
});
}
function createThread(invitees, threadType) {
if (typeof threadType == "string") {
threadTypeText = threadType;
} else {
threadTypeText = "NORMAL";
}
createThreadParams = {
title: "Thread Title Sample",
type: threadTypeText,
invitees: []
};
if (Array.isArray(invitees)) {
for (var i = 0; i < invitees.length; i++) {
invitee = formatDataToMakeInvitee({
id: invitees[i].id,
type: invitees[i].type
});
if (invitee) {
createThreadParams.invitees.push(invitee);
}
}
} else {
invitee = formatDataToMakeInvitee({
id: invitees.id,
type: invitees.type
});
if (invitee) {
createThreadParams.invitees.push(invitee);
}
}
chatAgent.createThread(createThreadParams, function (createThreadResult) {
console.log(createThreadResult);
});
}
function renameThread(threadId, newName) {
renameThreadParams = {
title: newName,
threadId: threadId
};
chatAgent.renameThread(renameThreadParams, function (renameThreadResult) {
console.log(renameThreadResult);
});
}
function muteThread(threadId) {
var data = {
subjectId: threadId
}
chatAgent.muteThread(data, function (result) {
if (!result.hasError) {
console.log("Threaded has been successfully muted!");
}
console.log(result);
});
}
function blockContact(contactId) {
var data = {
contactId: contactId
}
chatAgent.block(data, function (result) {
if (!result.hasError) {
console.log("Contact has been successfully Blocked!");
}
console.log(result);
});
}
function unblockContact(blockId) {
var data = {
blockId: blockId
}
chatAgent.unblock(data, function (result) {
if (!result.hasError) {
console.log("Contact has been successfully unBlocked!");
}
console.log(result);
});
}
function getBlockedList() {
var data = {
count: 50,
offset: 0
}
chatAgent.getBlocked(data, function (result) {
if (!result.hasError) {
console.log(result);
}
});
}
function unMuteThread(threadId) {
var data = {
subjectId: threadId
}
chatAgent.unMuteThread(data, function (result) {
if (!result.hasError)
console.log("Threaded has been successfully unMuted!");
console.log(result);
});
}
function formatDataToMakeInvitee(messageContent) {
var inviteeData = {
id: messageContent.id,
idType: messageContent.type
};
return inviteeData;
}
function uploadImage(image, xC, yC, hC, wC) {
chatAgent.uploadImage({
image: image,
xC: xC,
yC: yC,
hC: hC,
wC: wC
}, function (result) {
console.log(result);
if (!result.hasError) {
var image = result.result;
console.log("Image has been Successfully Uploaded => \n\n", image);
}
});
}
function getImage(imageId, hashCode) {
chatAgent.getImage({
imageId: imageId,
hashCode: hashCode
}, function (result) {
if (!result.hasError) {
console.log("Image has been successfully received => \n", result.result);
}
});
}
function uploadFile(file) {
chatAgent.uploadFile({
file: file
}, function (result) {
console.log(result);
if (!result.hasError) {
var file = result.result;
console.log("File has been Successfully Uploaded => \n", file);
}
});
}
function getFile(fileId, hashCode, downloadable) {
chatAgent.getFile({
fileId: fileId,
hashCode: hashCode,
downloadable: downloadable
}, function (result) {
if (!result.hasError) {
console.log("File has been successfully received => \n", result.result);
}
});
}
function removeContacts(id) {
chatAgent.removeContacts({
id: id
}, function (result) {
console.log(result);
});
}
</script>
<style>
.btn {
padding: 10px 25px;
color: #fff;
background-color: #222;
border: none !important;
text-decoration: none;
margin: 10px 15px;
display: inline-block;
}
#reconnect,
#clearCache,
#deleteCache {
display: inline-block;
font-size: 12px;
color: #aaa;
margin-left: 10px;
cursor: pointer;
}
</style>
</head>
<body style="max-width: 600px;">
<p>POD CHAT <span id="reconnect">Reconnect...</span> | <span id="clearCache">Clear User Cache</span> | <span
id="deleteCache">Delete Cache</span></p>
Token: <input type="text" id="tokenInput" autocomplete="on" width="500">
<button id="tokenInputSet">Set Token</button>
<br><br>
<form>
<fieldset>
<legend>General Functionalities</legend>
<label for="g-p2p">P2P Thread Id : </label>
<input type="text" name="p2p" id="g-p2p" value="312">
<label for="g-p2p-off">offset: </label>
<input type="text" name="p2poff" id="g-p2p-off" value="0" size="2">
<label for="g-p2p-count">Count: </label>
<input type="text" name="p2pcount" id="g-p2p-count" value="10" size="2">
<br>
<a class="btn" href="#" onclick="getContacts({
count:document.getElementById('g-p2p-count').value,
offset: document.getElementById('g-p2p-off').value
})">Get Contacts</a>
<a class="btn" href="#" onclick="getThreads({
count:document.getElementById('g-p2p-count').value,
offset: document.getElementById('g-p2p-off').value
})">Get Threads</a>
<a class="btn" href="#" onclick="getHistory({
// fromTimeFull: 1557830885624256000,
// toTimeFull: 1558247572310448000,
count:document.getElementById('g-p2p-count').value,
offset: document.getElementById('g-p2p-off').value,
threadId: document.getElementById('g-p2p').value});">Get History</a>
<a class="btn" href="#" onclick="getThreadParticipants(document.getElementById('g-p2p').value)">Get Thread
Participants</a>
<a class="btn" href="#" onclick="chatAgent.getThreadAdmins({threadId:document.getElementById('g-p2p').value}, function(res){
console.log(res);
})">Get Thread Admins</a>
<a class="btn" href="#" onclick="leaveThread(document.getElementById('g-p2p').value)">Leave Thread</a>
<br>
<br>
</fieldset>
</form>
<br>
<hr>
<br>
<form>
<fieldset>
<legend>Create Thread</legend>
<label for="createThreadTitle">Thread title</label>
<input type="text" name="createThreadTitle" id="createThreadTitle" value="Thread Title">
<label for="createThreadPublicName">Thread Public Name</label>
<input type="text" name="createThreadPublicName" id="createThreadPublicName" value="TPN">
<label for="createThreadType">Thread Type</label>
<select name="createThreadType" id="createThreadType">
<option value="NORMAL">NORMAL</option>
<option value="OWNER_GROUP">OWNER_GROUP</option>
<option value="PUBLIC_GROUP">PUBLIC_GROUP</option>
<option value="CHANNEL_GROUP">CHANNEL_GROUP</option>
<option value="CHANNEL">CHANNEL</option>
</select>
<br>
<label for="createThreadImage">Thread img</label>
<input type="text" name="createThreadImage" id="createThreadImage" value="">
<label for="createThreadDesc">Thread Desc</label>
<input type="text" name="createThreadDesc" id="createThreadDesc" value="Thread Description">
<br>
<label for="createThreadMetadata">Thread Metadata (JSON)</label>
<textarea name="createThreadMetadata" id="createThreadMetadata" rows="4" cols="70"></textarea>
<br>
<label for="createThreadInvitees">Thread Invitees (JSON Array)</label>
<textarea name="createThreadInvitees" id="createThreadInvitees" rows="10" cols="70">
[{
"id": 122,
"type": "TO_BE_USER_CONTACT_ID"
}, {
"id": 1102,
"type": "TO_BE_USER_CONTACT_ID"
}]
</textarea>
<button type="button" name="button" id="createThreadButton">Create Thread</button>
</fieldset>
</form>
<br>
<hr>
<br>
<form>
<fieldset>
<legend>Create Thread With File Message</legend>
<label for="createThreadWithFileFile">File : </label>
<input type="file" name="createThreadWithFileFile" id="createThreadWithFileFile">
<br>
<label for="createThreadWithFileTitle">Thread title</label>
<input type="text" name="createThreadWithFileTitle" id="createThreadWithFileTitle" value="Thread Title">
<br>
<label for="createThreadWithFileType">Thread Type</label>
<select name="createThreadWithFileType" id="createThreadWithFileType">
<option value="NORMAL">NORMAL</option>
<option value="OWNER_GROUP">OWNER_GROUP</option>
<option value="PUBLIC_GROUP">PUBLIC_GROUP</option>
<option value="CHANNEL_GROUP">CHANNEL_GROUP</option>
<option value="CHANNEL">CHANNEL</option>
</select>
<br>
<label for="createThreadWithMessageType">Message Type</label>
<select name="createThreadWithMessageType" id="createThreadWithMessageType">
<option value="TEXT">TEXT</option>
<option value="POD_SPACE_PICTURE">POD_SPACE_PICTURE</option>
<option value="POD_SPACE_VIDEO">POD_SPACE_VIDEO</option>
<option value="POD_SPACE_SOUND">POD_SPACE_SOUND</option>
<option value="POD_SPACE_VOICE">POD_SPACE_VOICE</option>
<option value="POD_SPACE_FILE">POD_SPACE_FILE</option>
<option value="LINK">LINK</option>
</select>
<br>
<label for="createThreadWithFileDesc">Thread Desc</label>
<input type="text" name="createThreadWithFileDesc" id="createThreadWithFileDesc" value="Thread Description">
<br>
<label for="createThreadWithFileCaption">FileMessage caption</label>
<input type="text" name="createThreadWithFileCaption" id="createThreadWithFileCaption" value="Caption">
<br>
<label for="createThreadWithFileMetadata">Thread Metadata (JSON)</label>
<textarea name="createThreadWithFileMetadata" id="createThreadWithFileMetadata" rows="4" cols="70"></textarea>
<br>
<label for="createThreadWithFileInvitees">Thread Invitees (JSON Array)</label>
<textarea name="createThreadWithFileInvitees" id="createThreadWithFileInvitees" rows="7" cols="70">
[{
"id": 122,
"type": "TO_BE_USER_CONTACT_ID"
}, {
"id": 1102,
"type": "TO_BE_USER_CONTACT_ID"
}]
</textarea>
<button type="button" name="button" id="createThreadWithFileButton">Create Thread</button>
</fieldset>
</form>
<br>
<hr>
<br>
<form>
<fieldset>
<legend>Add Participant to Thread</legend>
<label for="apThread">Thread Id</label>
<input type="text" name="apThread" id="apThread">
<br>
<label for="apList">Participants (Array of IDs):</label>
<input type="text" name="apList" id="apList" placeholder="1, 2, 3, ...">
<button type="button" name="button" id="apButton">Add Participants</button>
</fieldset>
</form>
<br>
<hr>
<br>
<form>
<fieldset>
<legend>Send Text Message</legend>
<label for="sendTextThread">Thread Id</label>
<input type="text" name="sendTextThread" id="sendTextThread">
<br>
<label for="sendTextMessage">Message :</label>
<textarea type="text" name="sendTextMessage" id="sendTextMessage"></textarea>
<button type=