Created
January 26, 2019 01:31
-
-
Save Grohden/0650040a9df10756b5ba0d9dab0a6d8d to your computer and use it in GitHub Desktop.
Intercom issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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