Skip to content

Instantly share code, notes, and snippets.

@Grohden
Created January 26, 2019 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grohden/0650040a9df10756b5ba0d9dab0a6d8d to your computer and use it in GitHub Desktop.
Save Grohden/0650040a9df10756b5ba0d9dab0a6d8d to your computer and use it in GitHub Desktop.
Intercom issue
/*
* This function doesn't work. I get a tiny error log saying that i cannot
* update the email of a anonymous user and that i should call `registerIdentifiedUser`
*
* In the `RealIntercom` class, on the `registerIdentifiedUser`
* there's a if condition that fails in this case
* `if (userIdentity.canRegisterIdentifiedUser(userRegistration))`
*
* It fails cuz the `Registration` class expects the `updateState` to be called
* at least once, `withEmail` and `withUserId` are the ones that do that
* but using only the `UserAttributes.Builder` they're not called and the validation fails.
*
*/
fun Intercom.registerUserModel(user: User) {
val userAttrs = UserAttributes.Builder()
.withEmail(user.user)
.withUserId(user.user) // This is the problem
.withCompany(Company
.Builder()
.withCompanyId(user.enterpriseCnpj)
.withCustomAttribute("email", user.enterpriseEmail)
.build()
).build()
this.registerIdentifiedUser(
Registration
.create()
.withUserAttributes(userAttrs)
)
}
/*
* This function work.
*/
fun Intercom.registerUserModel(user: User) {
val userAttrs = UserAttributes.Builder()
.withEmail(user.user)
.withCompany(Company
.Builder()
.withCompanyId(user.enterpriseCnpj)
.withCustomAttribute("email", user.enterpriseEmail)
.build()
).build()
this.registerIdentifiedUser(
Registration
.create()
.withUserId(user.user) // this solves, but why only here?
.withUserAttributes(userAttrs)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment