I'm playing around with Einstein Bots and have created a simple bot that is consumed inside a customer community.

I'd like to get the current User inside an Apex action used in a bot dialog.

The UserInfo.getUserId(), as expected, returns the Automated Process system user.

Are there system slots (like LiveAgentSessionId) that can be used for this porpouse?

In my mynd the only way to get the running user is to create a custom lightning component that would grab the UserId and pass it to the Bot without actually asking for anything from the running user...but honestly it seems more a workaround.

Any suggestions?

UPDATE I found a workaround on this but it seems robust enough. Here are the details: https://blog.enree.co/2018/11/salesforce-dealing-with-the-running-user-on-einstein-bot-dialogs.html

  • 1
    Since you mention LiveAgentSessionId, are you inside LiveAgent with this bot? If so, you'll want to refer to the Live Agent Developer Guide. If not, then explaining how the bot interacts with the community user might be more helpful. My guess would be that you'll need a controller for a component to get the info if you don't use embedded visualforce in an I frame inside the component. – crmprogdev Oct 12 at 16:21
  • I've created a custom lightning component that is able to get the current running user, but when I put the Snap-Ins component on the home page of the customer community, I find no way to tell the prechat that you can have an additional field, that is the UserId. I've tried with the community builder "Extrnal Scripts" for the chat snap-in component, but no luck so far to pass another parameter. – Enrico Murru Oct 12 at 16:46
  • 1
    I've seen a lot of questions asked about getting things to work with the pre-chat app on SF.SE. I suggest you search on it to see if it turns up anything useful because I know it's a difficult app to work with that I do not think is well documented. That thing is conditioned to look for a contact and probably doesn't want to think in terms of community users. I don't know if there are any real limits on how many fields it can use. Hopefully someone else will jump in after seeing this. I will edit your title and tags to draw attention to your post. – crmprogdev Oct 12 at 19:50

I've come up with a solution that seems to be working to get back the logged in community user details.

You need to override PreChat Lightning Components with your own custom components. This needs to be configured in the Live Agent Settings on your Snap-In.

Use a Controller(Apex Class) on your custom Pre Chat Component to get logged in user details on onInit. This will run in System Context and you'll be able to get the user details.

Now use these details to set the pre-chat fields like FirstName, LastName, Email etc. Validate and Start the Chat. You'll see the Bot now has Pre-Chat data.

Secondly, add a Apex Invocation call at the start in Welcome Message, pass LiveAgentSessionId as a parameter. Fetch the LiveChatTranscript. Since, we've already set the Pre-Chat fields and mapped the contact the LiveChatTranscipt will have the correct Contact mapped too. Just pass these details back to the Bot.

This way your Bot now also has the Contact details.

Have tested it and it works on a Community with Einstein Bot deployed via Snap-in.

  • Hi Shantanu! Thank you! This is the same solution I came up with but the problem is that using the contact details is not the best solution as there is no guarantee that you are referring to the current user. What I'm looking for is a way to pass to the chat the user id/username to be passed to the Live Chat transcript...if you use custom snap-in snippet on an external web page or in visualforce you have plain control on the configurations, but using a lightning ocmponent inside a snap-in community component it's not that easy to setup :( – Enrico Murru Oct 19 at 8:29
  • That's correct, using standard lightning snap-in has very limited customisable options at the moment. All processes running from Bot's context will be owned by Cloud Integration User. We can fire Platform Events but those will be run via the Automated User. The solution I presented can capture the Community logged in user. These are the only 3 users which will be running processes when interacting with the Bot. Checked your question again not sure which other user would you need info about? – Shantanu Srivastava Oct 19 at 8:40
  • I guess this is the answer I was lookgin for :( salesforce.stackexchange.com/questions/228053/… – Enrico Murru Oct 19 at 8:58
  • 1
    Yeah, I've referred to this answer for more understanding earlier too. Sorry, missed to direct you to it. – Shantanu Srivastava Oct 19 at 9:01
  • I found a solution, I'll document it on a post on my blog and link it here later...it's a workaround but it works. – Enrico Murru Oct 19 at 12:50

It’s not possible. The user in the snapping is an integration user. “Login” like a customer, is not possible

  • You can actually use the pre-chst by adding the current user to the Transcript object, but so far I couldn't make it work using snap-ins + community + standard snap-ins component in builder – Enrico Murru Oct 16 at 23:16
  • 1
    But pre-chat Is not a "secure" Login. I think Is better ask something to customer and use a second authenticator factor to verify who is talking with you – Edu Trujillo Oct 17 at 21:21
  • I meant that in the pre-chat I know if I'm logged at all and send the proper info to the chat apis. – Enrico Murru Oct 18 at 22:02

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.