How add an extension tool that respond requests?
Hi, is possible to me add a totally custom response, e.g pass the request to an extension script and let him to respond with a Json?
I'm very confuse about how do this, i try to add a script in the message responder -> response (tab) but on this i only can manipulate context on script created in that way.
I want to receive the input and return the response on the script, and i'm very confused about it, in documentation i can find how i make the script but i can't find where and how i create it.
Thanks if someone can help me
Best Answers
-
Hi angrymouse,
If you want to access the request information in a script, my recommendation would be to use a text databank to grab the entire request and then reference that databanked value using context.getValue("Generated Data Source", "extracted column name").
Alternately, you might be able to use the Custom Responder Correlation to have access to that incoming request body immediately in a script. Just make sure that if you use this particular style, you will need to pass a boolean value as part of that script definition.
6 -
For the method call, "Generated Data Source" should appear exactly as-is. "Extracted column name" should be whatever you name the extraction in the text databank. See the picture below for an example:
Here, I am extracting the entire body of the request by not specifying left and right bounds for my text.
The datasource column both in the window and along the bottom are "myColumn". In my case, the method call would look like:
context.getValue("Generated Data Source", "myColumn");
Hope this helps!
5
Answers
-
Good morning,
Yes, it is certainly possible to script a custom response. However, what is it that you're trying to accomplish with scripting that you can't with the built-in tools? Perhaps we can propose a better solution
Below is simple scripted responder that returns some JSON:
Some additional references:
Language Specific Tips
Creating a Custom Script/Extension Tool
Scripting Values Based on Incoming Requests0 -
Thanks for the answer.
We are trying to customize complex scenarios, atm we are trying to do a POC that can respond with mocks relatives to the input.This mocks we want to save in database in diferent tables to choose according to request data. If you have a sugestion for this case i'll be happy xD.
0 -
But about your example, doing how you did, i can only access the context object.
In this state we can't access the request data in the script, how we want.0 -
Hi Thomas, thank you so much for the answer.
What i put in "column name" and "Generated Data Source" when i use text databank?context.getValue("Generated Data Source", "extracted column name")
0 -
In case this helps, see Accessing Data Sources from Scripts
1