incomingWebhook.jsThis function serves as the main entry point for handling incoming webhooks.
The main exported handler in this function does the following:
validateWebhookPayloadsaveWebhookprocessEventsresponse: Constructs a response object given a status code and body.validateWebhookPayload: Validates the provided webhook payload, ensuring it's properly formatted as JSON. Returns parsed JSON or null if invalid.processEvents: Processes each event in the provided events array. This involves:
getDealData: Fetches deal data from the Velocity API given specific parameters, specifically a loan code.The function makes use of the following dependencies:
axios - For making HTTP requests.dotenv - For loading environment variables.This main function relies on a couple of backend utility functions imported from other modules:
saveWebhook - Saves the webhook data. The specific logic of this function isn't detailed in the provided code.ghHandler - A collection of methods for sending specific sets of data to GoHighLevel.saveWebhook.jsThis function is responsible for saving the incoming webhook data to an AWS S3 bucket.
The function leverages the following modules:
AWS - For interfacing with AWS services, specifically S3.path - For handling and manipulating file paths.dotenv - For loading environment variables.The function utilizes the following environment variables:
S3_ACCESS_KEY_Id: AWS S3 access key ID.S3_SECRET_KEY: AWS S3 secret key for authentication.Upon successful storage of the webhook data into the S3 bucket, the function returns a success message with a 200 status code, indicating the filename where the data was stored. If there is an error during the process, it logs the error and returns a 500 status code with an error message.