Skip to content
DocsRequests and notifications

Theme

Requests and notifications

A Request waits for an answer and a Notification does not: two endpoints, and what each one accepts.

Your agent has two kinds of things to say to a person: what it needs an answer to, and what it only wants them to know. Kiwi Studio's invoice has both. Before filing it, invoice-flow asks; once it is filed, it says so. Nibify gives each its own endpoint.

Two endpoints

Both create a Message: a sender, a notification block, the title and the line the lock screen shows, and optionally a Surface. Which endpoint you call decides what the Message is. Nothing in the body does.

  • POST /v1/requests creates a Request. It is born pending and waits for the person's answer. In the SDK it is ask().
  • POST /v1/notifications creates a Notification. It asks for nothing. In the SDK it is notify().

A Request

The Quickstart sent one: the invoice, with File it and Fix it on the notification. The person answers, and the answer is the Request's Response: which action they chose, from which component, with what context.

A Request gets one Response and is never reopened. If the person changes their mind, your agent asks again, with a new Request.

Only a Request has a lifecycle: it is pending until it reaches one of four terminal states. Only a Request can expire, be withdrawn by your agent or be sent again as a reminder. Lifecycle and expiry tells the whole story.

A Notification

Once the person files the invoice, invoice-flow tells them it is done:

import { Card, Column, Nibify, Text } from '@nibify/sdk';

const nibify = new Nibify({ apiKey: 'sk_test_…' });

const surface = {
  root: 'root',
  dataModel: {},
  components: [
    Card('root', { child: 'body' }),
    Column('body', { children: ['title', 'text'] }),
    Text('title', { text: 'Kiwi Studio invoice filed', variant: 'h4' }),
    Text('text', { text: '$1,420, consulting, due Oct 30.' }),
  ],
};

await nibify.notify({
  sender: { name: 'invoice-flow' },
  notification: {
    title: 'Kiwi Studio invoice filed',
    body: '$1,420, consulting, due Oct 30.',
  },
  surface,
});

It lands in the Inbox and rings the phone like a Request does, and nothing comes back. A Notification has no pending, no expiry and no Response. What there is to know about it is that it was delivered and that it was read, and those reach your agent as the message.delivered and message.read webhook events.

The 201 returns a messageId rather than a requestId, and GET /v1/requests/{id} does not know it.

A Notification may carry a Surface, to show more than a title and a line. The Surface may only show things: a button that sends an action is a question, so a Surface with one is refused with 422 surface_invalid, and the error points at POST /v1/requests.

What each one accepts

The two bodies share sender, notification, surface, priority and threadKey. Four things belong to a Request alone:

  • notification.quickActions, the buttons on the notification.
  • expiresAt, the moment the Request stops waiting.
  • callbackUrl, an address called once, when the Request ends.
  • The Idempotency-Key header, which makes a retry safe.

POST /v1/notifications refuses the three fields by name, with 422 invalid_request_body, instead of ignoring them: a Notification that quietly dropped a callbackUrl would leave your agent waiting for a call that never comes.

It does not read an Idempotency-Key. The same Notification sent twice arrives twice, which is why the SDK's notify() never retries on its own.

Every field of both bodies is in the reference: the Requests API and the Notifications API.