In this guide, we will use the Integry.JS SDK and Integry Functions API to enable users to connect apps and invoke functions in those apps from your AI application.
Before you proceed, please sign up for a free trial (if you haven't).
Follow the steps here.
Your users have to first connect an app before you can invoke functions in that app. You could use or more of the following options.
Call the showApps() method to easily show all (or some) available apps as a marketplace. Users will simply click an app to connect.
Build your own apps marketplace and call the connectApp() method when they click on an app.
Call isAppConnected() method (when they try to use a function of an app) to check if the app is connected. If not, ask them to connectApp().
Let's say your user says they want to "send a message saying hello! to the random channel on slack".
In order to execute the slack-post-message
function, you have to first predict that its the most relevant function.
You can simply pass the prompt to Integry and predict the function with Integry AI, or predict it yourself (by listing all available functions).
Call the functions/
API endpoint with predict_function=true&prompt=<user_message>
to get the most relevant function. You can also have Integry predict the arguments.
Sample Response:
The response will be empty if Integry is unable to predict the function. You can ask the user to improve the prompt
and try again.
Retrieve a list of available functions using the /functions
endpoint and pass them to your AI model. Your model will predict the function to use.
If you need to call an endpoint that is not supported by Integry, you can make a Passthrough Request.
In order to invoke a function, you have to first prepare the arguments based on the parameters that the function requires.
Similar to predicting the function, you can simply pass the prompt to Integry and predict the arguments with Integry AI, or predict them yourself (using the function spec).
Parameter vs Argument: A function parameter is the placeholder name of the type of input the function expects. The actual value passed is called the argument.
Call the functions/
API endpoint with predict_function=true&predict_arguments=true&prompt=<user_message>
to get the most relevant function with populated arguments.
Sample Response for Prediction with Populated Arguments:
Alternatively, if you predicted the function yourself and want Integry to predict the arguments, call the functions/<function_name>
API endpoint with predict_arguments=true&prompt=<user_message>
to get the function with populated arguments.
The response is the same as above.
Call the functions/<function_name>
endpoint to get the function spec and pass it to your AI model. Your model will predict and populate the arguments.
You may need to make additional calls to source functions to fetch options. Once you have the related data from the source function, use your model to pick the most relevant value from the set.
If you use predict the arguments with Integry AI, we handle this for you.
Before you invoke the function, if you want the user to confirm the predicted arguments, or provide one (or more) required arguments that could not be predicted, you can call showFunctionUI()
method to show the Function UI to the user (with pre-filled arguments, if any).
This will open the Function UI (with the pre-filled arguments) in a modal.
This method returns a result
object with the filled-in arguments that you can use to invoke the function.
Functions that mutate data can potentially do irreversible damage. Even if you have predicted the arguments, consider always showing the Function UI to the user (with the predicted arguments) so they can confirm before you execute.
Call invokeFunction()
with the <function_name>
and arguments
object to execute the function.
The result
object will have the response from the app if the function was executed (or error details if it wasn't).
In this case, you should see the following success response from Slack in the console:
That's it! You have enabled your users to connect apps and execute functions in those apps from your AI application using Integry Functions.
Try fetching data using a function like pipedrive-get-all-persons
. It supports paginated calls so the the result will include a next_page
cursor that you will include in the arguments in the next invocation.