Skip to content

Add recipient list functionality #19

@kentico-matthews

Description

@kentico-matthews

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:

  1. A recipient list
    • ContactGroupInfo (ContactGroupIsRecipientList set to true)
    • RecipientListSettingsInfo
  2. Bindings between the contact and recipient list (specifically the ContactGroupInfo representing it)
    • ContactGroupMemberInfo
    • EmailSubscriptionConfirmationInfo (EmailSubscriptionConfirmationIsApproved set 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions