diff --git a/events/cognito.go b/events/cognito.go index c24a3e3e..a61b03d9 100644 --- a/events/cognito.go +++ b/events/cognito.go @@ -266,3 +266,24 @@ type CognitoEventUserPoolsCustomMessageResponse struct { EmailMessage string `json:"emailMessage"` EmailSubject string `json:"emailSubject"` } + +// CognitoEventUserPoolsCustomEmailSender is sent by AWS Cognito User Pools before each mail to send. +type CognitoEventUserPoolsCustomEmailSender struct { + CognitoEventUserPoolsHeader + Request CognitoEventUserPoolsCustomEmailSenderRequest `json:"request"` + Response CognitoEventUserPoolsCustomEmailSenderResponse `json:"response"` +} + +// CognitoEventUserPoolsCustomEmailSenderRequest contains the request portion of a CustomEmailSender event +type CognitoEventUserPoolsCustomEmailSenderRequest struct { + UserAttributes map[string]interface{} `json:"userAttributes"` + Code string `json:"code"` + ClientMetadata map[string]string `json:"clientMetadata"` + Type string `json:"type"` +} + +// CognitoEventUserPoolsCustomEmailSenderResponse contains the response portion of a CustomEmailSender event +type CognitoEventUserPoolsCustomEmailSenderResponse struct { + EmailMessage string `json:"emailMessage"` + EmailSubject string `json:"emailSubject"` +} diff --git a/events/cognito_test.go b/events/cognito_test.go index fdb1d437..a0fbab91 100644 --- a/events/cognito_test.go +++ b/events/cognito_test.go @@ -240,3 +240,29 @@ func TestCognitoEventUserPoolsCustomMessageMarshaling(t *testing.T) { func TestCognitoUserPoolsCustomMessageMarshalingMalformedJson(t *testing.T) { test.TestMalformedJson(t, CognitoEventUserPoolsCustomMessage{}) } + +func TestCognitoEventUserPoolsCustomEmailSenderMarshaling(t *testing.T) { + // read json from file + inputJSON, err := ioutil.ReadFile("./testdata/cognito-event-userpools-customemailsender.json") + if err != nil { + t.Errorf("could not open test file. details: %v", err) + } + + // de-serialize into CognitoEvent + var inputEvent CognitoEventUserPoolsCustomEmailSender + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { + t.Errorf("could not unmarshal event. details: %v", err) + } + + // serialize to json + outputJSON, err := json.Marshal(inputEvent) + if err != nil { + t.Errorf("could not marshal event. details: %v", err) + } + + assert.JSONEq(t, string(inputJSON), string(outputJSON)) +} + +func TestCognitoUserPoolsCustomEmailSenderMarshalingMalformedJson(t *testing.T) { + test.TestMalformedJson(t, CognitoEventUserPoolsCustomEmailSender{}) +} diff --git a/events/testdata/cognito-event-userpools-customemailsender.json b/events/testdata/cognito-event-userpools-customemailsender.json new file mode 100644 index 00000000..f9087f12 --- /dev/null +++ b/events/testdata/cognito-event-userpools-customemailsender.json @@ -0,0 +1,26 @@ +{ + "version": "1", + "triggerSource": "CustomEmailSender_SignUp/CustomEmailSender_ResendCode/CustomEmailSender_ForgotPassword/CustomEmailSender_UpdateUserAttribute/CustomEmailSender_VerifyUserAttribute/CustomEmailSender_AdminCreateUser", + "region": "", + "userPoolId": "", + "userName": "", + "callerContext": { + "awsSdkVersion": "", + "clientId": "" + }, + "request": { + "userAttributes": { + "phone_number_verified": true, + "email_verified": false + }, + "code": "example code", + "clientMetadata": { + "exampleMetadataKey": "example metadata value" + }, + "type": "example type" + }, + "response": { + "emailMessage": "", + "emailSubject": "" + } +}