aiMessage

View as MarkdownOpen in Claude

Send a message to an active AI agent session on the call. Use this to inject context, instructions, or simulated user input into a running AI conversation.

This method requires an active AI session started via ai(). Calling it without an active session has no effect.

Parameters

messageText
string | undefined

The message text to send to the AI agent.

role
string | undefined

The role of the message sender. Valid values:

  • "user" — simulate user input
  • "system" — send a system-level instruction
  • "assistant" — inject an assistant response
reset
Record<string, unknown> | undefined

Reset configuration. Allows resetting AI state such as the conversation history or functions.

globalData
Record<string, unknown> | undefined

Update the global data accessible to the AI and SWAIG functions.

Returns

Promise<Record<string, unknown>> — Server response confirming the message was sent.

Example

import { RelayClient } from '@signalwire/sdk';
const client = new RelayClient({
project: process.env.SIGNALWIRE_PROJECT_ID!,
token: process.env.SIGNALWIRE_API_TOKEN!,
contexts: ['default']
});
client.onCall(async (call) => {
await call.answer();
// Start an AI agent
const action = await call.ai({
prompt: { text: 'You are a helpful assistant.' },
});
// Inject a system message after 10 seconds
await new Promise((resolve) => setTimeout(resolve, 10_000));
await call.aiMessage({
messageText: 'The caller is a VIP customer. Be extra helpful.',
role: 'system',
});
await action.wait();
});
await client.run();