From a77f02189e95ed7db1498917bb7cbe13b8282ff9 Mon Sep 17 00:00:00 2001 From: m5r Date: Sat, 11 Jun 2022 19:35:09 +0200 Subject: [PATCH] receive messages --- app/routes/webhook/message.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/routes/webhook/message.ts b/app/routes/webhook/message.ts index 2764df6..69841e3 100644 --- a/app/routes/webhook/message.ts +++ b/app/routes/webhook/message.ts @@ -15,7 +15,7 @@ export const action: ActionFunction = async ({ request }) => { return badRequest("Invalid header X-Twilio-Signature"); } - const body: Body = await request.json(); + const body: Body = Object.fromEntries(await request.formData()) as any; try { const phoneNumbers = await db.phoneNumber.findMany({ where: { number: body.To }, @@ -53,10 +53,13 @@ export const action: ActionFunction = async ({ request }) => { if (phoneNumbersWithActiveSub.length === 0) { // accept the webhook but don't store incoming message // because the organization is on the free plan - return html(""); + console.log("no active subscription"); // TODO: uncomment the line below -- beware: refresh phone numbers refetch those missed messages lol + // return html(""); } - const phoneNumber = phoneNumbersWithActiveSub.find((phoneNumber) => { + const phoneNumber = phoneNumbers.find((phoneNumber) => { + // TODO: uncomment the line below + // const phoneNumber = phoneNumbersWithActiveSub.find((phoneNumber) => { // if multiple organizations have the same number // find the organization currently using that phone number // maybe we shouldn't let that happen by restricting a phone number to one org?