When multiple recipients use different Personalization object for each of the recipient

Created on 6 October 2023, about 1 year ago

Problem/Motivation

Currently the sendgrid_integration module always builds the personalization object as a single item, even if there are multiple recipients . The multiple recipients gets added to the 'To' object and they all share the same Personalization keys, such as substitiutions.

In older version of the module, you could send an array of substitutions like this:

$message['sendgrid']['substitutions'] = [
 '%token%' => [
    0 => "test",
    1 => "test2",
  ],
];

This would match the array key with the recipient key and replace the tokens, so it was possible to send the same email with different substitutions based on the recipient.

In the new version this is no longer possible, the v3 version of Sendgrid API is no longer accepting array as values for the 'subsitutions' key, but rather is has to be a string. If you want to apply the same `substitution` to multiple recipients, then you need to build a separate Personalization object for each of the recipient and add the substitution there. With current implementation in the module this is not possible as it will always threat one mail as a single personalization object.

You can read more about the problem here: https://stackoverflow.com/questions/40382948/sendgrid-web-api-v3-differe...

Steps to reproduce

1. Create an email with multiple recipients that contains a token/substitution
2. Try to use the same substitution key and display different values based on the recipient.

Proposed resolution

1. Refactor the personalization part, and always build a seperate personalization object for each of the recipient.

2. When adding substitutions, check if the value is an array and if so match the array keys with recipients and add the correct substitution to their personalization object.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇸🇮Slovenia nkoporec Slovenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024