Skip to main content

Interception

Interceptors allow you to plug custom logic into a channel connection at the ADK level, process, and transform messages flowing through channels in real-time. Interceptors act as programmable filters in the message pipeline, enabling custom business logic, validation, transformation, and integration with external systems.

note

We suggest you understanding the core concepts of Interceptor before diving into this section. To learn more about interceptors, click here

How to intercept

Interceptors can be integrated in the message pipeline at any required place using the orchestrator. While creating channel if the Enable Orchestrator option is checked, then the flow of the message through pipeline is decided by orchestrator which creates a flow chart of operations as nodes.

warning

A channel can only be intercepted if orchestrator is enabled while creation. It cannot be changed later.

You can learn more about Message orchestration and configuring orchestrator from the Agent Builder Documentation

There are two types of interceptors based on the execution model:

  1. Synchronous interceptor: Pipeline waits for interceptor completion
  2. Asynchrounous interceptor: Pipeline waits for interceptor completion
// Synchronous interceptor
subscription.intercept(interceptorName, (payload, resolve, reject) => {
if (payload) { // Replace with your logic
resolve({ status: "success", data: payload });
} else {
reject("Failed");
}
});

// Asynchrounous interceptor
subscription.intercept(interceptorName, async (payload, resolve, reject) => {
try {
const result = await externalApiCall(payload); // Replace with your logic
resolve(result);
} catch (error) {
reject(error.message);
}
});
  • First parameter is the interceptor name that you want to attach to the channel.
  • Second parameter is the callback function that will be invoked when a message passes through the interceptor.
important

Encrypted channel type cannot be intercepted ART promises complete preservation of user's privacy