Stop matching by phone number when upserting members in Identity#33
Open
michael-gratton wants to merge 4 commits intomainfrom
Open
Stop matching by phone number when upserting members in Identity#33michael-gratton wants to merge 4 commits intomainfrom
michael-gratton wants to merge 4 commits intomainfrom
Conversation
6a84df8 to
81569eb
Compare
81569eb to
6b45cbc
Compare
This gets use to create Spoke CampaignContact objects, and that object's `external_id` attribute is a string.
For Twilio at least, this is a generated incoming number, and will possibly be different for each campaign contact. If message.user is nil, we simply don't know which Spoke backend account was involved. That should never be the case for outging messages - i.e. messages the user sends to a campaign contact, but seems to be always the case for incoming messages - i.e. replies from the campaign contact to a message. Since Contact.contactee cannot be nil (but Contact.contactor can be) it means that the Contact.contactee must always be the Spoke campaign contact, and the Contact.contactor must be the Spoke user given by message.user (if known), even for incoming messages. This sits a bit awkwardly, but if you think about contactor/contactee as being the people originating and receiving messages for the campaign as a whole (i.e. not from a per-message perspective) it makes a bit of sense. Note also that since conversations can be re-assigned, we can't just rely on "whoever sent the first message" to work out who will pick up and reply to any incoming messages, either. Best not make a guess that may well be in correct.
In general since our member phone number data quality is so poor (we have many members with duplicate phone numbers), we can't rely on matching against the phone number when pulling Spoke data into Identity. When pulling messages and opt-outs, if an external id for a Spoke Campaign contact is set, use that when both pulling messages - the external id came from Identity so we know what member is involved. If not we must create a new member every time - because if there is zero matching members, we need to create one; if there is one matching member, that member could have a bad phone number, so we can't assume it's them, so create a new one; if there are multiple members with matching numbers, we can't pick the right one reliably, so create a new one. For Spoke users, upsert based on their known email address, because that is more reliable. In all cases, update external ids in Spoke when one is not known, so if multiple contacts are processed for a newly upserted member, the same member is used for all further contacts in the same campaign.
6b45cbc to
14eec0b
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In general since our member phone number data quality is so poor (we have many members with duplicate phone numbers), we can't rely on matching against the phone number when pulling Spoke data into Identity.
When pulling messages and opt-outs, if an external id for a Spoke
CampaignContactis set, use that to look up the member - the external id came from Identity so we know what member is involved.If not we must create a new member every time - because if there is zero matching members, we need to create one; if there is one matching member, that member could have a bad phone number, so we can't assume it's them, so create a new one; if there are multiple members with matching numbers, we can't pick the right one reliably, so create a new one.
For Spoke users, upsert based on their known email address, because that is more reliable.
In all cases, update external ids in Spoke when one is not known, so if multiple contacts are processed for a newly upserted member, the same member is used for all further contacts in the same campaign.