('webhook-logs.json', [])
return (
diff --git a/src/lib/whatsapp.ts b/src/lib/whatsapp.ts
index a90e34e..b283e3c 100644
--- a/src/lib/whatsapp.ts
+++ b/src/lib/whatsapp.ts
@@ -1,6 +1,25 @@
import { appendLog, readJsonFile, writeJsonFile } from './storage'
type FlowState = Record
+type WebhookValue = {
+ messages?: IncomingMessage[]
+ statuses?: unknown[]
+}
+type WebhookChange = {
+ value?: WebhookValue
+}
+type WebhookEntry = {
+ changes?: WebhookChange[]
+}
+type WebhookPayload = {
+ entry?: WebhookEntry[]
+}
+type IncomingMessage = {
+ from?: string
+ text?: {
+ body?: string
+ }
+}
function normalizeNumber(number?: string | null) {
return (number || '').replace(/\D+/g, '')
@@ -37,7 +56,7 @@ export async function sendTextMessage(to: string, message: string) {
return payload
}
-export async function handleWebhook(payload: any) {
+export async function handleWebhook(payload: WebhookPayload) {
appendLog({ type: 'webhook_received', payload, created_at: new Date().toISOString() })
for (const entry of payload.entry || []) {
@@ -55,7 +74,7 @@ export async function handleWebhook(payload: any) {
}
}
-async function handleIncomingMessage(message: any) {
+async function handleIncomingMessage(message: IncomingMessage) {
const from = message.from || ''
appendLog({ type: 'incoming_message', from, message, created_at: new Date().toISOString() })
diff --git a/tsconfig.json b/tsconfig.json
index caa4325..5d998c4 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "ES2017",
- "lib": ["dom", "dom.iterable", "esnext"],
+ "lib": [
+ "dom",
+ "dom.iterable",
+ "esnext"
+ ],
"allowJs": false,
"skipLibCheck": true,
"strict": true,
@@ -11,13 +15,27 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
- "jsx": "preserve",
+ "jsx": "react-jsx",
"incremental": true,
- "plugins": [{ "name": "next" }],
+ "plugins": [
+ {
+ "name": "next"
+ }
+ ],
"paths": {
- "@/*": ["./src/*"]
+ "@/*": [
+ "./src/*"
+ ]
}
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
- "exclude": ["node_modules"]
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts",
+ ".next/dev/types/**/*.ts"
+ ],
+ "exclude": [
+ "node_modules"
+ ]
}