Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Sending contact us email and details in discord channel#359

Merged
nxtcoder17 merged 2 commits into
release-v1.0.7from
update/email-trigger
Aug 22, 2024
Merged

Sending contact us email and details in discord channel#359
nxtcoder17 merged 2 commits into
release-v1.0.7from
update/email-trigger

Conversation

@nxtcoder19
Copy link
Copy Markdown
Contributor

@nxtcoder19 nxtcoder19 commented Aug 16, 2024

Resolves kloudlite/internal-workflows#10

Summary by Sourcery

Implement a new feature to handle 'Contact Us' form submissions by sending emails and posting details to a Discord channel. This includes adding a new gRPC method, HTTP endpoint, and email template.

New Features:

  • Introduce a new feature to send 'Contact Us' emails using a new gRPC method and input structure.
  • Add a new HTTP endpoint '/contact-us' to handle contact form submissions and send details to a Discord channel.

Enhancements:

  • Integrate a new email template for 'Contact Us' emails in the comms service.

Build:

  • Add a new task in Taskfile.yml to run the webhook application with development settings.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 16, 2024

Reviewer's Guide by Sourcery

This pull request implements a new feature for sending contact us emails and posting details to a Discord channel. The changes include adding a new gRPC method for sending contact us emails, creating a new endpoint for handling contact us submissions, and updating the necessary infrastructure to support these features.

File-Level Changes

Files Changes
grpc-interfaces/kloudlite.io/rpc/comms/comms.pb.go
grpc-interfaces/kloudlite.io/rpc/comms/comms_grpc.pb.go
Added a new gRPC method 'SendContactUsEmail' to the Comms service
apps/comms/internal/app/grpc-server.go Implemented the 'SendContactUsEmail' method in the comms service
apps/webhook/internal/app/git-webhook.go Created a new endpoint '/contact-us' in the webhook service to handle contact us submissions
apps/webhook/internal/app/git-webhook.go Added functionality to send contact us details to a Discord channel
apps/webhook/internal/domain/domain.go
apps/webhook/internal/domain/api.go
Created a new domain package for the webhook service to handle contact us logic
apps/webhook/internal/env/env.go Updated environment variables to include Discord webhook URL and Comms service address
apps/comms/email-templates/contact-us/email.html Added a new HTML email template for contact us emails
go.mod
apps/webhook/Taskfile.yml
apps/webhook/internal/framework/main.go
apps/webhook/internal/app/app.go
Updated dependencies and module configurations

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nxtcoder19 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
CompanyName string `protobuf:"bytes,3,opt,name=companyName,proto3" json:"companyName,omitempty"`
Country string `protobuf:"bytes,4,opt,name=country,proto3" json:"country,omitempty"`
MobileNumber int64 `protobuf:"varint,5,opt,name=mobileNumber,proto3" json:"mobileNumber,omitempty"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using string for MobileNumber

Phone numbers often contain non-digit characters and may have leading zeros. Using a string type would be more flexible and avoid potential issues with international numbers or formatting.

	MobileNumber string `protobuf:"bytes,5,opt,name=mobileNumber,proto3" json:"mobileNumber,omitempty"`

return c.SendString("OK")
})

app.Post("/contact-us", func(ctx *fiber.Ctx) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Implement rate limiting and CAPTCHA for contact form

To prevent abuse and spam, consider adding rate limiting and a CAPTCHA mechanism to the contact form endpoint.

app.Post("/contact-us", limiter.New(limiter.Config{
    Max:        5,
    Expiration: 1 * time.Minute,
}), middleware.Captcha(), func(ctx *fiber.Ctx) error {

app.Post("/contact-us", func(ctx *fiber.Ctx) error {
var data *domain.ContactUsData

if err := ctx.BodyParser(&data); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Improve error handling specificity

Instead of returning generic error messages, consider providing more specific error responses for different types of failures. This will help with debugging and improve the API's usability.

				if err := ctx.BodyParser(&data); err != nil {
					var errMsg string
					switch {
					case errors.Is(err, fiber.ErrUnprocessableEntity):
						errMsg = "Invalid data format"
					case errors.Is(err, fiber.ErrRequestEntityTooLarge):
						errMsg = "Request payload too large"
					default:
						errMsg = "Error parsing request body"
					}
					return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": errMsg})
				}

NatsURL string `env:"NATS_URL" required:"false"`

CommsService string `env:"COMMS_SERVICE" required:"true"`
DiscordWebhookUrl string `env:"DISCORD_WEBHOOK_URL" required:"false"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Document the purpose of DiscordWebhookUrl

Add a comment explaining the purpose and usage of the DiscordWebhookUrl environment variable for better maintainability and easier configuration.

Suggested change
DiscordWebhookUrl string `env:"DISCORD_WEBHOOK_URL" required:"false"`
// DiscordWebhookUrl is the URL for sending notifications to a Discord channel.
// If set, it enables Discord integration for important system alerts.
DiscordWebhookUrl string `env:"DISCORD_WEBHOOK_URL" required:"false"`

@nxtcoder19 nxtcoder19 force-pushed the update/email-trigger branch from 653c5a3 to ebd6b6d Compare August 21, 2024 11:42
@nxtcoder17 nxtcoder17 merged commit 580ef05 into release-v1.0.7 Aug 22, 2024
@nxtcoder17 nxtcoder17 deleted the update/email-trigger branch August 22, 2024 03:23
abdheshnayak pushed a commit that referenced this pull request Nov 5, 2024
Sending contact us email and details in discord channel
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants