4

I would like to create two buttons on Snap-ins pre-chat form to route customer to different support departments.

According to documentation we can control the agent routing with embedded_svc.settings.directToButtonRouting param also we can pass additional params to transcript with embedded_svc.settings.extraPrechatFormDetails and many more. But we should place the code to the page where chat will be initiated.

Is it possible to read and modify these params from the overridden lightning pre-chat form component?

The only API I found is

<lightningsnapin:prechatAPI aura:id="prechatAPI"/>
<lightningsnapin:settingsAPI aura:id="settingsAPI"/>

cmp.find("prechatAPI").getPrechatFields();
cmp.find("settingsAPI").getLiveAgentSettings();

But it returns very limited info. the global variable embedded_svc is also not visible in lightning component for some reason.

2 Answers 2

5

At this moment, the full Snap-In embedded_svc library structure is not available in Lightning. If you are developing in a Community and using the OOTB Lightning Snap-In component, for example, you are limited to the methods you've called out (in addition to a couple more referenced in the documentation):

cmp.find("prechatAPI").getPrechatFields();
cmp.find("prechatAPI").validateFields();
cmp.find("prechatAPI").startChat();
cmp.find("settingsAPI").getLiveAgentSettings();

This has been called out as a limitation here: https://help.salesforce.com/articleView?id=snapins_chat_limitations.htm&type=0%C2%A0

  • "You can’t embed Snap-ins Chat into Lightning components. Use a Visualforce page, Community, or web property only."

A couple of notes there:

  • I'm assuming "web property" there refers to the non-Lightning component implementation that uses the embedded_svc library
  • If in a Community, you can embed the Snap-In library into a VisualForce page, but the button itself hugs the bottom of the VisualForce page, not the actual bottom of the window. I'm not sure if you can have this chat persist from page to page like the web implementation or the OOTB Community implementation
  • Again from above, in the OOTB Community implementation, there is no access to the embedded_svc library, so the ability to exert control over the records getting created and things like direct-to-button routing are not available yet for the Community

In a Community, it is possible to create a rich pre-chat form and build a custom display for the prechat fields, as long as you start a chat by passing the formatted fields that are expected from the cmp.find("prechatAPI").getPrechatFields() function.

To add some context for the default behavior for the OOTB Snap-In component for Communities, a Case and Contact are created and attached to the Live Agent Transcript without any additional custom work in a custom prechat form, both of which will be popped for an agent with the chat.

When using Person Accounts, if an existing Person Account is found based on matching first name, last name, and email, that record will be attached to the Live Agent Transcript and popped instead of a Contact record. If a Person Account does not match, a Contact record will be created and popped. This Contact creation can be blocked using a validation rule if desired.

3

Thanks friendofflore for your answer this really helped me out. At present There are definitely some contradictions in the documentation which doesn't make it entirely clear what you can and cannot do from lightning components.

I have just raised a similar question with the SF support team and your analysis is entirely correct at present.

r.e. Artem's question on Direct to button routing, my findings were also that this is not yet available from within a lightning component. If developers wish to do dynamic rendering of a buttonID based on data NOT available in the prechat form then they will need to copy the ‘getCode’ snippet in to a vf page, use vf remoting or something similar(possibly AJAX) in order to access server side data.

Once they have access to that data then they can then use direct to button routing accordingly E.g. if a customer is a high priority customer then send them to ‘x’ queue. This vf page will then need to be added to the community in replacement of the OOB community snap-in component.

e.g. (from within a vf page) invoke server side controller passing in the email address from the form as parameter to get details of contact that is not available in prechat form(that we don’t ask users to fill in)

embedded_svc.settings.directToButtonRouting = function(prechatFormData) {

var email = prechatFormData[2].value;    


    Visualforce.remoting.Manager.invokeAction(
               ‘{!$RemoteAction.GenericControllerName.GenericGetContactMethod}’, email,

               function(result, event){

                    if(result.HighValueAccount== true){
                                return buttonIdOfTheHighValueQueue
                     }
                 },

           {escape: true}
             );
            };

We didn’t try this, but I believe it’s also possible to do remoting from within the snippetfile (Static resource) which would allow the snap in to sit at the bottom of the webpage/community rather than at the bottom of the vf page as really the creation of the vf page was only so we could access data via apex code to dynamically set the buttonId.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .