• Terry Garvin
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Below is my custom code for live chat which is working good but I need to implement an auto greeting message to the customer which should include salutation last name. (EX. Hi MR Pal how may I help you?) Without omnichannel routing, this code is working and everything works fine. How can we achieve this through a custom lightning component?.
<apex:page >
    <apex:includeScript value="/support/console/48.0/integration.js"/>
    <head>
   <script type="text/javascript">
       
       var state = history.state || {};
        var reloadCount = state.reloadCount || 0;
        if (performance.navigation.type === 1) { // Reload
            state.reloadCount = ++reloadCount;
            history.replaceState(state, null, document.URL);
        } else if (reloadCount) {
            reloadCount = 0;
            delete state.reloadCount;
            history.replaceState(state, null, document.URL);
        }
       
       
       var chatKey; 
       var checkmsgsent;
       var chatLogMessage; 
       var sizes;
       
       
       var eventHandler_endchat = function (result) {
            localStorage.clear();
            console.log('endchat'+localStorage.getItem("VarKey"));
        }
       
       var eventHandler1 = function (result) {
            checkmsgsent = result.content;
            localStorage.setItem("VarKey", checkmsgsent );

            alert('The agent is attempting to send the following message: ' + result.content);
            //sforce.console.chat.sendMessage(chatKey, theMessage)
            alert('The following message has been sent: ' + checkmsgsent);
            console.log('message'+checkmsgsent);
        }
        
           function getChatLogSuccess(result) {
            //Report whether getting the chat log was succesful
            alert('getchatlog'+ result.success);
            if (result.success == true) {
                 chatLogMessage = result.messages;
                 sizes= JSON.stringify(chatLogMessage);
                alert('The first message in this chatLog is: ' +JSON.stringify( chatLogMessage)+'---'+sizes.length);
                console.log('Chat messages'+JSON.stringify(chatLogMessage)+'-----'+ JSON.parse(sizes).length);
            } else {
                alert('Getting the chat log was not successful');
            }
        };
        
        
        
       var eventHandler =  function testGetDetailsByChatKey(reslt) {
              
             
            //Get the value for 'myChatKey' from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods. 
            //These values are for example purposes only
             chatKey= reslt.chatKey;
             localStorage.setItem("oldkey", chatKey);
             console.log(localStorage.getItem("oldkey"));
             
                  sforce.console.chat.onNewMessage(chatKey, eventHandler1);
                  sforce.console.chat.getChatLog(chatKey, getChatLogSuccess);

                    sforce.console.chat.getDetailsByChatKey(chatKey, getDetailsSuccess);
                    
                    
                      //sforce.console.chat.onNewMessage(chatKey, eventHandler1);
                    
                    
    
        }
        
        function getDetailsSuccess(result) {
                   
                    
            //Report whether accepting the chat was succesful
            if (result.success == true) {
                ipAddress = result.details.customDetails;
                alert('The Visitor IP Address for this chat is: ' + JSON.stringify(ipAddress));
                console.log(JSON.stringify(ipAddress) + ipAddress[4].value);
                
                var text ='hi, ' +ipAddress[6].value +'. ' +ipAddress[4].value + ' How may i help you?';
                console.log('text'+text);
               
                var chktext = localStorage.getItem("VarKey");
                console.log(chktext +'---'+ text );
               
                
                if(text != chktext )
                {
                    
                    var msgavailable = false;
                    for (var i = 0; i < JSON.parse(sizes).length; i++) 
                    {
                        if(text == chatLogMessage[i].content)
                        {
                            msgavailable = true;
                        }
                    }
                    
                    if(msgavailable == false)
                    {
                        alert('in if chk');
                        sforce.console.chat.sendMessage(chatKey, text, sendMessageSuccess);
                    
                    
                    }
                    
                }
                    
                
            } else {
                alert('Getting the details was not successful');
            }
        };
        
        
        function sendMessageSuccess(result) {
            //Report whether getting the chat log was successful
            if (result.success == true) {
                alert('Message Sent');
               
               
            } else {
                alert('Sending the message was not successful');
            }
        };
    
    
    
 
        
        
    
     sforce.console.chat.onChatStarted(eventHandler);
     sforce.console.chat.onChatEnded(eventHandler_endchat);
     sforce.console.chat.onChatDeclined(eventHandler_endchat);
     sforce.console.chat.onChatCanceled(eventHandler_endchat);



    </script>
    </head>
</apex:page>

 
I have a Profile with 20 users asssigned to this Profile
Custom_Picklist__c field on the Activity object has several values in it. Now, not all of these values need to be seen by all users in the profile. 

e.g User 1, User 2, User 3, User 4 should only see Val78, Val79,Val80. They  should be able to access all other values. I want to restrict rest of the users from accessing Val78, Val79,Val80.

Any way to achive this ?