For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
WebsiteStatusSupportDashboard
DocumentationAPI ReferenceMCPSDKsCLI (new)What's New?
DocumentationAPI ReferenceMCPSDKsCLI (new)What's New?
  • Get started
    • Introduction
    • Phone calls
    • Web calls
    • Vapi Guides
    • Composer
    • CLI quickstart
  • Assistants
    • Quickstart
      • Variables
      • Multilingual support
      • Personalization with user information
      • Voice formatting plan
      • Flush syntax
      • Background messages
      • Idle messages
      • Assistant hooks
      • Background speech denoising
      • Pronunciation dictionaries
      • Email address reading
    • Tools
    • Custom keywords
    • Custom voices
    • Custom transcriber
    • Custom TTS
  • Observability
    • Boards
  • Squads
    • Quickstart
    • Overview
    • Handoff tool
    • Passing data between assistants
  • Best practices
    • Prompting guide
    • Debugging voice agents
    • Enterprise environments (DEV/UAT/PROD)
    • IVR navigation
  • Phone numbers
    • Free Vapi number
    • Inbound SMS
    • Phone Number Hooks
  • Calls
    • Call end reasons
    • Troubleshoot call errors
  • Outbound Campaigns
    • Quickstart
    • Overview
  • Chat
    • Quickstart
    • Streaming
    • Non-streaming
    • OpenAI compatibility
    • Session management
    • Variable substitution
    • SMS chat
    • Web widget
    • Webhooks
  • Workflows
    • Quickstart
    • Overview
LogoLogo
WebsiteStatusSupportDashboard
On this page
  • Overview
AssistantsConversation behavior

Background messages

Silently update chat history with background messages
Was this page helpful?
Edit this page
Previous

Idle messages

Keep users engaged during conversation pauses
Next
Built with

Overview

Background messages let you add information to the chat history without interrupting or notifying the user. This is useful for logging actions, tracking background events, or updating conversation context silently.

For example, you might want to log when a user presses a button or when a background process updates the conversation. These messages help you keep a complete record of the conversation and system events, all without disrupting the user experience.

1

Add a Button to Trigger the Message

Add a button to your interface with an onClick event handler that will call a function to send the system message:

1<button id="log-action" onClick="logUserAction()">Log Action</button>
2

Log the Action as a System Message

When the button is clicked, the logUserAction function will silently insert a system message into the chat history:

1function logUserAction() {
2 // Function to log the user action
3 vapi.send({
4 type: "add-message",
5 message: {
6 role: "system",
7 content: "The user has pressed the button, say peanuts",
8 },
9 });
10}
  • vapi.send: The primary function to interact with your assistant, handling various requests or commands.
  • type: "add-message": Specifies the command to add a new message.
  • message: This is the actual message that you want to add to the message history.
    • role: “system” Designates the message origin as ‘system’, ensuring the addition is unobtrusive. Other possible values of role are ‘user’ | ‘assistant’ | ‘tool’ | ‘function’
    • content: The actual message text to be added.
Practical Use Cases
  • Silent logging of user activities.
  • Contextual updates in conversations triggered by background processes.
  • Non-intrusive user experience enhancements through additional information provision.