Skip to main content
Version: 1.0.0

sendQuotationRequestEmailHttp

Admin NotificationUser Confirmation
Admin Quotation Request TemplateUser Quotation Request Confirmation Template

Function Name: sendQuotationRequestEmailHttp

Author: Domenico Cerone Creation Date: 25/09/2025
Last Reviewer: Domenico Cerone

Trigger: HTTPS (onRequest)

Purpose: Manages the automatic sending of quotation request emails via ZeptoMail when a catalog order processing is completed with Excel report generation. Sends dual emails to administrators (with Excel attachment) and confirmation to the requesting user.

Detailed Functionality​

This Firebase Function handles the complete email workflow for quotation requests through a dual notification system:

1. AUTOMATIC TRIGGER​

  • Called automatically by downloadVariantJsonsHttps.js ONLY when Excel has been generated
  • Required condition: must exist excelResult with valid downloadUrl, token and fileName
  • Activation ONLY in cases of successful Excel generation (regardless of previous API errors)

2. ORDER DATA RETRIEVAL​

  • Accesses 'CatalogOrders' collection using provided orderId
  • Verifies document existence and 'excelReportUrl' property
  • Extracts necessary data: timestamp, profile, excelReportUrl, excelReportFileName
  • Retrieves ordering user's full name from 'Profiles' collection using 'profile' field as document ID

3. ORDERING USER PROFILE RETRIEVAL​

  • Uses 'profile' field from order (e.g., "92mt@live.it") as document ID
  • Accesses 'Profiles' collection to retrieve firstName and lastName of ordering user
  • Combines firstName and lastName to create full name (e.g., "Michele Telesca")
  • Fallback handling: if profile not found or data missing, uses email as fallback
  • Detailed logging to track profile retrieval process
  • Full name used for both admin email and user confirmation email

4. NOTIFICATION PREFERENCE CHECK​

  • Checks if the user has enabled the sendQuotationRequestEmailHttp notification in their notification preferences
  • Verifies notification_types.sendQuotationRequestEmailHttp field in the profile
  • If notification is disabled (false): returns success without sending email
  • If notification is enabled (true): proceeds with administrator recipients retrieval
  • Provides clear logging about notification preference status

5. ADMINISTRATOR RECIPIENTS RETRIEVAL​

  • Executes query on 'Profiles' collection with filter: role == 'Admin'
  • For each administrator found, extracts only '_email'
  • Creates recipient array using email as both address and name
  • If no admin found: terminates with 'NO_ADMIN_FOUND' error
  • If query error: terminates with 'NO_ADMIN_FOUND' error
  • Detailed logging with admin count and their emails

6. DATE FORMATTING​

  • Converts Firestore timestamp to readable English format
  • Format: "June 20, 2025 at 5:56 PM" (month day year hours:minutes)
  • Handles missing timestamp cases with fallback "Date not available"

7. ATTACHMENT DOWNLOAD AND PREPARATION​

  • Downloads Excel file from Firebase Storage URL (excelReportUrl)
  • Converts file to base64 format for email attachment
  • 30-second timeout for download with robust error handling
  • Verifies file size and validity of downloaded file

8. ADMIN EMAIL ZEPTOMAIL CONFIGURATION​

  • Template key: 13ef.8598f19fbcc5adb.k1.e8a28620-50ea-11f0-9c4e-dad70ff08860.197a19bc782
  • Sender: no-reply@arshades.com (noreply)
  • Recipients: ALL users with role='Admin' from Profiles collection
  • Merge data:
    • date: formatted timestamp date of the order
    • profile: full name of ordering user (e.g., "Michele Telesca") retrieved from Profiles collection

9. USER EMAIL ZEPTOMAIL CONFIGURATION​

  • Template key: 13ef.8598f19fbcc5adb.k1.9337a850-5e23-11f0-9e15-dad70ff08860.197f8418755
  • Sender: no-reply@arshades.com (noreply)
  • Recipient: user who made the request ('profile' field from CatalogOrders)
  • Merge data:
    • profile: user's full name (e.g., "Michele Telesca") or email if name not available
  • Message: "Hello {{profile}}, Request for quotation sent successfully!"
  • Sent immediately after admin email to confirm request to user

10. ATTACHMENT HANDLING​

  • File name: excelReportFileName (default: "report.xlsx")
  • MIME type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • Content: Excel file converted to base64
  • Maximum manageable size: limited by available memory
  • Attachment ONLY to admin email, NOT to user confirmation email

11. MULTIPLE EMAIL SENDING AND CONFIRMATION​

  • First email: simultaneous sending to all administrators in single API call
  • Second email: immediate sending to user for request confirmation
  • Logging with recipient count and email list for traceability
  • Asynchronous handling with Promise for optimal performance
  • Returns results of both sends in response

12. ERROR HANDLING AND LOGGING​

  • Detailed logging for each phase of the process
  • Separate error handling: order not found, Excel missing, admins not found, download failed, sending failed
  • Structured return with success/failure, admin count and email list
  • If no admin found: returns error instead of sending email
  • Does not interrupt main process in case of email error
  • Separate tracking of sending results for admin email and user email

Technical Features​

  • PROTOCOL: HTTPS with TLS for security
  • TIMEOUT: 30 seconds for attachment downloads
  • FORMAT: Custom HTML email templates (2 different templates)
  • ATTACHMENTS: Complete support for Excel files (.xlsx)
  • ENCODING: Base64 for binary attachments
  • LOCALIZATION: Date in English format
  • LOGGING: Complete for debugging and monitoring
  • RESILIENCE: Non-blocking error handling

Integration​

  • Called by: downloadVariantJsonsHttps.js
  • Input: orderId (string)
  • Output: {success: boolean, message: string, emailResult?: object, userEmailResult?: object, error?: string}
  • Dependencies: Firebase Firestore, ZeptoMail, Axios

Input (Payload):​

{
"orderId": "xq02X2a6CEFVoQtZd5Pa"
}

Parameters:

  • orderId (string, required): ID of the catalog order document in the 'CatalogOrders' collection

Output (Success):​

{
"success": true,
"message": "Quotation request email sent successfully to 3 administrators and to user Michele Telesca for order xq02X2a6CEFVoQtZd5Pa",
"emailResult": {
"request_id": "1234567890abcdef",
"message": "Email sent successfully"
},
"userEmailResult": {
"request_id": "abcdef1234567890",
"message": "User confirmation email sent successfully"
},
"attachmentIncluded": true,
"adminCount": 3,
"adminEmails": [
"admin1@arshades.com",
"admin2@arshades.com",
"admin3@arshades.com"
]
}

Response Properties:

  • success (boolean): Indicates if the operation was completed successfully
  • message (string): Descriptive message of the email sending results
  • emailResult (object): Complete response from admin email sending
  • userEmailResult (object): Complete response from user confirmation email sending
  • attachmentIncluded (boolean): Indicates if Excel attachment was included
  • adminCount (number): Number of administrators who received the email
  • adminEmails (array): List of administrator emails that received the notification

This output is returned in the HTTP response (Postman, browser, curl).

Testing​

URL (if HTTPS): http://127.0.0.1:5001/arshadesstaging/europe-central2/sendQuotationRequestEmailHttp

Test with Emulator:

  1. Start the Firebase emulator: firebase emulators:start --only functions
  2. Ensure you're using Node.js version 20: nvm use 20
  3. Test with curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/sendQuotationRequestEmailHttp" \
-H "Content-Type: application/json" \
-d '{"orderId": "xq02X2a6CEFVoQtZd5Pa"}'

Postman Testing:

Deploy Command:​

firebase deploy --only functions:sendQuotationRequestEmailHttp

Production URL:​

sendQuotationRequestEmailHttp: https://europe-central2-arshades-7e18a.cloudfunctions.net/sendQuotationRequestEmailHttp