Cognigy Sessions: Endpoint Transformers – Cognigy.AI Help Center
Cognigy Sessions: Endpoint Transformers
Cognigy Support
January 8, 2025
In this episode of Cognigy Sessions we will dive into Endpoint Transformers, a powerful feature to enable customization of any Cognigy.AI Endpoint. You will get to know typical Endpoint Transformer applications, how to use them as a part of your Conversational AI stack, and how to deploy Transformers from our GitHub repository to your projects. Furthermore, we’ll demonstrate how to build your own Endpoint Transformers for individual use cases.
YouTube Video
Cognigy Sessions: Endpoint Transformers
Welcome to Cognigy Sessions, our Techinar series from Conversational AI experts for experts. Every episode will give you deep insights into a new Cognigy.AI topic. Today's episode is about Endpoint Transformers. If you're new to Cognigy.AI, there's a good chance you've never come across that feature. But for many advanced users, Endpoint Transformers are mission-critical capability that makes Cognigy.AI stand out as an enterprise-grade platform.
Overview of Endpoint Transformers
Hi, everyone, this is Chris from Cognigy, and in this Techinar, I'm going to show you how to use Endpoint Transformers. Now, what exactly are they? Endpoint Transformers represent a powerful developer tool that enables you to customize any of our existing Cognigy Endpoints. It does so by hooking into the user inputs and the Cognigy output. Transformers use Typescript with extra functions. These are custom HTTP Requests and the Session Storage. More on these later on. The Endpoint Transformers also have an execution timeout of five seconds, which is customizable on all dedicated environments.
Default Behavior
Now, if we take a look at our default Endpoint behavior, you can see that the user input goes straight from the channel the user is currently using to the platform and the platform output goes straight back to the user channel.
Once we bring the Endpoint Transformers into play, you can see that the user input first goes through the Input Transformer and only then into the platform and the platform output first goes through the Output Transformer and only afterwards to the user channel.
Use Cases
What exactly is this good for? Plenty of use cases actually. The most common one is that you want to use Cognigy with a channel that Cognigy does not provide the Endpoints by default. This might, for example, be a new messenger app. And expanding upon that idea, basically, any custom integrations that you want to do. Speaking from experience, modifying an Endpoint is much faster than adapting the internal API, going through all the change requests and all of that. Also, you don't usually have influence over external systems. The Endpoint Transformer allows you to handle events from third-party systems that are not in your control.
Another very common use case is the auto-translation. Feel free to check out our multi-language Techinar for more information on that.
Custom Integrations
When we talk about custom integrations, you usually want to have your Input Transformer or your Output Transformer or both, talk to third-party APIs, or your internal logging API. For this, you usually need some way to send an HTTP Request, which our HTTP Request function gives you the capability to.
Using HTTP Requests
The HTTP Request in the Endpoint Transformers is a function with the same configuration object that has the exact same format as the Options object from the Request API module. There are some limitations by default on that functions as well. The first one is that you can only use it once per Transform execution, and the second one is that you are not allowed to send an HTTP Request to other Endpoints. Both of these restrictions are in place to prevent self-DDoS'ing on a SaaS environment and are, of course, customizable on dedicated environments.
Session Storage
The second function that we added is the Session Storage, which as the name implies, is a storage object that is available in all Transformer functions. The getSessionStorage function uses the user ID and the session ID as parameters. It returns a promise which results with this Session Storage object. This has the implication that you should not mutate within the Session Storage directly. Instead, you should mutate locally and then reassign to the Session Storage.
Example Code
const temporaryArray = [];
temporaryArray.push('element1');
// Modify the array locally
setSessionStorage(temporaryArray);
Hands-On Demonstration
As you can see, we are now in the Cognigy user interface. In the "Chris Techinar Agent" I previously created for this video. Now, before we head to the Endpoint section, let's first create a Flow that will help us understand the Transformers.
If now, I say "Hi," and "Hi again," the second time it repeats back the user input.
Now, if we head over to the Endpoints section and have our little Webchat here, let's actually open it and see that the current status is pretty much the same as the Interaction Panel.
Now, if we head into the Endpoint settings, you can find a Transformer Functions area here. If we expand that, you can find the Transformer code here.
Modifying the Transformations
Let's actually do some changes, so let's have the inputs that we received be encased by some brackets, for example.
Let's modify the processedOutput of text and simply add " - from Cognigy" to the end.
Testing the Changes
If I now say "Hi", you can see that the "Hello world" output has received " - from Cognigy" at the end. If I now say "hi" again, the "Hi again" is enclosed in the round brackets.
Now, let's actually do something a little bit more usable with the Input Transformer. For example, if I talk to this Flow in Spanish, we can actually translate this in the Input Transformer so that the English Flow is still able to use English input.
Using External APIs
We will add an HTTP Request to the Azure Cognitive Translate API.
Summary
Now, instead of coding your own Transformer, you can also simply use our existing Transformer samples on our GitHub repository.
Cognigy CLI
The Cognigy CLI allows you to edit your Endpoint Transformers in VS Code on your PC and then push it to Cognigy.
Thank you very much for watching our session on Endpoint Transformers. Please don't forget to visit our Cognigy Help Center under support.cognigy.com for additional resources and information.