-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use different CustomerIO templates and edit slack notifs (#12674)
* Use different CustomerIO templates and edit slack notifs * fix unit test * fix file naming and comments
- Loading branch information
1 parent
c7a3ab5
commit cd61364
Showing
11 changed files
with
110 additions
and
84 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 |
---|---|---|
|
@@ -12,35 +12,37 @@ | |
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.UUID; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Notification client that uses customer.io API send emails. | ||
* | ||
* These notifications rely on `TRANSACTION_MESSAGE_ID`, which are basically templates you create | ||
* through customer.io. These IDs are specific to a user's account on customer.io, so they will be | ||
* different for every user. For now they are stored as variables here, but in the future they may | ||
* be stored in as a notification config in the database. | ||
* | ||
* For Airbyte Cloud, Airbyte engineers may use `DEFAULT_TRANSACTION_MESSAGE_ID = "6"` as a generic | ||
* template for notifications. | ||
*/ | ||
public class CustomeriolNotificationClient extends NotificationClient { | ||
public class CustomerioNotificationClient extends NotificationClient { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CustomeriolNotificationClient.class); | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerioNotificationClient.class); | ||
|
||
// Once the configs are editable through the UI, these should be stored in | ||
// airbyte-config/models/src/main/resources/types/CustomerioNotificationConfiguration.yaml | ||
// - SENDER_EMAIL | ||
// - receiver email | ||
// - customer.io identifier email | ||
// - customer.io TRANSACTION_MESSAGE_ID | ||
private static final String SENDER_EMAIL = "Airbyte Notification <[email protected]>"; | ||
private static final String TRANSACTION_MESSAGE_ID = "6"; | ||
private static final String AUTO_DISABLE_TRANSACTION_MESSAGE_ID = "7"; | ||
private static final String AUTO_DISABLE_WARNING_TRANSACTION_MESSAGE_ID = "8"; | ||
|
||
private static final String CUSTOMERIO_EMAIL_API_ENDPOINT = "https://api.customer.io/v1/send/email"; | ||
private static final String AUTO_DISABLE_NOTIFICATION_TEMPLATE_PATH = "customerio/auto_disable_notification_template.json"; | ||
private static final String AUTO_DISABLE_WARNING_NOTIFICATION_TEMPLATE_PATH = "customerio/auto_disable_warning_notification_template.json"; | ||
|
||
private final HttpClient httpClient; | ||
private final String apiToken; | ||
private final String emailApiEndpoint; | ||
|
||
public CustomeriolNotificationClient(final Notification notification) { | ||
public CustomerioNotificationClient(final Notification notification) { | ||
super(notification); | ||
this.apiToken = System.getenv("CUSTOMERIO_API_KEY"); | ||
this.emailApiEndpoint = CUSTOMERIO_EMAIL_API_ENDPOINT; | ||
|
@@ -50,10 +52,10 @@ public CustomeriolNotificationClient(final Notification notification) { | |
} | ||
|
||
@VisibleForTesting | ||
public CustomeriolNotificationClient(final Notification notification, | ||
final String apiToken, | ||
final String emailApiEndpoint, | ||
final HttpClient httpClient) { | ||
public CustomerioNotificationClient(final Notification notification, | ||
final String apiToken, | ||
final String emailApiEndpoint, | ||
final HttpClient httpClient) { | ||
super(notification); | ||
this.apiToken = apiToken; | ||
this.emailApiEndpoint = emailApiEndpoint; | ||
|
@@ -72,28 +74,32 @@ public boolean notifyJobSuccess(final String sourceConnector, final String desti | |
throw new NotImplementedException(); | ||
} | ||
|
||
// Once the configs are editable through the UI, the reciever email should be stored in | ||
// airbyte-config/models/src/main/resources/types/CustomerioNotificationConfiguration.yaml | ||
// instead of being passed in | ||
@Override | ||
public boolean notifyConnectionDisabled(final String receiverEmail, | ||
final String sourceConnector, | ||
final String destinationConnector, | ||
final String jobDescription, | ||
final String logUrl) | ||
final UUID workspaceId, | ||
final UUID connectionId) | ||
throws IOException, InterruptedException { | ||
final String requestBody = renderTemplate(AUTO_DISABLE_NOTIFICATION_TEMPLATE_PATH, TRANSACTION_MESSAGE_ID, SENDER_EMAIL, receiverEmail, | ||
receiverEmail, sourceConnector, destinationConnector, jobDescription, logUrl); | ||
final String requestBody = renderTemplate(AUTO_DISABLE_NOTIFICATION_TEMPLATE_PATH, AUTO_DISABLE_TRANSACTION_MESSAGE_ID, receiverEmail, | ||
receiverEmail, sourceConnector, destinationConnector, jobDescription, workspaceId.toString(), connectionId.toString()); | ||
return notifyByEmail(requestBody); | ||
} | ||
|
||
@Override | ||
public boolean notifyConnectionDisableWarning( | ||
final String receiverEmail, | ||
public boolean notifyConnectionDisableWarning(final String receiverEmail, | ||
final String sourceConnector, | ||
final String destinationConnector, | ||
final String jobDescription, | ||
final String logUrl) | ||
final UUID workspaceId, | ||
final UUID connectionId) | ||
throws IOException, InterruptedException { | ||
final String requestBody = renderTemplate(AUTO_DISABLE_WARNING_NOTIFICATION_TEMPLATE_PATH, TRANSACTION_MESSAGE_ID, SENDER_EMAIL, receiverEmail, | ||
receiverEmail, sourceConnector, destinationConnector, jobDescription, logUrl); | ||
final String requestBody = renderTemplate(AUTO_DISABLE_NOTIFICATION_TEMPLATE_PATH, AUTO_DISABLE_WARNING_TRANSACTION_MESSAGE_ID, receiverEmail, | ||
receiverEmail, sourceConnector, destinationConnector, jobDescription, workspaceId.toString(), connectionId.toString()); | ||
return notifyByEmail(requestBody); | ||
} | ||
|
||
|
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
11 changes: 6 additions & 5 deletions
11
airbyte-notification/src/main/resources/customerio/auto_disable_notification_template.json
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,19 +1,20 @@ | ||
{ | ||
"transactional_message_id": "%s", | ||
"from": "%s", | ||
"subject": "Automatic Notification: Your Airbyte connection has been disabled", | ||
"to": "%s", | ||
"identifiers": { | ||
"email": "%s" | ||
}, | ||
"message_data": { | ||
"email_title": "Automatic Notification: Connection Disabled", | ||
"email_body": "Your connection from <b>%s</b> to <b>%s</b> was automatically disabled because it failed 100 times consecutively or has been failing for 14 days in a row.<p>Please address the failing issues to ensure your syncs continue to run. The most recent attempted %s You can access its logs here: %s.<p>If you need help with resolving your connection, reach out to Support in-app or by emailing [email protected]." | ||
"source": "%s", | ||
"destination": "%s", | ||
"job_description": "%s", | ||
"connection_id": "%s", | ||
"workspace_id": "%s" | ||
}, | ||
|
||
"disable_message_retention": false, | ||
"send_to_unsubscribed": true, | ||
"tracked": true, | ||
"tracked": false, | ||
"queue_draft": false, | ||
"disable_css_preprocessing": true | ||
} |
19 changes: 0 additions & 19 deletions
19
...otification/src/main/resources/customerio/auto_disable_warning_notification_template.json
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
airbyte-notification/src/main/resources/customerio/default_template.json
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,17 @@ | ||
{ | ||
"transactional_message_id": "%s", | ||
"to": "%s", | ||
"identifiers": { | ||
"email": "%s" | ||
}, | ||
"message_data": { | ||
"email_title": "%s", | ||
"email_body": "%s" | ||
}, | ||
|
||
"disable_message_retention": false, | ||
"send_to_unsubscribed": true, | ||
"tracked": true, | ||
"queue_draft": false, | ||
"disable_css_preprocessing": true | ||
} |
5 changes: 4 additions & 1 deletion
5
airbyte-notification/src/main/resources/slack/auto_disable_slack_notification_template.txt
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,3 +1,6 @@ | ||
Your connection from %s to %s was automatically disabled because it failed 100 times consecutively or has been failing for 14 days in a row. | ||
|
||
Please address the failing issues to ensure your syncs continue to run. The most recent attempted %s You can access its logs here: %s. | ||
Please address the failing issues to ensure your syncs continue to run. The most recent attempted %s | ||
|
||
Workspace ID: %s | ||
Connection ID: %s |
5 changes: 4 additions & 1 deletion
5
...otification/src/main/resources/slack/auto_disable_warning_slack_notification_template.txt
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,3 +1,6 @@ | ||
Your connection from %s to %s is scheduled to be automatically disabled because it either failed 50 times consecutively or there were only failed jobs in the past 7 days. Once it has failed 100 times consecutively or has been failing for 14 days in a row, the connection will be automatically disabled. | ||
|
||
Please address the failing issues to ensure your syncs continue to run. The most recent attempted %s You can access its logs here: %s. | ||
Please address the failing issues to ensure your syncs continue to run. The most recent attempted %s | ||
|
||
Workspace ID: %s | ||
Connection ID: %s |
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
Oops, something went wrong.