Mirroring Approvals
Objective
This cookbook describes how to mirror approvals from other business systems into your AI assistant. You can use this cookbook to recreate the experience that your users have with our built-in approval mirroring experience.
This specifically ensures that your users get the full experience of our Approval Queue (i.e. ability to ask “which approvals do I still need to complete”).
Architecture
At a high-level, there are going to be two plugins needed in order to build this experience.
- Polling Plugin. Periodically checks for new records that need approval from the user
- Notification Plugin. Sends the target user a notification, validates the status of the record on response, and pushes the update to the system of record.
Polling Plugin
- Trigger: Scheduled job. Runs on an interval.
- Body: Compound action. Fetches notifications that are eligible for notification.
Notification Plugin
-
Trigger Webhook. Triggered by the polling plugin.
For this cookbook, assume the payload looks something like this:
-
Body: Compound action. Notifies the user and processes their response.
Risks
-
Rate Limits. Approvals tend to be bursty, so we recommend building rate limit checks into your plugin.
- Make sure you secure your webhooks! Unauthenticated webhooks have low rate limits, so they won’t be able to process all of the events you are generating.
- Throttle your polling plugin. You can use a delay config to space your webhook events out.
-
Stale Approvals. After you send your approval request, it can go “stale.” For example, the user might log into the application and approve it there, but the approval request will still be in the assistant. Or another approver might handle the request, making the user’s response irrelevant.
We recommend validating the approval is still “fresh” before taking action. However, there is currently no way to remove it from their “queue” of approvals.
-
Duplicate notifications. To avoid notifying the same user twice about the same approval, you should implement some sort of deduplication logic in your compound action. We recommend that you…
- Use time-based cursors. That way you’ll only fetch the approval once (e.g. by the
created_ondate) - Use worknotes & audit trails. You can leave a comment on the approval object (a purchase requisition, expense report, etc.) to log whether or not you’ve already reached out to the user. Then, in your notification plugin, check for that marker before creating the approval request.
- Use time-based cursors. That way you’ll only fetch the approval once (e.g. by the
-
Approval requests will expire after 30 days. Generally users don’t act on requests that are over 30 days old. So if your approval request expires, we recommend escalating to a different owner rather than just notifying the same user again.