UNPKG

podchat-browser

Version:

Javascript SDK to use POD's Chat Service - Browser Only

1,477 lines (1,291 loc) 147 kB
<!DOCTYPE html> <html> <head> <title>PodChat Browser Version</title> <link href="https://talk.pod.ir/styles/images/_common/favicon-32x32.png" rel="icon" type="image/x-icon"/> <!-- Development Mode --> <script src="../dist/podchat-browser-bundle.js"></script> <script type="text/javascript" src="./config.js"></script> <!-- Production Mode --> <!-- <script type="text/javascript" src="/dist/podchat-10.13.8.js"></script>--> <!--<script type="text/javascript" src="podchat-browser.min.js"></script>--> <script type="text/javascript"> // Development var PodChat = window.POD.Chat; var env = 'sandbox'; // main | sandbox | integration var params = { appId: new Date().getTime(), /** * ActiveMQ Config */ // protocol: "queue", // queueHost: CONFIG.queueHost, // queuePort: CONFIG.queuePort, // queueUsername: CONFIG.queueUsername, // queuePassword: CONFIG.queuePassword, // queueReceive: CONFIG.queueReceive, // queueSend: CONFIG.queueSend, // queueConnectionTimeout: 20000, // serverName: "chat-server", socketAddress: CONFIG[env].socketAddress, ssoHost: CONFIG[env].ssoHost, platformHost: CONFIG[env].platformHost, fileServer: CONFIG[env].fileServer, podSpaceFileServer: CONFIG[env].podSpaceFileServer, serverName: CONFIG[env].serverName, callServerName: CONFIG[env].callServerName, // protocol: "webrtc", webrtcConfig: { baseUrl: "https://async-chat.fanapsoft.ir/webrtc/",//"https://172.16.110.26/webrtc/",//"http://localhost:3000/webrtc/",//"http://109.201.0.97/webrtc/",//"https://172.16.110.26:443/webrtc/", configuration: { bundlePolicy: "balanced", iceTransportPolicy: "relay", iceServers: [{ "urls": "turn:turnsandbox.podstream.ir:3478", "username": "mkhorrami", "credential": "mkh_123456" }] } }, token: CONFIG.token, grantDeviceIdFromSSO: false, enableCache: false, fullResponseObject: true, mapApiKey: CONFIG.mapApiKey, typeCode: "default", typeCodeOwnerId: 1, typeCodesList: [ { typeCode: "default", ownerId: 1 }, { typeCode: "RequestOTP", ownerId: undefined } ], wsConnectionWaitTime: 500, connectionRetryInterval: 5000, connectionCheckTimeout: 10000, messageTtl: 24 * 60 * 60, reconnectOnClose: true, httpRequestTimeout: 30000, httpUploadRequestTimeout: 0, forceWaitQueueInMemory: true, asyncRequestTimeout: 50000, callRequestTimeout: 5000, callOptions: { callNoAnswerTimeout: 20000, // callSocketAddress: "wss://online-stream.pod.ir/gsthandler", // callTurnIp: "188.75.65.144", // callSocketAddress: "wss://46.32.6.187/gsthandler", callTurnIp: "46.32.6.188", callDivId: "call-div", callVideo: { minWidth: 320, minHeight: 180 }, // callAudioTagClassName: "podcall-audio", callVideoTagClassName: "podcall-video" }, asyncLogging: { onFunction: true, consoleLogging: true, onMessageReceive: false, onMessageSend: false, actualTiming: false }, clientName: 'SDK Default example', // protocol: 'webrtc', protocolSwitching: { webrtc: 1, websocket: 2 }, webrtcConfig: { baseUrl: "async-webrtc.pod.ir", // https://msgkhatam.pod.ir/webrtc/",// https://async-webrtc.pod.ir/webrtc/ //"https://172.16.110.26/webrtc/",//"http://localhost:3000/webrtc/",//"http://109.201.0.97/webrtc/", basePath: "/webrtc/", configuration: { bundlePolicy: "balanced", iceTransportPolicy: "relay", iceServers: [{ "urls": "turn:turn1-async.podstream.ir:3478", "username": "mkhorrami", "credential": "mkh_123456" }] } }, }; var chatAgent = new PodChat(params); /* * Main Chat Ready Listener */ var chatReadyInstance = chatAgent.on("chatReady", function () { // // chatAgent.deleteThread({ // threadId: 200000000000, // }, function(result) { // console.log(result); // }); // chatAgent.getMutualGroups({ // user: { // id: 'h.amouzegar', // idType: 'TO_BE_USER_USERNAME' // }, // offset: 0, // count: 5 // }, function(result) { // console.log(result) // }); // chatAgent.registerAssistant({ // assistants: [{ // contactType: 'default', // roleTypes: ['read_thread', 'edit_thread', 'add_rule_to_user'], // assistant: { // id: 'h.amouzegar', // idType: 'TO_BE_USER_USERNAME' // } // }] // }, function(result) { // console.log(result); // }); // chatAgent.deactivateAssistant({ // assistants: [{ // assistant: { // id: 'h.amouzegar', // idType: 'TO_BE_USER_USERNAME' // } // }] // }, function (result) { // console.log(result); // }); // chatAgent.getAssistantsList({ // contactType: 'default' // }, function(assistants) { // console.log({assistants}); // }); // chatAgent.getAssistantsHistory({ // // actionType: 'register' // // toTime: 1628509673879 // }, function(assistantsHistory) { // console.log({assistantsHistory}) // }); // chatAgent.blockAssistant({ // assistants: [{ // assistant: { // id: 'h.amouzegar', // idType: 'TO_BE_USER_USERNAME' // } // }] // }, function (result) { // console.log(result); // }); // chatAgent.unblockAssistant({ // assistants: [{ // assistant: { // id: 'h.amouzegar', // idType: 'TO_BE_USER_USERNAME' // } // }] // }, function (result) { // console.log(result); // }); // chatAgent.getBlockedAssistantsList({ // contactType: 'default' // }, function(assistants) { // console.log({assistants}); // }); // chatAgent.createTag({ // tagName: 'پابل' // }, function (result) { // console.log(result); // }); // chatAgent.editTag({ // tagId: 161, // tagName: 'تاک' // }, function (result) { // console.log(result); // }); // chatAgent.deleteTag({ // tagId: 161 // }, function (result) { // console.log(result); // }); // chatAgent.getTagList({}, function (result) { // console.log(result); // }); // chatAgent.addTagParticipants({ // tagId: 1, // threadIds: [40991, 40992] // }, function(result) { // console.log(result) // }); // chatAgent.removeTagParticipants({ // tagId: 1, // threadIds: [40991] // }, function(result) { // console.log(result) // }); // chatAgent.createSelfThread({ // description: 'Use this space to save messages for your own sake', // metadata: { // name: 'Masoud', // status: '😒' // } // }, function(result) { // console.log({result}); // }); // chatAgent.changeThreadPrivacy({ // threadId: 149486, // threadType: 'PUBLIC_GROUP', // uniqueName: 'takeGhadKeshide' // }, function(result) { // console.log(result); // }); // chatAgent.createBot({ // botName: 'clasorTestBOT', // }, function (res) { // console.log(res); // }); // chatAgent.getBotCommandsList({ // botName: 'talkyBOT' // }, function (res) { // console.log(res); // }); // // chatAgent.defineBotCommand({ // botName: 'takiBOT', // commandList: ['start', 'finish', 'scoreboard', 'dev'] // }, function (res) { // console.log(res); // }); // chatAgent.addParticipants({ // threadId: 149486, // usernames: ['takiBOT'] // }, function (res) { // console.log(res); // }); // removeParticipants(149486, [3945575]); // // chatAgent.startBot({ // threadId: 149486, // botName: 'takiBOT' // }, function (res) { // console.log(res); // }); // chatAgent.getThreadAllBots({threadId: 149486}, function (res) { // console.log(res) // }); // chatAgent.closeThread({ // threadId: 451618 // }, function (res) { // // console.log(res); // chatAgent.getThreads({}, function(threads) { // console.log(threads.result); // }); // }); // chatAgent.sendLocationPing({ // location: 'contacts' // }, function(res) { // console.log('Loation Ping has been sent', res); // }); // chatAgent.terminateCall({ // callId: 234 // }, function(res){ // console.log({res}) // }) // chatAgent.startCall({ // threadId: 4441, // type: 'voice', // // invitees: [ // // { // // idType: 'TO_BE_USER_CONTACT_ID', // // id: 934363 // // } // // ] // }, function(result) { // console.log({result}); // // // chatAgent.cancelCall({callId: event.result.callId}, function (res) { // // console.log({res}); // // }); // }); // chatAgent.getCallsList({ // type: 'video', // callIds: [273, 274], // name: 'فرهاد', // count: 50, // offset: 0, // creatorCoreUserId: 2648, // creatorSsoId: 131, // uniqueId: '3r42f-f242hf-u45bsd3-ber42', // contactType: 'default', // }, function (calls) { // console.log({calls}); // }); // chatAgent.getCallsToJoin({ // type: 'video', //Optional // name: 'فرهاد', //Optional // count: 50, //Optional // offset: 0, //Optional, // threadIds: [] //Optional // }, function (calls) { // console.log({calls}); // }); // chatAgent.deleteFromCallList({ // contactType: 'default', // callIds: [6900, 6901, 6902] // }, function (result) { // console.log(result) // }); // chatAgent.getContacts( // { // username: 'n.soltani' // }, function(res) { // console.log({res}) // } // ); // chatAgent.pinMessage({ // messageId: 601414, // notifyAll: true // }, function(res){ // console.log({res}); // }); /******************************************************* * U S E R * *******************************************************/ // console.log('sending seen'); // chatAgent.seen({ // messageId: 109291, // ownerId: 254 // }) // chatAgent.getCurrentUserRoles({ // threadId: 35316 // }, function(result) { // console.log(result); // }); // var currentUser = chatAgent.getCurrentUser(); // console.log(currentUser) // chatAgent.getAllUnreadMessagesCount({}, function(result){ // console.log('All unread messages count is: ', result); // }); /** * Get User Info */ // getUserInfo(); // chatAgent.updateChatProfile({ // bio: 'Whatever :|', // metadata: { // birthDate: '26 Jun 1991', // constellation: 'cancer ♋' // } // }, function(result) { // console.log(result) // }); // chatAgent.getUserNotSeenDuration({ // userIds: [164055, 366174] // }, function(result) { // console.log(result); // }); // chatAgent.startTyping({ // threadId: 13554 // }); // // 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": 934363, // "type": "TO_BE_USER_CONTACT_ID" // }, { // "id": 3459620, // "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(36038, '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 */ // chatAgent.getHistory({ // count: 50, // offset: 200, // threadId: 489068, // // fromTimeFull: 1611728867161577000, // order: 'asc', // // firstMessageId: 17035, // // order: "ASC", // // lastMessageId: 17052, // // metadataCriteria: { // // "field": "type", // // "has": "BOT_", // // "and": [{ // // "field": "id", // // "is": "1534835339446" // // }] // // }, // // query: "/start@takiBOT", // // messageType: 'sticker' // }, function (history) { // console.log(history) // }); /** * ARCHIVE/UNARCHIVE THREAD * @param threadId */ // chatAgent.archiveThread({ // threadId: 1111 // }, function (result){ // console.log(history) // }) // chatAgent.unArchiveThread({ // threadId: 1111 // }, function (result){ // console.log(history) // }) /** * 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(3459620); /** * GET BLOCKED CONTACTS LIST * @param count * @param offset */ // getBlockedList(); /** * UNBLOCK CONTACT * @param blockId */ // unblockContact(23602); /** * ADD CONTACTS * @param firstName * @param lastName * @param cellphoneNumber * @param email */ // var addContactInstantResult = chatAgent.addContacts({ // firstName: "Masoud", // lastName: "Amjadi", // cellphoneNumber: "091******", // email: "ma.amjadi@fanap.ir" // }, 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: 7742 // }, 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 */ // setInterval(function() { // sendMessage(4441, "PooPoo This is a Sample Message at " + new Date(), { // id: new Date().getTime(), // type: "BOT_MESSAGE", // owner: "Masoud" // }); // }, 1000); /** * 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(919202, "New message content goes here."); /** * DELETE MESSAGE IN THREAD * @param {int} messageId * @param {boolean} deleteForAll */ // deleteMessage(919192, true); /** * REPLY TO MESSAGE * @param threadId * @param messageId */ // replyMessage(149486, 1582759, "..."); /** * FORWARD MESSAGE * @param destination * @param messageIds */ // forwardMessage(57583, [592482, 592481]); /** * GET MESSAGE SEEN LIST * @param messageId */ // chatAgent.getMessageSeenList({ // messageId: 19623 // }, function(seenList) { // console.log("Seen list", seenList); // }); /** * GET MESSAGE DELIVERED LIST * @param messageId */ /** * Delivery has been deprecated and removed from sdk */ // 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.73229, // lng: 51.90794 // }, // mapWidth: 1200, // mapHeight: 500, // threadId: 148737, // userGroupHash: 'A6ULVAUYM1E1G9', // systemMetadata: { // time: new Date() // } // }, function(result) { // console.log(result); // }); // // setTimeout(function() { // sendLocationMessageInstantResponse.cancel(); // }, 1000); /* * Create Bot */ // chatAgent.createBot({ // botName: 'game1BOT' // }, (result) => { // console.log(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(8543, 'username', ['docsBOT']); // addParticipants(149486, 'username', ['salman.shahbazi']); // addParticipants(149486, 'contact', [25023511]); /* * Start Bot */ // chatAgent.startBot({ // botName: 'docsBOT', // threadId: 8543 // }, (result) => { // console.log(result); // }); /* * Stop Bot */ // chatAgent.stopBot({ // botName: 'yoBOT', // threadId: 7411 // }, (result) => { // console.log('Stop Bot result', result); // }); // chatAgent.getBotCommandsList({ // botName: 'docsBOT' // }, function(result) { // console.log(result); // }); // chatAgent.getThreadAllBots({threadId: 8543}, function (result) { // console.log(result); // }) }); /** * Listen to Error Messages */ chatAgent.on("error", function (error) { console.log("Error ", error); }); /** * Listen to Chat State Changes */ chatAgent.on("chatState", function (chatState) { // console.log(chatState); }); /** * Listen to File Upload Events */ chatAgent.on("fileUploadEvents", function (event) { console.log("[fileUploadEvents]", event); }); /** * Listen to File Download Events */ chatAgent.on("fileDownloadEvents", function (event) { console.log("[fileDownloadEvents]", event); }); /** * Listen to Contact Events */ chatAgent.on("contactEvents", function (event) { console.log("[contactEvents]", 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("[threadEvents]", 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("[messageEvents]", event); switch (type) { case "MESSAGE_NEW": /** * Sending Message Seen to Sender after 5 secs */ // console.log('Sending Message Deliver'); // chatAgent.deliver({ // messageId: message.id, // threadId: message.threadId // }); // console.log('Sending Message Seen'); // chatAgent.seen({ // messageId: message.id, // threadId: message.threadId // }); break; case "MESSAGE_EDIT": break; case "MESSAGE_DELIVERY": break; case "MESSAGE_SEEN": break; case "MESSAGE_FAILED": break; default: break; } }); /** * Listen to System Events */ chatAgent.on("systemEvents", function (event) { var type = event.type; console.log("[systemEvents]", 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("[userEvents]", event); switch (type) { case 'CHAT_PROFILE_UPDATED': console.log('Chat Profile Has Been Updated', event); break; default: break; } }); /** * Listen to Call Events */ chatAgent.on('callEvents', function (event) { var type = event.type; console.log("[callEvents]", event); // if (type === 'CALL_ERROR') // debugger; switch (type) { case 'RECEIVE_CALL': document.getElementById('call-receive-id').innerText = event.result.callId; console.log('Accepting the call #' + event.result.callId); // chatAgent.acceptCall({ // callId: event.result.callId, // video: true, // mute: false // }, function (res) { // console.log({res}); // }); // console.log('Rejecting the call #' + event.result.callId); // chatAgent.rejectCall({ // callId: event.result.callId // }, function (res) { // console.log({res}); // }); // console.log('End the call #' + event.result.callId); // chatAgent.endCall({ // callId: event.result.callId // }, function (res) { // console.log({res}); // }); break; case 'CALL_SESSION_CREATED': document.getElementById('call-receive-id').innerText = event.result.callId; break; case 'CALL_STARTED': document.getElementById('call-receive-broker').innerText = event.result.chatDataDto.brokerAddress.split(',')[0]; document.getElementById('call-receive-send').innerText = event.result.clientDTO.topicSend; document.getElementById('call-receive-receive').innerText = event.result.clientDTO.topicReceive; document.getElementById('call-receive-key').innerText = event.result.clientDTO.sendKey; break; default: break; } }); /** * Local Functions */ function getUserInfo() { chatAgent.getUserInfo(function (userInfo) { console.log(userInfo); }); } function getThreads(params) { var instantResult = chatAgent.getThreads(params, function (threadsResult) { console.log(threadsResult); }); // var instantResult = chatAgent.getThreadsLight(params, function (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, contactIds: participants }, function (result) { console.log(result); }); break; case 'username': chatAgent.addParticipants({ threadId: threadId, usernames: participants }, function (result) { console.log(result); }); break; case 'coreUserids': chatAgent.addParticipants({ threadId: threadId, coreUserids: participants }, function (result) { console.log(result); }); break; } } // 3432707,[{id:"nedahgh", idType:4}] function removeParticipants(threadId, participants) { chatAgent.removeParticipants({ threadId: threadId, // participantIds: participants, usernames: ["fntest2"] }, function (result) { // console.log(result); }); } function leaveThread(threadId) { chatAgent.leaveThread({ threadId: threadId }, function (result) { // console.log(result); }); } function addUserToUserGroup(thread_id,params) { console.log(params,thread_id) chatAgent.addUserToUserGroup(thread_id,params, function (contactsResult) { if (!contactsResult.hasError) { console.log(contactsResult); } console.log(contactsResult) }); } 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 startTime = new Date().getTime(); params.queues = { sending: true, uploading: true, failed: true }; chatAgent.getHistory(params, function (historyResult) { if (!historyResult.hasError) { console.log(historyResult); var endTime = new Date().getTime(); console.log(`Get History Duration: ${endTime - startTime} ms`); } }); } 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!'); }, /** * Delivery has been deprecated and removed from sdk */ // 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!"); }, /** * Delivery has been deprecated and removed from sdk */ // onDeliver: function (result) { // console.log(result.uniqueId + " \t has been Delivered!"); // }, onSeen: function (result) { console.log(result.uniqueId + " \t has been Seen!"); }, onFileUpload: function (result) { console.log('File Upload is done', result); } }); 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!"); }, /** * Delivery has been deprecated and removed from sdk */ // 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)"); }, /** * Delivery has been deprecated and removed from sdk */ // 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({ threadId: destination, messageIds: messageIds }, { onSent: function (result) { console.log(res