Prepare server deployment

This commit is contained in:
2026-05-12 16:21:00 +07:00
parent ac2cfca335
commit 713bfbcbb9
9 changed files with 120 additions and 16 deletions

View File

@ -8,7 +8,7 @@ export default async function TestPage({ searchParams }: { searchParams: Promise
redirect('/login')
}
const logs = readJsonFile<any[]>('webhook-logs.json', [])
const logs = readJsonFile<unknown[]>('webhook-logs.json', [])
const state = readJsonFile<Record<string, unknown>>('flow-state.json', {})
const params = await searchParams

View File

@ -8,7 +8,7 @@ export default async function WebhookLogsPage() {
redirect('/login')
}
const logs = readJsonFile<any[]>('webhook-logs.json', [])
const logs = readJsonFile<unknown[]>('webhook-logs.json', [])
return (
<div className="wrap">

View File

@ -1,6 +1,25 @@
import { appendLog, readJsonFile, writeJsonFile } from './storage'
type FlowState = Record<string, { step: string; name?: string }>
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() })