I have live agent set up and I am trying to set an alert on the agent side when a customer does not reply to his messages after a certain interval of time
Here is how I am trying to achieve (All these are in the js helper,being delegated from the js controller)
Declared A global variable globalvariable1 which keeps track of its changed value
Used an onAgentMessageSend component which fires when an Agent chats
onAgentMessageSend : function(cmp,recordId,content,name,type,timestamp){
if(type=='Agent')
{
var self = this;
setTimeout(function() {
var returnedType=self.checkMessageSenderAndResetCounter(cmp);
}, 5000);
if(returnedType=='Default Value')
{alert('Unresponsive Customer');}
else{
console.log('customer responded hence reset');
globalvariable1= 'Default Value'}}
else{
console.log('Do nothing');}},
- A function to change the global value as and when coming from Agent or Customer
checkMessageSenderAndResetCounter: function(cmp) {
console.log('the current value of globalvarable'+this.globalvariable1);
return this.globalvariable1;},
A method which is fired when a customer messages
onNewMessageFromEndUser : function(cmp,recordId,content,name,type,timestamp){
this.globalvariable1='Customer';},
Summing up, what I am trying to achieve here is once the agent chats, a timer is set for lets say 5 seconds. Within that time frame if a customer replies, the global variable changes and it continues. In case there is no reply from the customer's end, the global variable is still a default value, then it raises an alert indicating that there is an unanswered question.
But the result from the Settimeout is not achievable, could you please help out here for any other way to achieve this, or rectify this itself?
You need to perform your logic either inside
setTimeout
or create a function and call it inside timeout.