generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Add functionality that allows importing contacts to recipient lists
There are some cases where contacts have consented to receive emails in some external system, so forcing them to go through the subscription flow in Xperience does not make sense.
To accomplish this you need the following:
- A recipient list
ContactGroupInfo(ContactGroupIsRecipientListset to true)RecipientListSettingsInfo
- Bindings between the contact and recipient list (specifically the
ContactGroupInforepresenting it)ContactGroupMemberInfoEmailSubscriptionConfirmationInfo(EmailSubscriptionConfirmationIsApprovedset to true)
A rough sketch of the code would look something like this:
// Inject these
private readonly IInfoProvider<ContactGroupMemberInfo> contactGroupMemberInfoProvider;
private readonly IInfoProvider<EmailSubscriptionConfirmationInfo> emailSubscriptionConfirmationInfoProvider;
private readonly IInfoProvider<ContactInfo> contactInfoProvider;
int recipientListContactGroupID = XX;
List<ContactGroupMemberInfo> groupMemberList = new();
List<EmailSubscriptionConfirmationInfo> subscriptionConfirmationList = new();
// Subquery - doesn't execute here because we don't enumerate its result
existingRecipientIdSubquery = contactGroupMemberInfoProvider.Get()
.WhereEquals(nameof(ContactGroupMemberInfo.ContactGroupMemberType), ContactGroupMemberTypeEnum.Contact)
.WhereEquals(nameof(ContactGroupInfo.ContactGroupMemberContactGroupID), recipientListContactGroupID)
.Column(nameof(ContactGroupMemberRelatedID));
// Query utilizing subquery
var contactIDs = await contactInfoProvider.Get()
.WhereNotIn(nameof(ContactInfo.ContactId), existingRecipientIdSubquery)
.WhereIn(nameof(ContactInfo.ContactGUID), theContactGuidsFromTheCSV)
.Column(nameof(ContactInfo.ContactId))
.GetListResultAsync<int>();
foreach (int contactID in contactIDs)
{
// Add the current contact to the contact group representing the recipient list
groupMemberList.Add( new ContactGroupMemberInfo {
ContactGroupMemberRelatedID = contactID,
ContactGroupMemberType = ContactGroupMemberTypeEnum.Contact,
ContactGroupMemberContactGroupID = recipientListContactGroupID,
...
});
// Add a subscription confirmation for the current contact
// Add some kind of disclaimer that users of the tool must ensure recipients have consented/opted in at some point
subscriptionConfirmationList.Add( new EmailSubscriptionConfirmationInfo {
EmailSubscriptionConfirmationContactID = contactID,
EmailSubscriptionConfirmationRecipientListID = recipientListContactGroupID,
EmailSubscriptionConfirmationIsApproved = true,
EmailSubscriptionConfirmationDate = DateTime.Now(),
...
});
}
// Just one query to insert all group members
contactGroupMemberInfoProvider.BulkInsert(groupMemberList);
// Just one query to insert all subscription confirmations
emailSubscriptionConfirmationInfoProvider.BulkInsert(subscriptionConfirmationList);
Metadata
Metadata
Assignees
Labels
No labels