function call in react js web sdk
# support
s
when i use function call, how to return a response to assistant (like success or failure) in web sdk (react js)
v
message has been deleted
@SajithSPY To return a response to the assistant after a function call in a web SDK using React JS, you typically handle the promise returned by the function call. Here's a concise example of how you might do it:
Copy code
javascript
function callYourFunction() {
  yourFunctionCall() // This is where you call your API function
    .then(response => {
      // Handle success
      console.log('Success:', response);
      return { "result": "The function call was successful." };
    })
    .catch(error => {
      // Handle error
      console.error('Error:', error);
      return { "result": "The function call failed." };
    });
}
In this example,
yourFunctionCall
represents the function you are calling. It returns a promise that resolves with the response from the function call. The
.then()
method is used to handle a successful call, and the
.catch()
method is used to handle any errors. When the function call is successful, you return a JSON object with a success message. If the function call fails, you return a JSON object with a failure message. These JSON objects can then be used by the assistant to determine the next steps in the conversation.
You can continue this conversation by mentioning me in the message.
s
@Vapi can you elaborate?
s
you can subscribe to client side messages for tools calling, but you can return the tool call response from client side.
s
Can’t?