-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support sending email message via Notifications passthrough API #406
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import org.opensearch.commons.authuser.User | |
import org.opensearch.commons.destination.message.LegacyBaseMessage | ||
import org.opensearch.commons.destination.message.LegacyCustomWebhookMessage | ||
import org.opensearch.commons.destination.message.LegacyDestinationType | ||
import org.opensearch.commons.destination.message.LegacyEmailMessage | ||
import org.opensearch.commons.destination.response.LegacyDestinationResponse | ||
import org.opensearch.commons.notifications.action.LegacyPublishNotificationRequest | ||
import org.opensearch.commons.notifications.action.LegacyPublishNotificationResponse | ||
|
@@ -265,7 +266,7 @@ object SendMessageActionHelper { | |
* @return notification delivery status for the legacy destination | ||
*/ | ||
private fun sendMessageToLegacyDestination(baseMessage: LegacyBaseMessage): LegacyDestinationResponse { | ||
val message = | ||
var message = | ||
MessageContent(title = "Legacy Notification", textDescription = baseMessage.messageContent) | ||
// These legacy destination calls do not have reference Ids, just passing 'legacy' constant | ||
return when (baseMessage.channelType) { | ||
|
@@ -291,6 +292,45 @@ object SendMessageActionHelper { | |
LegacyDestinationResponse.Builder().withStatusCode(status.statusCode) | ||
.withResponseContent(status.statusText).build() | ||
} | ||
LegacyDestinationType.LEGACY_EMAIL -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not re-use the logic from |
||
val recipients = (baseMessage as LegacyEmailMessage).recipients | ||
// The naming is a little confusing but need to use the subject from LegacyEmailMessage as the title, | ||
// so it appears as the subject of the email | ||
message = MessageContent(title = baseMessage.subject, textDescription = baseMessage.messageContent) | ||
runBlocking { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we plan to simplify this blocking call in the future? |
||
val emailRecipientStatus: List<EmailRecipientStatus> = recipients.map { | ||
async(Dispatchers.IO) { | ||
val destination = SmtpDestination( | ||
baseMessage.accountName, | ||
baseMessage.host, | ||
baseMessage.port, | ||
baseMessage.method, | ||
baseMessage.from, | ||
it | ||
) | ||
val status = sendMessageThroughSpi(destination, message, "legacy") | ||
EmailRecipientStatus( | ||
it, | ||
DeliveryStatus(status.statusCode.toString(), status.statusText) | ||
) | ||
} | ||
}.awaitAll() | ||
|
||
val firstStatus = emailRecipientStatus.first() | ||
var overallStatus = firstStatus.deliveryStatus.statusCode | ||
var overallStatusText = firstStatus.deliveryStatus.statusText | ||
emailRecipientStatus.forEach { | ||
val status = it.deliveryStatus | ||
log.info("$LOG_PREFIX:Legacy email:statusCode=${status.statusCode}, statusText=${status.statusText}") | ||
if (overallStatus != status.statusCode) { | ||
overallStatus = RestStatus.MULTI_STATUS.status.toString() | ||
overallStatusText = "Errors" | ||
} | ||
} | ||
LegacyDestinationResponse.Builder().withStatusCode(overallStatus.toInt()) | ||
.withResponseContent(overallStatusText).build() | ||
} | ||
} | ||
null -> { | ||
log.warn("No channel type given (null) for publishing to legacy destination") | ||
LegacyDestinationResponse.Builder().withStatusCode(400) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have a unit test for fallback case?