// Worked example for AI assistants: a webhook trigger and one action, built only against the public // connector framework (https://aancer.ai/dev/schemas/connector-framework.d.ts.txt). The service is fictional. import { createAction, createConnector, createTrigger, ConnectorAuth, Property, TriggerStrategy } from '@aancer/connector-framework'; const API = 'https://api.acme.example.com/v1'; const HOOK = 'webhook'; type Ticket = { id: string; title: string; status: string; createdAt: string }; async function call(apiKey: string, method: 'GET' | 'POST' | 'DELETE', path: string, body?: unknown): Promise { const res = await fetch(`${API}${path}`, { method, headers: { authorization: `Bearer ${apiKey}`, accept: 'application/json', ...(body === undefined ? {} : { 'content-type': 'application/json' }) }, body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(30_000), }); if (method === 'DELETE' && res.status === 404) return undefined as T; if (!res.ok) throw new Error(`Acme Tickets ${method} ${path}: HTTP ${res.status} ${(await res.text()).slice(0, 300)}`); return (res.status === 204 ? undefined : await res.json()) as T; } // One API key per connection, entered once by an administrator. Read it as auth.secret_text. export const auth = ConnectorAuth.SecretText({ displayName: 'API key', description: 'An Acme Tickets API key.', required: true }); export const ticketCreated = createTrigger({ auth, name: 'ticket_created', displayName: 'Ticket created', description: 'Starts a flow for each new ticket.', type: TriggerStrategy.WEBHOOK, props: {}, sampleData: { id: 't_1', title: 'Printer offline', status: 'open', createdAt: '2026-01-01T00:00:00Z' }, async onEnable({ auth, webhookUrl, store }) { const hook = await call<{ id: string }>(auth.secret_text, 'POST', '/webhooks', { url: webhookUrl, events: ['ticket.created'] }); await store.put(HOOK, hook.id); }, async onDisable({ auth, store }) { const id = await store.get(HOOK); if (id) await call(auth.secret_text, 'DELETE', `/webhooks/${encodeURIComponent(id)}`); await store.delete(HOOK); }, async run({ payload }) { const ticket = payload.body as Ticket; return ticket?.id ? [ticket] : []; }, }); export const addComment = createAction({ auth, name: 'add_comment', displayName: 'Add comment', description: 'Adds a comment to a ticket.', props: { ticketId: Property.ShortText({ displayName: 'Ticket id', required: true }), comment: Property.LongText({ displayName: 'Comment', required: true }), }, async run({ auth, propsValue }) { return call(auth.secret_text, 'POST', `/tickets/${encodeURIComponent(propsValue.ticketId)}/comments`, { body: propsValue.comment }); }, }); // createConnector takes no name: the connector's name comes from package.json (@aancer/connector-acme-tickets). export const acmeTickets = createConnector({ displayName: 'Acme Tickets', description: 'Starts a flow when a ticket is created and adds comments to tickets.', logoUrl: 'https://api.acme.example.com/logo.svg', minimumSupportedRelease: '0.0.0', authors: ['acme'], auth, actions: [addComment], triggers: [ticketCreated], });