-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
117 additions
and
23 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
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
86 changes: 86 additions & 0 deletions
86
ChatGPT/src/main/java/cloud/cleo/squareup/functions/SendEmail.java
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,86 @@ | ||
package cloud.cleo.squareup.functions; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
import java.util.function.Function; | ||
import software.amazon.awssdk.services.ses.SesClient; | ||
|
||
/** | ||
* Send an Email message | ||
* | ||
* @author sjensen | ||
* @param <Request> | ||
*/ | ||
public class SendEmail<Request> extends AbstractFunction { | ||
|
||
@Override | ||
public String getName() { | ||
return "send_email_message"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Send Email message to an employee, use to relay information to an employee"; | ||
} | ||
|
||
@Override | ||
public Class getRequestClass() { | ||
return Request.class; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
@Override | ||
public Function<Request, Object> getExecutor() { | ||
return (var r) -> { | ||
|
||
try { | ||
final var ses = SesClient.create(); | ||
final var id = ses.sendEmail((email) -> { | ||
email.destination(dest -> dest.toAddresses(r.employee_email)) | ||
.message((mesg) -> { | ||
mesg.body((body) -> { | ||
body.text(cont -> cont.data(r.message)); | ||
}).subject(cont -> cont.data(r.subject)); | ||
}).source("[email protected]"); | ||
}); | ||
|
||
log.info("Sent email to " + r.employee_email + " with id " + id); | ||
log.info("Subject: " + r.subject); | ||
log.info("Message: " + r.message); | ||
return mapper.createObjectNode().put("status", "SUCCESS").put("message", "The email has been successfuly sent."); | ||
} catch (Exception e) { | ||
log.error("Unhandled Error", e); | ||
return mapper.createObjectNode().put("status", "FAILED").put("message", "An error has occurred, the email could not be sent."); | ||
} | ||
}; | ||
} | ||
|
||
private static class Request { | ||
|
||
@JsonPropertyDescription("The employee email address") | ||
@JsonProperty(required = true) | ||
public String employee_email; | ||
|
||
@JsonPropertyDescription("Subject for the email message") | ||
@JsonProperty(required = true) | ||
public String subject; | ||
|
||
@JsonPropertyDescription("The message body to relay to the employee") | ||
@JsonProperty(required = true) | ||
public String message; | ||
} | ||
|
||
/** | ||
* Square must be enabled or their won't be a way to get email addresses | ||
* | ||
* @return | ||
*/ | ||
@Override | ||
protected boolean isEnabled() { | ||
return squareEnabled; | ||
} | ||
|
||
} |
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
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
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