-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(developer): Automatic sign up for email marketing
refs #288
- Loading branch information
Showing
5 changed files
with
142 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
LEGACY_PEPPER=some pepper value | ||
SENDGRID_API_KEY=some sendgrid api key |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import client from '@sendgrid/client'; | ||
|
||
export const mailingListSignUp = async (data, apiKey) => { | ||
client.setApiKey(apiKey); | ||
|
||
let response; | ||
const [first_name, last_name] = data.displayName.split(' '); | ||
|
||
const body = { | ||
list_ids: ['272a49d6-7d98-46bd-9312-7310e8e73ba9'], | ||
contacts: [ | ||
{ | ||
email: data.email, | ||
first_name, | ||
last_name, | ||
}, | ||
], | ||
}; | ||
|
||
try { | ||
response = await client.request({ | ||
method: 'PUT', | ||
url: '/v3/marketing/contacts', | ||
body, | ||
}); | ||
|
||
if (response.statusCode !== 202) { | ||
error('[mail::mailingListSignUp] sendgrid job error', { | ||
response: response.body, | ||
data, | ||
}); | ||
|
||
return false; | ||
} | ||
} catch (errorMessage) { | ||
error('[mail::mailingListSignUp] sendgrid error', { | ||
errorMessage, | ||
data, | ||
}); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Did you mean to send the API key to the createUser function?