Skip to content
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

[FEAT] Sending Message Using Template(in the Background) with Variable Substitution #242

Closed
PcNerd9 opened this issue Jul 18, 2024 · 1 comment
Labels
feature Needs Revision When there is an issue and it needs to be revised

Comments

@PcNerd9
Copy link

PcNerd9 commented Jul 18, 2024

Description

Develop an endpoint to handle requests for sending emails using pre-defined templates. The emails should be sent in the background to ensure the application remains responsive. The endpoint should also handle variable substitution, replacing placeholders in the templates with actual data.

Acceptance Criteria

  • The endpoint should receive requests to send emails using specific templates.
  • The endpoint should handle variable substitution to replace placeholders with actual data.
  • The email sending process should be handled in the background using a task queue.
  • The endpoint should return appropriate status codes and responses based on the outcome of the request.
  • Endpoints should be correctly versioned.

Requirements

  • Implement an API endpoint for sending emails using templates.
  • Handle variable substitution for placeholders in the email templates.
  • Use a task queue system to send emails in the background.
  • Handle unexpected errors and return the appropriate status codes.
  • Endpoints should be correctly versioned.

Expected Outcome

  • Users should be able to send requests to the backend to send emails using templates.
  • Users should receive appropriate status codes and responses based on the outcome of the requests.
  • Emails should be sent in the background without blocking the main application flow.

Endpoints

[POST] /api/v1/send-email

Description: Sends an email using a specified template.

Request Body:

{
  "template_id": 1,
  "recipient": "john.doe@example.com",
  "variables": {
    "name": "John Doe",
    "product": "Wireless Headphones",
    "order_number": 12345
  }
}

Success Response:
Status Code: 202 Accepted
Body:

{
  "message": "Email sending request accepted and is being processed in the background."
}

###Error Responses
Internal Server Error
Status Code: 500 Internal Server Error
Body:

{
  "error": "Internal server error."
}

Not Found
Status Code: 404 Not Found
Body:

{
  "error": "This method is not allowed."
}

Invalid Method
Status Code: 405 Method Not Allowed
Body:

{
  "error": "This method is not allowed."
}

Bad Request
Status Code: 400 Bad Request
Body:

{
  "error": "An invalid request was sent."
}

Testing

Test Scenarios

  1. Successful Email Sending Request

    • Ensure that the endpoint accepts a request to send an email using a template.
    • Verify that the response indicates the request is being processed in the background.
    • Confirm that the status code is 202 Accepted.
  2. Template Not Found

    • Simulate a scenario where the specified email template ID does not exist.
    • Confirm that the response body contains an appropriate error message.
    • Confirm that the status code is 404 Not Found.
  3. Internal Server Error

    • Simulate an internal server error to raise an exception.
    • Verify that the endpoint returns a 500 Internal Server Error status code.
    • Confirm that the response body contains an appropriate error message.
  4. Invalid Method

    • Send a request using an invalid HTTP method (e.g., GET) to the endpoint.
    • Verify that the endpoint returns a 405 Method Not Allowed status code.
    • Confirm that the response body contains an appropriate error message.
  5. Bad Request

    • Send a request with invalid data (e.g., missing required fields) to the endpoint.
    • Verify that the endpoint returns a 400 Bad Request status code.
    • Confirm that the response body contains an appropriate error message.
@markessien
Copy link

This is done in two steps:

  1. The email is placed in a db queue for sending
  2. The email is retrieved from queue and dispatched.

Split this second part into a different ticket. Second part must be done with celery/rabbit

@markessien markessien added the Needs Revision When there is an issue and it needs to be revised label Jul 19, 2024
@PcNerd9 PcNerd9 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Needs Revision When there is an issue and it needs to be revised
Projects
None yet
Development

No branches or pull requests

2 participants