background messaging via API?
# support
j
Hi there, is it possible to use Background messaging (https://docs.vapi.ai/assistants/background-messages) via API? I want to add a message as soon as a call is established, but can't find anything in the documentation
v
@jooles Absolutely, you can use background messaging via the API. The
.send()
function is exactly what you need to use to send intermediate messages during a call. When a call is established, you can send a message using this function with the type set to "add-message". Here's how you can do it:
Copy code
javascript
vapi.send({
  type: "add-message",
  message: {
    role: "system",
    content: "Your custom message here",
  },
});
Replace "Your custom message here" with the message you want to add as soon as the call is established. If you need any further assistance or have additional questions, feel free to ask!
You can continue this conversation by mentioning me in the message.
Got it. Tagging @User for additional help.
j
This does not help, as I need to find an information how to send this message via API
fixed! 🙂
d
Hey @jooles was you able to solve it and send background messages via REST Api to the active call? Docu is still not fixed how to do it,..
v
To send a background message to an active call, use the Vapi Web SDK's
.send()
method as shown below:
Copy code
javascript
vapi.send({
  type: "add-message",
  message: {
    role: "system", // or "user", "assistant", etc.
    content: "Your background message here",
  },
});
This will silently add a message to the chat history during an active call. For REST API usage, there is currently no official documentation on sending background messages directly via HTTP requests. [See documentation](https://docs.vapi.ai/assistants/background-messages) Sources: - [Background messages documentation](https://docs.vapi.ai/assistants/background-messages) - [Vapi Web SDK documentation](https://docs.vapi.ai/sdk/web)
k
checking if this is resolved/solved for you?
k
Hey @jooles, what's blocking you with respect to live call control via API
Yes, you can add background messages via the Vapi Web SDK’s vapi.send() method with "add-message" to insert system messages when a call starts.
3 Views