Skip to content

Instantly share code, notes, and snippets.

@vitorebatista
Created February 25, 2019 14:28
Show Gist options
  • Save vitorebatista/375040fb14e3e3119e54c6dc06feb50e to your computer and use it in GitHub Desktop.
Save vitorebatista/375040fb14e3e3119e54c6dc06feb50e to your computer and use it in GitHub Desktop.
IntercomExtensions.kt
package br.com.ngi.mnt.services.extensions.trackers
import br.com.ngi.mnt.services.extensions.libs.applyWhen
import br.com.ngi.mnt.sync.model.CurrentBranch
import br.com.ngi.mnt.sync.model.User
import io.intercom.android.sdk.Company
import io.intercom.android.sdk.Intercom
import io.intercom.android.sdk.UserAttributes
import io.intercom.android.sdk.identity.Registration
fun Intercom.logSearchEvent(item: String) {
logEvent("Searched for a $item")
}
fun Intercom.registerUserModel(branch: CurrentBranch, user: User) {
val userAttrs = UserAttributes.Builder()
.withName(branch.workerName ?: branch.executorName ?: branch.requesterName)
.withCustomAttribute("speciality", branch.speciality)
.withCustomAttribute("branchName", branch.branchName)
.withCompany(Company
.Builder()
.applyWhen({ branch.enterpriseFantasyName != null }) {
withName(branch.enterpriseFantasyName)
}
.withCompanyId(user.enterpriseCnpj)
.withCustomAttribute("email", user.enterpriseEmail)
.build()
).build()
this.registerIdentifiedUser(
Registration
.create()
// Both are the user email
.withUserId(user.user)
.withEmail(user.user)
.withUserAttributes(userAttrs)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment