- A button inside Attio that will call a server function
- A server function to actually send the data to ALC
- A webhook to receive the lead status back from ALC sometime in the future
App UI components cannot directly communicate with the outside world. They can only call custom
app server functions, which can communicate with the outside world via
fetch(), and communicate with Attio’s REST API via
ATTIO_API_TOKEN.Sequence
The general sequence of how the app will work is:Installation
- User clicks to install the app.
- User is prompted to add a connection to Acme Lead Checker
- User logs into Acme Lead Checker to complete the OAuth flow.
- User is redirected back to Attio. The app is now installed.
- The
connection-addedevent handler the app registered is fired. - Event Handler calls
createWebhookHandler()to register a webhook handler. - Event Handler registers the new webhook with Acme Lead Checker.
Usage
- App provides a record action which will manifest itself in Attio’s UI as - a button on the People record page - in the CMD+K quick action palette.
- User views the record page
- User clicks button
- Attio’s UI fires the
onTrigger()function provided by the record action - Record Action notifies the user that async things are happening
with
showToast(). - Record Action loads the phone number of the person whose record page we are on
asynchronously via GraphQL using
runQuery(). - If no phone numbers are found, the user is notified via analert(). Otherwise… - Record Action calls a
server function called
sendToALC(). - Server function uses
fetch()to send aPOSTrequest toapi.acmeleadchecker.ai. - Server function calls the Attio REST API with
ATTIO_API_TOKENto mark the record as “Pending”. - Server function returns success.
- Record Action hides first toast
with
hideToast(). - Record Action notifies the user that the process was successful
with
showToast().
- Acme Lead Checker’s server calls a webhook provided by the app.
- Webhook Handler calls the Attio REST API with
ATTIO_API_TOKENto mark the record as “Complete”.
Implementation
App structure
An app is organized by folder convention undersrc/app/: the CLI discovers every entry point from the file layout (see App structure). Our finished app will look like this:
Record action
Our record action lives in its own folder undersrc/app/extensions/, as the default export of that folder’s extension.tsx:
src/app/extensions/send-to-alc/extension.tsx
GraphQL query
Now let’s write that GraphQL query we’re importing:src/app/extensions/send-to-alc/get-person-phone-numbers.graphql
Server function
Server function file names MUST:- have a
.server.tssuffix - contain an
export default async function
send-to-alc.server.ts
Webhook handler
Our webhook handler is going to be called by Acme Lead Checker when they have processed our lead that we sent them. Webhook handler files MUST:- Live under the
src/app/webhooksdirectory - Have a
.webhook.tssuffix. - Contain an
export default async functionthat:
src/app/webhooks/lead-processed.webhook.ts
Connection event handlers
In order to let Acme Lead Checker know how to call our app’s webhook, we need to tell them as soon as our user creates an authorized connection; we accomplish this with event handlers. Connection Event Handler files MUST:- Live in
src/app/events - Have a
.event.tssuffix. - Contain an
export default async functionthat:- Takes a
{ connection: Connection }argument - Returns
void
- Takes a
Connection added event handler
When a connection is added, we need to:- Create a webhook
- Register our webhook with Acme Lead Checker
- Update our webhook with the unique identifier of our webhook on ALC’s side
src/app/events/connection-added.event.ts
Connection removed event handler
When a connection is removed, we need to:- Load all our app’s webhook handlers (there should only be one)
- For each handler, tell ALC to stop calling it
- Delete the webhook from Attio
src/app/events/connection-removed.event.ts
Workflow blocks
The example above shows how apps surface UI and call external APIs. Apps can also extend Attio Workflows with custom triggers and steps.- A trigger block starts a workflow run when an external event arrives, for example a webhook from a third-party service.
- A step block runs as part of an in-progress workflow run, for example calling an external API, transforming data, or waiting on an async callback.
fetch(), ATTIO_API_TOKEN, and connections.
See the Workflow blocks overview and the reference pages for full details.