-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from Open-Earth-Foundation/feature/send-notif…
…ication Feature/send notification
- Loading branch information
Showing
9 changed files
with
357 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,8 @@ jobs: | |
kubectl set env deployment/cc-web-deploy CHAT_PROVIDER=openai | ||
kubectl set env deployment/cc-web-deploy OPENAI_API_KEY=${{secrets.OPENAI_API_KEY}} | ||
kubectl set env deployment/cc-web-deploy HUGGINGFACE_API_KEY=${{secrets.HUGGINGFACE_API_KEY}} | ||
kubectl set env deployment/cc-web-deploy ADMIN_EMAILS="[email protected],[email protected],[email protected]" | ||
kubectl set env deployment/cc-web-deploy ADMIN_NAMES=${{secrets.ADMIN_NAMES}} | ||
kubectl set env deployment/cc-web-deploy "DEFAULT_ADMIN_EMAIL=${{secrets.DEFAULT_ADMIN_EMAIL}}" | ||
kubectl set env deployment/cc-web-deploy "DEFAULT_ADMIN_PASSWORD=${{secrets.DEFAULT_ADMIN_PASSWORD}}" | ||
kubectl create -f k8s/cc-create-admin.yml -n default | ||
|
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 |
---|---|---|
|
@@ -17,4 +17,6 @@ VERIFICATION_TOKEN_SECRET="80c70dfdeedf2c01757b880d39c79214e915c786dd48d5473c9c0 | |
HUGGINGFACE_API_KEY=hf_MY_SECRET_KEY | ||
OPENAI_API_KEY=sk-MY_SECRET_KEY | ||
CHAT_PROVIDER=huggingface | ||
ADMIN_EMAILS="[email protected]" | ||
ADMIN_NAMES="John doe" | ||
NEXT_PUBLIC_OPENCLIMATE_API_URL="https://openclimate.openearth.dev" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { smtpOptions } from "@/lib/email"; | ||
import nodemailer, { Transporter } from "nodemailer"; | ||
|
||
interface EmailOptions { | ||
to: string; | ||
subject: string; | ||
text: string; | ||
html: string; | ||
} | ||
|
||
interface SendEmailResponse { | ||
success: boolean; | ||
messageId?: string; | ||
error?: any; | ||
} | ||
|
||
class NotificationService { | ||
private transporter: Transporter; | ||
constructor() { | ||
this.transporter = nodemailer.createTransport({ ...smtpOptions }); | ||
} | ||
|
||
async sendEmail({ | ||
to, | ||
subject, | ||
text, | ||
html, | ||
}: EmailOptions): Promise<SendEmailResponse> { | ||
const mailOptions = { | ||
from: "", | ||
to, | ||
subject, | ||
text, | ||
html, | ||
}; | ||
|
||
try { | ||
const info = await this.transporter.sendMail(mailOptions); | ||
console.log("Message sent: %s", info.messageId); | ||
return { success: true, messageId: info.messageId }; | ||
} catch (error) { | ||
console.error("Error sending email:", error); | ||
return { success: false, error }; | ||
} | ||
} | ||
} | ||
|
||
export default NotificationService; |
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.