Pass company info to Intercom when user login through AUTH0

Hi,

I would like to update the user’s company name, company ID when login to Intercom, so it will showing right company on Intercom for the user who logged in our app through AUTH0

I have the follow rule related to the Intercom, how can I modified it to assign the Intercom - company name , company id for the user suppose below to every the user login through AUTH0

Thanks,

===
function (user, context, callback) {
const namespace = ‘https://s2s.mycompany_intercom_workspace/’;
const crypto = require(‘crypto’);
const hmac = crypto.createHmac(‘sha256’, configuration.intercom_key);

hmac.update(user.email);

const hash = hmac.digest(‘hex’);

context.idToken[namespace + ‘intercom_hash’] = hash;
context.accessToken[namespace + ‘intercom_hash’] = hash;
callback(null, user, context);

==============

Hey @mapperkids,

Can you please elaborate on the use-case a bit more in detail? Are you looking to add/update user metadata for login transactions?

Regards,
Sid

1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Hi Sid,

Yes, we have an intercom widget built-in our app, and when a user logged into our application through AUTH0, the user will appear as a web session on Intercom view, but the company info is messed up. What I want to do is create a rule or modify our existing rule to update the user profile on Intercom by assigning them the right company name, company id through their REST API call.

I don’t know if I can use the data metadata to do that or not or need a new rule for that.

Thanks,

Hey @mapperkids,

Thanks for elaborating the use-case, you can always update the user metadata in rules.
We have a sample rule to demonstrate this behavior:

Have a look and let me know how you go!

Regards,
Sid

1 Like

Hi Sid,

I check the Metadata, but we that work, I need to update the user info. on Intercom through their REST API?

To update the user’s company name and company ID when logging into Intercom using Auth0, you’ll need to modify the rule to include the necessary information in the user’s profile.
Here’s an updated version of marketing data enrichment of your rule that includes the company name and company ID:
function (user, context, callback) {
const namespace = ‘https://s2s.mycompany_intercom_workspace/’;
const crypto = require(‘crypto’);
const hmac = crypto.createHmac(‘sha256’, configuration.intercom_key);

// Update the user’s company name and company ID here
user.company_name = ‘Your Company Name’;
user.company_id = ‘Your Company ID’;

// Create a hash using the user’s email
hmac.update(user.email);
const hash = hmac.digest(‘hex’);

// Add the hash to the user’s profile
user.intercom_hash = hash;

// Update the ID token and access token with the hash
context.idToken[namespace + ‘intercom_hash’] = hash;
context.accessToken[namespace + ‘intercom_hash’] = hash;

// Continue with the authentication process
callback(null, user, context);
}