Provide dynamic information to the copilot using a prehook
Overview
Sometimes you may want to provide information from external systems to the Inkeep support copilot. This can include:
- Payment information from your billing system
- Account information from your CRM
- Activity or product-specific data from your database
- Uptime information from your application monitoring software
To accomplish this, you can use a prehook
for the copilot. When a prehook
is enabled, the following happens:
- When a support agent clicks on
Smart Assist
, Inkeep will make a request to an API route of your choosing. - Your API route fetches information from any arbitrary backend service[s].
- Your API route returns that information and any custom instructions in the API route's response.
- That information is added as custom context for the AI copilot to consider.
- That context is persisted across the entire conversation with the copilot.
Think of the prehook
as a way to inject dynamic, custom data or instructions into the Copilot's decision-making process.
1. Deploy your API route
You'll need to deploy an API endpoint that the Copilot can call.
Option 1: Deploy with Vercel (Recommended)
A quick way to deploy is to use the below Vercel template:
- Click the "Deploy with Vercel" button above
- Connect your GitHub account when prompted
- Generate a random API key using this command:
- Enter this API key as the
INKEEP_SUPPORT_COPILOT_API_KEY
environment variable - Click Deploy
Option 2: Deploy anywhere
As long as your API route follows the API contract, you can deploy and develop the API route in any cloud provider or API framework. A reference TypeScript template repository is provided here.
2. Write your custom logic
Below are the schemas that are used by the prehook. If you're using the reference template, you can customize your business logic in this file.
Request
The request to your API endpoint will include information the Copilot has in relation to the current ticket. You can use this information, like a user email or ID, to fetch information from downstream services.
Request examples
Request parameters
Parameter | Type | Description |
---|---|---|
ticketId | string | Unique identifier for the ticket for your support platform. |
ticketingPlatformType | string | The support platform type ("zendesk", "github", "plain", or "other"). |
ticketAttributes | object | Information about the ticket provided by the support platform. |
userAttributes | object | Information about the user provided by the support platform. |
organizationAttributes | object | Information about the organization the user is a member of as provided by the support platform (for business-to-business type scenarios). |
messages | MessageObject[] | List of message objects containing conversation history. |
The exact ticket, user and organization attributes provided are dependent on the support ticketing platform. If you'd like to fetch more information from the support platform, you can use the ticketId
to query relevant information.
MessageObject
Parameter | Type | Description |
---|---|---|
id | string | Unique identifier for the message. |
createdAt | date (optional) | Timestamp when the message was created. |
content | string | The message text content. |
authorId | string | Unique identifier for the message author. |
authorType | string | Type of author ("user" or "member"). |
authorName | string (optional) | Name of the message author. |
files | array | List of attached files, each containing id and url . |
isInternalComment | boolean (optional) | Whether the message is an internal note. |
Response
The response from your API endpoint should include any additional context you want to provide to the Copilot. You can also include specific instructions to guide how the Copilot should respond. All of the below are Optional.
Here's an example response:
Response format
Parameter | Type | Description |
---|---|---|
userAttributes | AttributeObject[] | Optional. List of attribute objects providing context about the user. |
organizationAttributes | AttributeObject[] | Optional. List of attribute objects providing context about the organization. |
ticketAttributes | AttributeObject[] | Optional. List of attribute objects providing context about the ticket. |
prompt | string | Optional. Additional instructions to guide the Copilot's response. |
The prompt
field is best used for high-level instructions or context that doesn't fit naturally into the attributes. For example, prompt can include:
- Real-time information on a wide-application situation: "There is currently an outage affecting our dashboard. If the user references an outage, link them to the tracker page here."
- Tone/style guidance: "This is a VIP customer, use an expedited tone..."
- Complex business rules: "If the user mentions feature X, first verify their subscription tier..."
Think of this as dynamic instructions or context for the bot beyond what can be described with attributes.
AttributeObject
Field | Type | Description |
---|---|---|
label | string | Semantic, short identifier for the attribute (e.g., 'subscription_plan'). |
value | string | The attribute's value (e.g., 'premium'). |
description | string | Optional explanation of the attribute's meaning or implications of the value. |
useWhen | string | Optional condition for when the copilot should consider or use this attribute. |
audience | "user" | "member" | "any" | Optional field to specify which type of participant can see this attribute. Defaults to any . |
useWhen
and description
should contain the core details of when this attribute may or may not be relevant and how it should be used.
For more complex scenarios, use xml
or markdown
format to specify behavior. Check out our prompting guide for ideas.
3. Configure the prehook in the Inkeep Dashboard
Once your endpoint is deployed, configure it from the Inkeep Dashboard. Creating a separate copilot integration is recommended if you want to test the prehook without affecting your main copilot. More on this in the Testing section below.
- Create a new Support Copilot integration in the Inkeep Dashboard. Follow the steps here and give it a name like "Support Copilot with Prehook".
- Expand Advanced Settings.
- Under Prehook URL, enter the full URL of your API endpoint. Example:
https://your-app-deployment-url.vercel.app/api
. - Under Headers (JSON), enter the headers you want to include in the prehook request. See below.
- Click Save.
Once this is saved, this new Copilot will use your prehook to get additional context and instructions when it runs.
Custom headers
In the Headers (JSON) field, you can configure custom headers to be included in the prehook request. While Content-Type: application/json
is always included, you can use this to add additional headers, like for authentication. The value should be a valid JSON object with double quotes.
Example: To secure the API request, you can configure the headers to include an API key. For example:
The template implementation includes a validation for this, so your-api-key
should match the value of the INKEEP_SUPPORT_COPILOT_API_KEY
environment variable.
If using your own implementation, ensure you implement your own validation of relevant headers.
4. Testing your prehook
Once you've configured your prehook in the Inkeep Dashboard, you can test it by updating your setup in your support platform and clicking on Smart Assist
.
Developing locally with ngrok
To test your prehook locally before deploying to production, you can use ngrok to create a public URL for your local development server:
-
Start your local development server:
-
Install and set up ngrok:
- Install from ngrok.com/download and follow the setup instructions
-
Create a secure tunnel to your local server:
-
In the ngrok output, copy the HTTPS URL (e.g.,
https://1234-your-tunnel.ngrok.app/api
) -
Use this URL as your prehook URL in the Inkeep Dashboard
Important: The ngrok URL is temporary and changes each time you restart ngrok.
Testing in your support platform
- Install another Zendesk app to be used for testing following the steps here, making sure to use the API key from the new "Support Copilot with Prehook" integration from the previous step.
- Open your test Zendesk app and click on
Smart Assist
. The Copilot should now use your prehook. - Once you're done testing, you can update your API key in your original Zendesk App configuration with the API key from the new "Support Copilot with Prehook" integration.
- Disable or delete your test Zendesk app.