UNPKG

plazbot

Version:

Official Plazbot SDK for creating AI agents for WhatsApp, portals, and developers.

37 lines (36 loc) 1.31 kB
import type { SyncConfig, SyncDefinition } from './types'; /** * Define un sync que trae datos de una API externa y los mapea a contactos de Plazbot. * * Estructura fija: `fetch` obtiene registros → `map` los transforma → Plazbot aplica. * Maneja cursor, match de contactos, crear/update y estadisticas automaticamente. * * Diferencia con defineSchedule: el sync tiene logica built-in para sincronizacion * (cursor, match, create/update, stats). El schedule es generico. * * @example * ```typescript * import { defineSync } from 'plazbot/workers'; * * export default defineSync<{ email: string; plan: string }>({ * name: 'stripe-customers', * reference: 'Sincroniza clientes de Stripe', * source: 'Stripe', * schedule: '0 * * * *', // cada hora * async fetch(plz) { * const res = await plz.fetch('https://api.stripe.com/v1/customers', { * headers: { Authorization: `Bearer ${plz.env.STRIPE_KEY}` }, * }); * return (await res.json()).data; * }, * map(customer) { * return { * match: { email: customer.email }, * variables: { stripe_plan: customer.plan }, * contact: { tags: ['stripe-synced'] }, * }; * }, * }); * ``` */ export declare function defineSync<T = unknown>(config: SyncConfig<T>): SyncDefinition<T>;