Skip to content

Integrations and syncs

Integrations and syncs

An integration connects the workspace to an outside system. Source declares the definition: the kind of system, its settings and the credentials it needs. The connections themselves, one per account, are created in the app. An administrator pairs each one there, and its credentials stay sealed on the host.

The native integrations page with available connections and their setup controls.
The native integrations page manages connections, their configuration and sync health.
// src/integration/google_routes/+integration.ts (scheduling)
import { integration } from '@norbital-ai/bolt';

export default integration('google_routes', {
	description: 'Google Routes for drive times and traffic.',
	driver: 'http',
	credential: { api_key: { kind: 'text' } },
	http: {
		base_url: 'https://routes.googleapis.com/',
		auth: { header: { name: 'X-Goog-Api-Key', value: 'api_key' } }
	}
});

Google Routes, from the scheduling template, is an HTTP API with a base URL and an API key sent as a header.

WhatsApp, email, Telegram, Slack, Discord and WeChat are built in, so you do not declare them. Many more chat platforms connect through the built-in chat integration.

An administrator creates connections in Settings → Integrations → Connections, or from an envoy's card in Settings → Integrations → Envoys, then pairs and tests them there. Disconnect logs the account out and deletes its stored credentials but keeps the connection. Delete connection removes it together with its credentials, sync progress, conversations and messages.

Calling it from an automation

Find the connection, a sys_integration row, and call ctx.request(connection, request). Declare the answer's shape in output so it arrives decoded.

// in an automation (scheduling, shortened); instance_id comes from '@norbital-ai/bolt'
const routes = yield* ctx.query({
	sys_integration: {
		where: { integration: { eq: 'google_routes' }, active: { eq: true }, owner: { is_null: true } },
		fields: ['integration'],
		limit: 1
	}
});
const [account] = routes.sys_integration.rows;
if (account === undefined) return;

const matrix = yield* ctx.request(instance_id('google_routes', account), {
	method: 'POST',
	path: 'distanceMatrix/v2:computeRouteMatrix',
	body: { origins, destinations, travelMode: 'DRIVE' },
	output: {
		kind: 'object',
		many: true,
		fields: { destinationIndex: { kind: 'int', optional: true }, duration: { kind: 'text', optional: true } }
	}
});

What happens when it runs

  1. An administrator adds a Google Routes connection in the app and pastes the API key. The key is sealed on the host.
  2. An automation that matches a helper to a visit calls ctx.request. The host adds the key header and sends the request to Google.
  3. The answer arrives decoded in the declared output shape. If the call fails, the automation keeps its own estimate.

Syncs

A model's syncs, each a +<sync>.sync.ts beside its +model.ts, exchange its rows with a connection or with files. A remote sync's read returns pages of rows and a cursor; its write sends local changes out. Bolt keeps the cursors, retries failed writes in order and holds writes that wait for approval. Only the fields a sync returns are synced; the rest stay local.

// src/data/model/customers/+crm.sync.ts: read customers from a CRM every five minutes, send local edits back
import { sync } from '@norbital-ai/bolt';

export default sync('customers', 'crm', {
	with: 'crm',
	every: '5min',
	read: function* ({ cursor }, ctx) {
		const page = yield* ctx.request({
			method: 'GET',
			path: '/customers',
			query: { updated_since: String(cursor ?? ''), limit: 200 },
			output: { kind: 'json' }
		});
		const data = yield* decode_customer_page(page); // your decoder for the CRM's answer
		return {
			rows: data.items.map((c) => ({ $id: c.id, $version: c.updated_at, name: c.name, email: c.email })),
			cursor: data.next_cursor,
			more: data.has_more
		};
	},
	write: function* ({ op, row, $id }, ctx) {
		const answer = yield* ctx.request({
			method: op === 'create' ? 'POST' : op === 'update' ? 'PATCH' : 'DELETE',
			path: $id ? '/customers/' + $id : '/customers',
			body: { name: row.name, email: row.email },
			output: { kind: 'json' }
		});
		const saved = yield* decode_customer(answer);
		return { $id: saved.id, $version: saved.updated_at };
	}
});

A file sync gives a table Import, Export and Download template buttons. sync('<model>', 'sheet', { with: 'file', parser: ['xlsx', 'csv'] }) in +sheet.sync.ts is enough when the column headers match the model's captions. Add a schema and a read body for other layouts. An import is all or nothing: if any row is refused, nothing is saved.

A sync write that keeps failing becomes a dead letter in the connection's view. Replay sends its saved payload again; Retire skips it and lets later writes for the record go out. Sync now refreshes a remote sync at once for administrators and holders of capabilities.syncs.

Channels

A channel is a connection that carries conversations, such as a WhatsApp number. A delivery from the platform is a hint, not the state: webhooks get dropped and people delete messages. Norbital stores a message before it acknowledges it, then repairs what each platform lets it read back. The connection form shows the level a platform reaches.

LevelWhat Norbital doesWhat comes backPlatforms
Change logReads the platform's change log from a saved position.New messages and deletes, for as long as the platform keeps its log.Gmail, iMessage (Photon), Google Calendar
HistoryCompares each active conversation with the platform when a connection opens and once a day.Missed messages and edits, and deletes where the platform shows the whole window.Slack, Discord, email (IMAP), WhatsApp (Twilio), Google Chat, Lark, Webex, Mattermost, X, XChat, WhatsApp (Kapso), SMS (Twilio), iMessage (Sendblue, Linq, Blooio), Dial, Zernio, GitHub, GitLab, Linear, Liveblocks, Velt, Resend
Delivery onlyStores before it acknowledges, so the platform's own retries work.Only what the platform retries. A message lost beyond that is gone.Telegram, WeChat, WhatsApp (Baileys), Microsoft Teams, WeCom, Messenger, Instagram, WhatsApp Business Cloud, LINE, Zalo, QQ, Weixin, Twitch, Notion, Novu, AgentPhone
  • A repaired message keeps its files' names and sizes, not their content.
  • Conversations quiet for more than 7 days are not compared.
  • A send is repeated only where the platform removes duplicates. Elsewhere an unknown result stays unknown, rather than risk a second message.