podchat 12.6.1 → 12.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node/chat.js CHANGED
@@ -333,7 +333,7 @@ messageContent=typeof chatMessage.content==='string'&&isValidJson(chatMessage.co
333
333
  * Type 5 Message Seen
334
334
  */case _constants.chatMessageVOTypes.SEEN:if(fullResponseObject){getHistory({offset:0,threadId:threadId,id:messageContent.messageId,cache:false},function(result){if(!result.hasError){_events.chatEvents.fireEvent('messageEvents',{type:'MESSAGE_SEEN',result:{message:result.result.history[0],threadId:threadId,senderId:messageContent.participantId}});}});}else{_events.chatEvents.fireEvent('messageEvents',{type:'MESSAGE_SEEN',result:{message:messageContent.messageId,threadId:threadId,senderId:messageContent.participantId}});}sendMessageCallbacksHandler(_constants.chatMessageVOTypes.SEEN,threadId,uniqueId);break;/**
335
335
  * Type 6 Chat Ping
336
- */case _constants.chatMessageVOTypes.PING:break;/**
336
+ */case _constants.chatMessageVOTypes.PING:if(messagesCallbacks[uniqueId]){var result=_utility["default"].createReturnData(false,'',0,messageContent);result.uniqueId=uniqueId;messagesCallbacks[uniqueId](result);}break;/**
337
337
  * Type 7 Block Contact
338
338
  */case _constants.chatMessageVOTypes.BLOCK:if(messagesCallbacks[uniqueId]){messagesCallbacks[uniqueId](_utility["default"].createReturnData(false,'',0,messageContent));}break;/**
339
339
  * Type 8 Unblock Blocked User
@@ -4211,7 +4211,7 @@ callback&&callback(returnData);}else{_events.chatEvents.fireEvent('error',{code:
4211
4211
  */callback=undefined;if(!returnData.hasError&&returnCache){_events.chatEvents.fireEvent('contactEvents',{type:'CONTACTS_SEARCH_RESULT_CHANGE',result:returnData.result});}}else{_events.chatEvents.fireEvent('error',{code:result.errorCode,message:result.errorMessage,error:result});}});};this.createBot=function(params,callback){var createBotData={chatMessageVOType:_constants.chatMessageVOTypes.CREATE_BOT,typeCode:params.typeCode,content:'',pushMsgType:3,token:token};if(params){if(typeof params.botName==='string'&&params.botName.length>0){if(params.botName.substr(-3)==="BOT"){createBotData.content=params.botName;}else{_events.chatEvents.fireEvent('error',{code:999,message:'Bot name should end in "BOT", ex. "testBOT"'});return;}}else{_events.chatEvents.fireEvent('error',{code:999,message:'Insert a bot name to create one!'});return;}}else{_events.chatEvents.fireEvent('error',{code:999,message:'Insert a bot name to create one!'});return;}return sendMessage(createBotData,{onResult:function onResult(result){callback&&callback(result);}});};this.defineBotCommand=function(params,callback){var defineBotCommandData={chatMessageVOType:_constants.chatMessageVOTypes.DEFINE_BOT_COMMAND,typeCode:params.typeCode,content:{},pushMsgType:3,token:token},commandList=[];if(params){if(typeof params.botName!=='string'||params.botName.length==0){_events.chatEvents.fireEvent('error',{code:999,message:'You need to insert a botName!'});return;}if(!Array.isArray(params.commandList)||!params.commandList.length){_events.chatEvents.fireEvent('error',{code:999,message:'Bot Commands List has to be an array of strings.'});return;}else{for(var i=0;i<params.commandList.length;i++){commandList.push('/'+params.commandList[i].trim());}}defineBotCommandData.content={botName:params.botName.trim(),commandList:commandList};}else{_events.chatEvents.fireEvent('error',{code:999,message:'No params have been sent to create bot commands'});return;}return sendMessage(defineBotCommandData,{onResult:function onResult(result){callback&&callback(result);}});};this.startBot=function(params,callback){var startBotData={chatMessageVOType:_constants.chatMessageVOTypes.START_BOT,typeCode:params.typeCode,content:{},pushMsgType:3,token:token};if(params){if(typeof+params.threadId!=='number'||params.threadId<0){_events.chatEvents.fireEvent('error',{code:999,message:'Enter a valid Thread Id for Bot to start in!'});return;}if(typeof params.botName!=='string'||params.botName.length==0){_events.chatEvents.fireEvent('error',{code:999,message:'You need to insert a botName!'});return;}startBotData.subjectId=+params.threadId;startBotData.content=JSON.stringify({botName:params.botName.trim()});}else{_events.chatEvents.fireEvent('error',{code:999,message:'No params have been sent to create bot commands'});return;}return sendMessage(startBotData,{onResult:function onResult(result){callback&&callback(result);}});};this.stopBot=function(params,callback){var stopBotData={chatMessageVOType:_constants.chatMessageVOTypes.STOP_BOT,typeCode:params.typeCode,content:{},pushMsgType:3,token:token},commandList=[];if(params){if(typeof+params.threadId!=='number'||params.threadId<0){_events.chatEvents.fireEvent('error',{code:999,message:'Enter a valid Thread Id for Bot to stop on!'});return;}if(typeof params.botName!=='string'||params.botName.length==0){_events.chatEvents.fireEvent('error',{code:999,message:'You need to insert a botName!'});return;}stopBotData.subjectId=+params.threadId;stopBotData.content=JSON.stringify({botName:params.botName.trim()});}else{_events.chatEvents.fireEvent('error',{code:999,message:'No params have been sent to create bot commands'});return;}return sendMessage(stopBotData,{onResult:function onResult(result){callback&&callback(result);}});};this.getBotCommandsList=function(params,callback){var getBotCommandsListData={chatMessageVOType:_constants.chatMessageVOTypes.BOT_COMMANDS,typeCode:params.typeCode,content:{},pushMsgType:3,token:token};if(params){if(typeof params.botName!=='string'||params.botName.length==0){_events.chatEvents.fireEvent('error',{code:999,message:'You need to insert a botName!'});return;}getBotCommandsListData.content=JSON.stringify({botName:params.botName.trim()});}else{_events.chatEvents.fireEvent('error',{code:999,message:'No params have been sent to get bot commands'});return;}return sendMessage(getBotCommandsListData,{onResult:function onResult(result){callback&&callback(result);}});};this.getThreadAllBots=function(params,callback){var getThreadBotsData={chatMessageVOType:_constants.chatMessageVOTypes.THREAD_ALL_BOTS,typeCode:params.typeCode,content:{},pushMsgType:3,token:token};if(params){if(typeof+params.threadId!=='number'||params.threadId<0){_events.chatEvents.fireEvent('error',{code:999,message:'Enter a valid Thread Id to get all Bots List!'});return;}getThreadBotsData.subjectId=+params.threadId;}else{_events.chatEvents.fireEvent('error',{code:999,message:'No params have been sent to get thread\' bots list!'});return;}return sendMessage(getThreadBotsData,{onResult:function onResult(result){callback&&callback(result);}});};this.mapReverse=function(params,callback){var data={};if(params){if(parseFloat(params.lat)>0){data.lat=params.lat;}if(parseFloat(params.lng)>0){data.lng=params.lng;}data.uniqueId=_utility["default"].generateUUID();}var requestParams={url:SERVICE_ADDRESSES.MAP_ADDRESS+_constants.SERVICES_PATH.REVERSE,method:'GET',data:data,headers:{'Api-Key':mapApiKey}};httpRequest(requestParams,function(result){if(!result.hasError){var responseData=JSON.parse(result.result.responseText);var returnData={hasError:result.hasError,cache:result.cache,errorMessage:result.message,errorCode:result.errorCode,result:responseData};callback&&callback(returnData);}else{_events.chatEvents.fireEvent('error',{code:result.errorCode,message:result.errorMessage,error:result});}});};this.mapSearch=function(params,callback){var data={};if(params){if(typeof params.term==='string'){data.term=params.term;}if(parseFloat(params.lat)>0){data.lat=params.lat;}if(parseFloat(params.lng)>0){data.lng=params.lng;}data.uniqueId=_utility["default"].generateUUID();}var requestParams={url:SERVICE_ADDRESSES.MAP_ADDRESS+_constants.SERVICES_PATH.SEARCH,method:'GET',data:data,headers:{'Api-Key':mapApiKey}};httpRequest(requestParams,function(result){if(!result.hasError){var responseData=JSON.parse(result.result.responseText);var returnData={hasError:result.hasError,cache:result.cache,errorMessage:result.message,errorCode:result.errorCode,result:responseData};callback&&callback(returnData);}else{_events.chatEvents.fireEvent('error',{code:result.errorCode,message:result.errorMessage,error:result});}});};this.mapRouting=function(params,callback){var data={};if(params){if(typeof params.alternative==='boolean'){data.alternative=params.alternative;}else{data.alternative=true;}if((0,_typeof2["default"])(params.origin)==='object'){if(parseFloat(params.origin.lat)>0&&parseFloat(params.origin.lng)){data.origin=params.origin.lat+','+parseFloat(params.origin.lng);}else{console.log('No origin has been selected!');}}if((0,_typeof2["default"])(params.destination)==='object'){if(parseFloat(params.destination.lat)>0&&parseFloat(params.destination.lng)){data.destination=params.destination.lat+','+parseFloat(params.destination.lng);}else{console.log('No destination has been selected!');}}data.uniqueId=_utility["default"].generateUUID();}var requestParams={url:SERVICE_ADDRESSES.MAP_ADDRESS+_constants.SERVICES_PATH.ROUTING,method:'GET',data:data,headers:{'Api-Key':mapApiKey}};httpRequest(requestParams,function(result){if(!result.hasError){var responseData=JSON.parse(result.result.responseText);var returnData={hasError:result.hasError,cache:result.cache,errorMessage:result.message,errorCode:result.errorCode,result:responseData};callback&&callback(returnData);}else{_events.chatEvents.fireEvent('error',{code:result.errorCode,message:result.errorMessage,error:result});}});};this.createSelfThread=function(params,callback){var content={type:_constants.createThreadTypes['SELF']};if(params){if(typeof params.description==='string'){content.description=params.description;}if(typeof params.metadata==='string'){content.metadata=params.metadata;}else if((0,_typeof2["default"])(params.metadata)==='object'){try{content.metadata=JSON.stringify(params.metadata);}catch(e){consoleLogging&&console.log(e);}}if((0,_typeof2["default"])(params.message)=='object'){content.message={};if(typeof params.message.text==='string'){content.message.text=params.message.text;}if(typeof params.message.uniqueId==='string'){content.message.uniqueId=params.message.uniqueId;}if(params.message.type>0){content.message.messageType=params.message.type;}if(params.message.repliedTo>0){content.message.repliedTo=params.message.repliedTo;}if(typeof params.message.metadata==='string'){content.message.metadata=params.message.metadata;}else if((0,_typeof2["default"])(params.message.metadata)==='object'){content.message.metadata=JSON.stringify(params.message.metadata);}if(typeof params.message.systemMetadata==='string'){content.message.systemMetadata=params.message.systemMetadata;}else if((0,_typeof2["default"])(params.message.systemMetadata)==='object'){content.message.systemMetadata=JSON.stringify(params.message.systemMetadata);}if(Array.isArray(params.message.forwardedMessageIds)){content.message.forwardedMessageIds=params.message.forwardedMessageIds;content.message.forwardedUniqueIds=[];for(var i=0;i<params.message.forwardedMessageIds.length;i++){content.message.forwardedUniqueIds.push(_utility["default"].generateUUID());}}}}var sendMessageParams={chatMessageVOType:_constants.chatMessageVOTypes.CREATE_THREAD,typeCode:generalTypeCode,//params.typeCode,
4212
4212
  content:content};return sendMessage(sendMessageParams,{onResult:function onResult(result){var returnData={hasError:result.hasError,cache:false,errorMessage:result.errorMessage,errorCode:result.errorCode};if(!returnData.hasError){var messageContent=result.result;returnData.result={thread:createThread(messageContent)};}callback&&callback(returnData);}});};this.mapStaticImage=function(params,callback){var data={},url=SERVICE_ADDRESSES.MAP_ADDRESS+_constants.SERVICES_PATH.STATIC_IMAGE,hasError=false;if(params){if(typeof params.type==='string'){data.type=params.type;}else{data.type='standard-night';}if(parseInt(params.zoom)>0){data.zoom=params.zoom;}else{data.zoom=15;}if(parseInt(params.width)>0){data.width=params.width;}else{data.width=800;}if(parseInt(params.height)>0){data.height=params.height;}else{data.height=600;}if((0,_typeof2["default"])(params.center)==='object'){if(parseFloat(params.center.lat)>0&&parseFloat(params.center.lng)){data.center=params.center.lat+','+parseFloat(params.center.lng);}else{hasError=true;_events.chatEvents.fireEvent('error',{code:6700,message:_constants.CHAT_ERRORS[6700],error:undefined});}}else{hasError=true;_events.chatEvents.fireEvent('error',{code:6700,message:_constants.CHAT_ERRORS[6700],error:undefined});}data.key=mapApiKey;}var keys=Object.keys(data);if(keys.length>0){url+='?';for(var i=0;i<keys.length;i++){var key=keys[i];url+=key+'='+data[key];if(i<keys.length-1){url+='&';}}}var returnData={hasError:hasError,cache:false,errorMessage:hasError?_constants.CHAT_ERRORS[6700]:'',errorCode:hasError?6700:undefined,result:{link:!hasError?url:''}};callback&&callback(returnData);};this.setAdmin=function(params,callback){setRoleToUser(params,callback);};this.removeAdmin=function(params,callback){removeRoleFromUser(params,callback);};this.setAuditor=function(params,callback){setRoleToUser(params,callback);};this.removeAuditor=function(params,callback){removeRoleFromUser(params,callback);};this.clearChatServerCaches=clearChatServerCaches;// this.deleteCacheDatabases = deleteCacheDatabases;
4213
4213
  // this.clearCacheDatabasesOfUser = clearCacheDatabasesOfUser;
4214
- this.getChatState=function(){return chatFullStateObject;};this.reconnect=function(){asyncClient.reconnectSocket();};this.setToken=function(newToken){if(typeof newToken!='undefined'){token=newToken;_events.chatEvents.updateToken(token);if(!userInfo||!userInfo.id){getUserAndUpdateSDKState();}}};this.generateUUID=_utility["default"].generateUUID;/** Call public methods */this.startRecordingCall=function(params,callback){var recordCallData={chatMessageVOType:_constants.chatMessageVOTypes.RECORD_CALL,typeCode:params.typeCode,pushMsgType:3,token:token,content:{}};if(params){if(typeof+params.callId==='number'&&params.callId>0){recordCallData.subjectId=+params.callId;}else{// chatEvents.fireEvent('error', {
4214
+ this.getChatState=function(){return chatFullStateObject;};this.reconnect=function(){asyncClient.reconnectSocket();};this.setToken=function(newToken){if(typeof newToken!='undefined'){token=newToken;_events.chatEvents.updateToken(token);if(!userInfo||!userInfo.id){getUserAndUpdateSDKState();}}};this.generateUUID=_utility["default"].generateUUID;var requestLimiter={pingChatServer:{limit:1000*60,lastTime:0}};this.pingChatServer=function(callback){if(requestLimiter.pingChatServer.lastTime<new Date().getTime()-requestLimiter.pingChatServer.limit){requestLimiter.pingChatServer.lastTime=new Date().getTime();sendMessage({chatMessageVOType:_constants.chatMessageVOTypes.PING,pushMsgType:3,uniqueId:_utility["default"].generateUUID()},function(result){messagesCallbacks[result.uniqueId]&&delete messagesCallbacks[result.uniqueId];callback&&callback(result);});}else{var result={hasError:true,errorCode:null,errorMessage:_constants.CHAT_ERRORS[6800].replace("{time}",requestLimiter.pingChatServer.limit)};callback&&callback(result);}};/** Call public methods */this.startRecordingCall=function(params,callback){var recordCallData={chatMessageVOType:_constants.chatMessageVOTypes.RECORD_CALL,typeCode:params.typeCode,pushMsgType:3,token:token,content:{}};if(params){if(typeof+params.callId==='number'&&params.callId>0){recordCallData.subjectId=+params.callId;}else{// chatEvents.fireEvent('error', {
4215
4215
  // code: 999,
4216
4216
  // message: 'Invalid Call id!'
4217
4217
  // });
@@ -169,6 +169,7 @@ var CHAT_ERRORS = {
169
169
  6602: 'Database Error',
170
170
  // Map Errors
171
171
  6700: 'You should Enter a Center Location like {lat: " ", lng: " "}',
172
+ 6800: "RequestLimiter: Too fast api call, you should wait {time}ms after each call to current api.",
172
173
  12003: 'Async socket connection failed'
173
174
  };
174
175
  exports.CHAT_ERRORS = CHAT_ERRORS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podchat",
3
- "version": "12.6.1",
3
+ "version": "12.6.2",
4
4
  "description": "Javascript SDK to use POD's Chat Service",
5
5
  "main": "./dist/node/chat.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "publish:snapshot": "npm run version:snapshot && npm publish --tag snapshot",
9
9
  "version:snapshot": "npm version prerelease --preid snapshot",
10
10
  "publish:release": "npm run version:release && npm publish",
11
- "version:release": "npm version 12.6.1",
11
+ "version:release": "npm version 12.6.2",
12
12
  "build:npm": "babel src -d dist/node --copy-files",
13
13
  "build": "npm run build:npm",
14
14
  "watch": "npm-watch build"
@@ -44,11 +44,11 @@
44
44
  "image-size": "^0.8.3",
45
45
  "jsdom": "^18.0.0",
46
46
  "mime": "^2.4.4",
47
- "podasync": "2.8.4-snapshot.3",
47
+ "podasync": "2.8.4-snapshot.5",
48
48
  "query-string": "^6.8.1",
49
49
  "request": "^2.88.0"
50
50
  },
51
51
  "devDependencies": {
52
- "mocha": "^8.1.1"
52
+ "mocha": "^10.2.0"
53
53
  }
54
54
  }
package/src/chat.js CHANGED
@@ -1697,6 +1697,11 @@ import Mime from 'mime';
1697
1697
  * Type 6 Chat Ping
1698
1698
  */
1699
1699
  case chatMessageVOTypes.PING:
1700
+ if (messagesCallbacks[uniqueId]) {
1701
+ let result = Utility.createReturnData(false, '', 0, messageContent);
1702
+ result.uniqueId = uniqueId;
1703
+ messagesCallbacks[uniqueId](result);
1704
+ }
1700
1705
  break;
1701
1706
 
1702
1707
  /**
@@ -12948,6 +12953,33 @@ import Mime from 'mime';
12948
12953
 
12949
12954
  this.generateUUID = Utility.generateUUID;
12950
12955
 
12956
+ let requestLimiter = {
12957
+ pingChatServer: {
12958
+ limit: 1000 * 60,
12959
+ lastTime: 0
12960
+ }
12961
+ };
12962
+
12963
+ this.pingChatServer = function (callback) {
12964
+ if(requestLimiter.pingChatServer.lastTime < (new Date().getTime() - (requestLimiter.pingChatServer.limit))){
12965
+ requestLimiter.pingChatServer.lastTime = new Date().getTime();
12966
+ sendMessage({
12967
+ chatMessageVOType: chatMessageVOTypes.PING,
12968
+ pushMsgType: 3,
12969
+ uniqueId: Utility.generateUUID()
12970
+ }, function (result) {
12971
+ messagesCallbacks[result.uniqueId] && delete messagesCallbacks[result.uniqueId]
12972
+ callback && callback(result);
12973
+ });
12974
+ } else {
12975
+ let result = {
12976
+ hasError: true,
12977
+ errorCode: null,
12978
+ errorMessage: CHAT_ERRORS[6800].replace("{time}", requestLimiter.pingChatServer.limit)
12979
+ }
12980
+ callback && callback(result)
12981
+ }
12982
+ };
12951
12983
 
12952
12984
  /** Call public methods */
12953
12985
  this.startRecordingCall = function (params, callback) {
@@ -180,7 +180,9 @@ const CHAT_ERRORS = {
180
180
  // Map Errors
181
181
  6700: 'You should Enter a Center Location like {lat: " ", lng: " "}',
182
182
 
183
- 12003: 'Async socket connection failed'
183
+ 6800: "RequestLimiter: Too fast api call, you should wait {time}ms after each call to current api.",
184
+ 12003: 'Async socket connection failed',
185
+
184
186
  }
185
187
 
186
188
  const SERVICES_PATH = {