Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop matching by phone number when upserting members in Identity #33

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

michael-gratton
Copy link
Contributor

@michael-gratton michael-gratton commented Aug 28, 2024

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 CampaignContact is 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.

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.
@michael-gratton michael-gratton changed the title Stop matching my phone number when upserting members in Identity Stop matching by phone number when upserting members in Identity Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant