-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
521027f
commit 36e00fb
Showing
25 changed files
with
484 additions
and
389 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,39 @@ | ||
import ky, { KyResponse } from "ky"; | ||
import { ApiError } from "../types/api-errors.js"; | ||
import { handleError } from "../utils/logger.js"; | ||
import { Response } from "express"; | ||
|
||
export const api = ky.create({ | ||
prefixUrl: process.env.PLOOMES_API_URL, | ||
hooks: { | ||
beforeRequest: [ | ||
(request) => { | ||
const userKey = process.env.PLOOMES_API_USER_KEY | ||
request.headers.set("User-Key", `${userKey}`) | ||
} | ||
], | ||
beforeError: [ | ||
async error => { | ||
const { response } = error; | ||
|
||
if (!response.ok) { | ||
const apiError: ApiError = await response.json() | ||
const expressLikeResponse = adaptKyResponse(response) | ||
const errorMessage = handleError(expressLikeResponse, apiError.message || '', apiError.message || '') | ||
error.name = apiError.message || "Unkown error"; | ||
error.message = `${errorMessage}`; | ||
} | ||
return error; | ||
} | ||
] | ||
} | ||
}) | ||
|
||
function adaptKyResponse(kyRes: KyResponse<unknown>): Partial<Response> { | ||
return { | ||
status: function (code: number) { | ||
return { ...this, statusCode: code } as Response | ||
}, | ||
statusCode: kyRes.status, | ||
} | ||
} |
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,18 @@ | ||
import { LeadFromPloomesAPIProps } from "../types/ploomes.js"; | ||
import { api } from "./client.js"; | ||
|
||
export const getCompleteDeal = async (dealId: number) => { | ||
const filterDealId = `Id+eq+${dealId}`; | ||
const expandFields = "Contact,OtherProperties,Person($expand=Phones)"; | ||
|
||
try { | ||
const result = await api | ||
.get(`Deals?$filter=${filterDealId}&$expand=${expandFields}`) | ||
.json<LeadFromPloomesAPIProps>() | ||
|
||
return { success: true, data: result, error: null } | ||
|
||
} catch (error) { | ||
return { success: false, data: null, error }; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
export const NOTIFICATION_NUMBERS = [ | ||
'+5514981668995', | ||
'+5514997300621' | ||
] | ||
'+5514981668995', //Giovani | ||
// '+5514997300621', //Lívia | ||
// '+5511947577254', //Marcela | ||
// '+5511959310506', //Xaiane | ||
// '+5511984444383', //Wendell | ||
// '+14075206493', //Tiago | ||
]; |
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
import { Request, Response } from "express"; | ||
import { handleError, logWebhook } from "../../utils/logger.js" | ||
import elementorWebhookService from "../../services/elementor-webhook-service.js"; | ||
import leadService from "../../services/lead-service.js"; | ||
import whatsappService from "../../services/whatsapp-service.js"; | ||
import notificationService from "../../services/notificationService.js"; | ||
|
||
const processElementorWebhook = async (req: Request, res: Response) => { | ||
logWebhook(`📩 [Elementor] Recebendo webhook: ${JSON.stringify(req.body)}`) | ||
|
||
try { | ||
const { form_id } = req.query | ||
if (!form_id) return handleError(res, "Form id not provided", "❌ Form id não informado.") | ||
|
||
const result = await elementorWebhookService.processLead(form_id.toString(), req.body) | ||
if (!result.success || !result.lead) return handleError(res, "Error processing lead", `❌ ${result.error}`) | ||
|
||
const lead = await leadService.createLead(result.lead) | ||
if (!lead.success || !lead.data) { | ||
handleError(res, "Erro ao criar lead", `❌ ${lead.error}`) | ||
return | ||
} | ||
|
||
const notificationMessage = notificationService.formatLeadMessage(result.lead, form_id.toString(), lead.data.id) | ||
|
||
const { success, error } = await whatsappService.sendMessages(notificationMessage) | ||
if (!success) { | ||
handleError(res, "Erro ao enviar mesagens", `❌ ${error}`) | ||
} | ||
|
||
res.status(200).json({ message: "Lead do Elementor processado e cadastrado com sucesso." }) | ||
} catch (error) { | ||
handleError(res, "Internal Server Error", `❌ Erro inesperado (Elementor): ${error}`); | ||
} | ||
} | ||
|
||
export default { processElementorWebhook } |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
import { Request, Response } from "express"; | ||
import { handleError, logWebhook } from "../../utils/logger.js"; | ||
import ploomesWebhookService from "../../services/ploomes-webhook-service.js"; | ||
import leadService from "../../services/lead-service.js"; | ||
import notificationService from "../../services/notificationService.js"; | ||
import whatsappService from "../../services/whatsapp-service.js"; | ||
|
||
const processPloomesWebhook = async (req: Request, res: Response) => { | ||
logWebhook(`📩 [Ploomes] Recebendo webhook: ${JSON.stringify(req.body)}`) | ||
|
||
try { | ||
const result = await ploomesWebhookService.processDeal(req.body) | ||
if (!result.success || !result.lead) return handleError(res, "Error processing deal", `❌ ${result.error}`) | ||
|
||
const lead = await leadService.createLead(result.lead) | ||
if (!lead.success || !lead.data) { | ||
handleError(res, "Erro ao criar lead", `❌ ${lead.error}`) | ||
return | ||
} | ||
|
||
const notificationMessage = notificationService.formatLeadMessage(result.lead, "form_ploomes", lead.data.id) | ||
|
||
const { success, error } = await whatsappService.sendMessages(notificationMessage) | ||
if (!success) { | ||
handleError(res, "Erro ao enviar mesagens", `❌ ${error}`) | ||
} | ||
|
||
res.status(200).json({ message: "Lead da Plooms processado e cadastrado com sucesso." }) | ||
} catch (error) { | ||
handleError(res, "Internal Server Error", `❌ Erro inesperado (Ploomes): ${error}`); | ||
} | ||
} | ||
|
||
export default { processPloomesWebhook } |
This file was deleted.
Oops, something went wrong.
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.