Free setup on annual plans

Sign up today!

API Reference: Hooks endpoints

A hook is a fixed event in AnswerPal’s processing, such as an incoming e-mail before the spam check, an escalation or the end of a phone call. You link actions to a hook to run them at that event, and documents to add their content to the prompt. Each link applies to one channel, a channel type or all channels.

Endpoints

Hook actions

  • GET /api/HookActions
    Access: Bearer JWT
    List the action links of a hook, paged. Query: hookName or actionId (at least one is required), pageNumber (at least 1), pageSize (1 to 100, default 10), sortBy (actionName by default, or hookName, channelName, priority) and sortOrder. Only links of active actions are returned.
  • POST /api/HookActions
    Access: Bearer JWT
    Link an action to a hook. Answers 201 Created with the link.
  • POST /api/HookActions/bulk
    Access: Bearer JWT
    Create several links in one call. Body: an array of links. Combinations that already exist are skipped; the answer (200 OK) lists only the links that were created.
  • GET /api/HookActions/wait-seconds
    Access: Bearer JWT
    The total wait time of a hook on one channel. Query: channelId and hookName. Answers { "totalWaitSeconds": 30 }: the sum of waitSeconds of the active Wait actions linked to that hook for the channel, its channel type or All, each action counted once. An unknown channel gives 0.
  • GET /api/HookActions/{id}
    Access: Bearer JWT
    Return one hook link. A link to a topic is not a hook link and gives 404.
  • PUT /api/HookActions/{id}
    Access: Bearer JWT
    Change the priority of a hook link; nothing else changes. Answers 204 No Content.
  • DELETE /api/HookActions/{id}
    Access: Bearer JWT
    Delete a hook link. The action itself stays. Answers 204 No Content.

Hook documents

  • POST /api/HookDocuments
    Access: Bearer JWT
    Link a document to a hook. Answers 201 Created with the link.
  • GET /api/HookDocuments/promptDocuments
    Access: Bearer JWT (all roles except Analyst, or phone token)
    The documents linked to a hook, as they go into a prompt. Query: hookName (required) and channelId (optional: links for that channel, its channel type and All). Returns an array, see below.

Hook document links are listed and deleted with the topic document endpoints on the Documents page: GET /api/TopicDocuments?hookName=OnPhonePickupSay and DELETE /api/TopicDocuments/{id}. To run the actions of a hook on one message, or to read the prompt documents of a message, use the execute-hook and prompt document routes on the Ticket Messages page. Actions themselves are defined on the Actions page.

Hook names

Started by AnswerPal

  • PreSpam
    An incoming e-mail, before the spam check. A Delete action here skips the e-mail.
  • PostSpam
    After the spam check of a message.
  • PostTopicDetection
    After topic detection. Its actions run together with the actions linked to the detected topics, in one priority order.
  • OnEscalate
    A message is escalated (once per message).
  • OnEscalateFailed
    After OnEscalate, when the ticket still has no representative.
  • OnPhoneCallEnded
    A recorded phone call is transcribed; the actions read the transcript as the message. Reply, Send, ReplySend, Forward, Wait, Delete and the cleanup types are skipped here.
  • OnTranscribe
    Documents only: their content is passed as a word list before a full audio recording is transcribed (a phone recording, an audio attachment or an upload). Action links are refused with HookDoesNotSupportActions.
  • OnAppointmentBooked
    A new appointment on a ticket is confirmed.
  • OnAppointmentRequested
    An appointment request on a ticket waits for a representative.

Started by a client

  • OnClose, OnEndUserAdd, OnEndUserUpdate, OnEndUserDelete, PostEscalate
    The API does not start these itself; their actions run when a client starts the hook for a message with execute-hook.
  • OnPhonePickup, OnPhonePickupSay
    The start of a phone call. The phone client reads their documents (OnPhonePickupSay for the greeting) and can start their actions with execute-hook.
  • UserTriggered
    The stage of actions a user runs by hand on a message.

The appointment hooks only take ApiCall, AICall and SendNotification actions; another type gives 400 with code HookDoesNotSupportActionType. They cannot be started by hand. The stored hook name is limited to 20 characters, so at this revision a link to OnAppointmentRequested (22 characters) cannot be saved and fails with 500.

Fields

Hook action link

  • hookName (string)
    One of the hook names above. When you leave it out, the link is made for PreSpam.
  • actionID (integer)
    The action to run.
  • channelID (integer or null)
    One channel.
  • specialChannel (string or null)
    A channel type instead: Email, Chat, Phone, WhatsApp, SMS, Teams or All.
  • priority (integer)
    Lower numbers run first.
  • In the response also hookActionID, actionName and channelName (the channel name, or the channel type).

A link applies to a message when its channel is the message’s channel, its channel type is the type of that channel, or it is All. An action linked twice to the same hook runs once, with its lowest priority. The update changes only priority; to move a link to another hook or channel, delete it and create a new one.

Hook document link

  • specialTopic (string, max 20)
    The hook name. It is not checked against the list: a misspelt name is stored but never used.
  • topicID (integer or null)
    Leave empty for a hook link. OnTranscribe refuses a topic.
  • documentID (integer)
  • channelID, specialChannel
    As for action links. Hook documents without channel or channel type also count for every channel when AnswerPal builds a prompt.
  • In the response also topicDocumentID, customerID, topicName, documentName and channelName.

An exact copy of an existing link gives 409 Conflict. For OnTranscribe the document must be a plain text document of the customer (not a data retrieval or function tool document) and a given channel must belong to the customer; otherwise 400 with code InvalidTranscriptionLexiconDocument.

Prompt document

  • documentID (integer), name (string)
  • content (string)
    The stored content, with {{now}}, {{today}}, {{next_week}}, relative values such as {{now_plus_2_days}} and {{TopicList}} filled in. Data retrieval documents are not run here.
  • includeInRealtimeInstructions, openAIVectorSearchEnabled (boolean), openAIVectorStoreId (string or null)
  • images (array)
    Image details of the documents (documentImageID, fileName, contentType, caption, sortOrder, size), up to the customer’s maximum per prompt.
  • contentType (null) and imageUrls (empty array) are always empty here.

Each document appears once. When no document matches, the array holds one entry with documentID 0, name No documents found and empty content. With the phone token the channel of the token is used; another channelId gives 403.

POST /api/HookActions
Authorization: Bearer <token>
Content-Type: application/json

{
  "hookName": "PostSpam",
  "actionID": 58,
  "specialChannel": "Email",
  "priority": 20
}

201 Created
Location: /api/HookActions/905

{
  "hookName": "PostSpam",
  "actionID": 58,
  "channelID": null,
  "specialChannel": "Email",
  "priority": 20,
  "hookActionID": 905,
  "actionName": "Look up order status",
  "channelName": "Email"
}
GET /api/HookActions?hookName=OnEscalate&sortBy=priority&pageSize=50
Authorization: Bearer <token>

200 OK
{
  "items": [
    {
      "hookName": "OnEscalate",
      "actionID": 61,
      "channelID": null,
      "specialChannel": "All",
      "priority": 1,
      "hookActionID": 911,
      "actionName": "Notify team lead",
      "channelName": "All"
    }
  ],
  "totalCount": 1,
  "totalPages": 1
}
POST /api/HookDocuments
Authorization: Bearer <token>
Content-Type: application/json

{
  "topicID": null,
  "specialTopic": "OnPhonePickupSay",
  "documentID": 140,
  "channelID": 7,
  "specialChannel": null
}

201 Created
{
  "topicID": null,
  "specialTopic": "OnPhonePickupSay",
  "documentID": 140,
  "channelID": 7,
  "specialChannel": null,
  "topicDocumentID": 377,
  "customerID": 12,
  "topicName": null,
  "documentName": "Phone greeting",
  "channelName": "Main line"
}
GET /api/HookDocuments/promptDocuments?hookName=OnPhonePickupSay&channelId=7
Authorization: Bearer <token>

200 OK
[
  {
    "documentID": 140,
    "name": "Phone greeting",
    "content": "Welcome to Example Services. How can I help you?",
    "contentType": null,
    "includeInRealtimeInstructions": true,
    "openAIVectorSearchEnabled": false,
    "openAIVectorStoreId": null,
    "imageUrls": [],
    "images": []
  }
]

Access and status codes

The hook action endpoints and POST /api/HookDocuments work for every signed-in user of the customer. GET /api/HookDocuments/promptDocuments is also open to the phone token. The access line of each endpoint above is the reference.

  • 200 OK, 201 Created, 204 No Content
    Success.
  • 400 Bad Request
    A list without hookName and actionId; an unknown hook name; { "code": "HookDoesNotSupportActions" }, { "code": "HookDoesNotSupportActionType" } or { "code": "InvalidTranscriptionLexiconDocument" }, each with a message; an unknown sort field.
  • 401 Unauthorized, 403 Forbidden
    No valid token, or a phone token used for another channel.
  • 404 Not Found
    No hook link with that ID for this customer.
  • 409 Conflict
    The hook document link already exists, or the database refuses a priority update.
  • 500 Internal Server Error
    An action link that already exists, a link to an action, document or channel that does not exist, a specialChannel outside the list, or a hook name longer than 20 characters. These are not validated up front.

FAQ

A topic link runs its action when the topic is detected on a message. A hook link runs its action at a fixed event, whatever the topic. Both have a channel scope and a priority.

The list only shows links of active actions. Activate the action on the Actions page to see its links again.

Find the link with GET /api/TopicDocuments?hookName=... and delete it with DELETE /api/TopicDocuments/{id}. The document itself stays.

Yes, on one message with the execute-hook route of the Ticket Messages page, except for OnTranscribe and the appointment hooks.

Need more help?

Table of Contents

AnswerPal: AI-powered customer service solutions to elevate your support and communication effortlessly.

Contact

For all support, sales, and partnership inquiries, email us at info@answerpal.eu

AnswerPal
Bisschoppenhoflaan 380
2100 Antwerp
Belgium

+32.36416685

BE 0862.692.858