Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Initiate outbound conversations


TAC supports outbound (agent-initiated) conversations across all channels. Your agent can send the first message over SMS, WhatsApp, or RCS, or place an outbound voice call — then handle customer replies through the same on_message_ready callback used for inbound conversations.


Prerequisites

prerequisites page anchor
  • TAC SDK installed and configured with your Twilio credentials (see Add TAC to your agent)
  • A running TAC server with channels configured (the server must be running to receive replies)
  • For Voice: TWILIO_VOICE_PUBLIC_DOMAIN set to your public domain (for example, your ngrok domain)
  • For WhatsApp: TWILIO_WHATSAPP_NUMBER set to your WhatsApp-enabled number (format: whatsapp:+1234567890)
  • For RCS: TWILIO_RCS_SENDER_ID set to your RCS Sender ID

Send an SMS to a customer and handle their replies.

PythonTypeScript
1
from tac import TAC, TACConfig
2
from tac.channels.sms import SMSChannel, SMSChannelConfig
3
from tac.models.outbound import InitiateMessagingConversationOptions
4
from tac.server import TACFastAPIServer
5
6
tac = TAC(config=TACConfig.from_env())
7
sms_channel = SMSChannel(tac, config=SMSChannelConfig(memory_mode="always"))
8
9
async def handle_message_ready(message, context, memory):
10
# Called when the customer replies
11
llm_response = await your_llm.generate(message)
12
return llm_response
13
14
tac.on_message_ready(handle_message_ready)
15
16
# Initiate outbound SMS after server starts
17
result = await sms_channel.initiate_outbound_conversation(
18
InitiateMessagingConversationOptions(
19
to="+16505551234",
20
message="Hi! This is Acme Corp. Your order has shipped.",
21
)
22
)
23
print(f"Conversation started: {result.conversation_id}")
24
25
# Start the TACFastAPIServer to receive replies
26
server = TACFastAPIServer(tac=tac, messaging_channels=[sms_channel])
27
server.start()

The initiate_outbound_conversation method creates a conversation through Conversation Orchestrator, adds both participants (customer and AI agent), and sends the initial message. When the customer replies, TAC routes their response to your on_message_ready callback.


Place an outbound voice call. The call connects to your TAC server's WebSocket endpoint, where Conversation Relay handles speech-to-text and text-to-speech.

PythonTypeScript
1
import os
2
from tac import TAC, TACConfig
3
from tac.channels.voice import VoiceChannel, VoiceChannelConfig
4
from tac.models.outbound import InitiateVoiceConversationOptions
5
from tac.server import TACFastAPIServer
6
from tac.server.config import TACServerConfig
7
8
tac = TAC(config=TACConfig.from_env())
9
voice_channel = VoiceChannel(tac, config=VoiceChannelConfig(memory_mode="always"))
10
11
async def handle_message_ready(message, context, memory):
12
llm_response = await your_llm.generate(message)
13
return llm_response
14
15
tac.on_message_ready(handle_message_ready)
16
17
# Get public domain for WebSocket URL
18
server_config = TACServerConfig.from_env()
19
public_domain = server_config.public_domain
20
21
# Initiate outbound voice call
22
result = await voice_channel.initiate_outbound_conversation(
23
InitiateVoiceConversationOptions(
24
to="+16505551234",
25
websocket_url=f"wss://{public_domain}/ws",
26
welcome_greeting="Hi! This is an AI assistant calling from Acme Corp.",
27
action_url=f"https://{public_domain}/conversation-relay-callback",
28
)
29
)
30
print(f"Call placed: {result.call_sid}")
31
32
# Start the TACFastAPIServer to handle the call
33
server = TACFastAPIServer(tac=tac, voice_channel=voice_channel)
34
server.start()

The welcome_greeting (Python) or welcomeGreeting (TypeScript) is optional — if provided, Conversation Relay speaks it to the customer as soon as they pick up, before waiting for your agent to respond.


Outbound WhatsApp and RCS

outbound-whatsapp-and-rcs page anchor

WhatsApp and RCS outbound follow the same pattern as SMS. Use the corresponding channel class and configure the required environment variable.

PythonTypeScript
1
from tac.channels.whatsapp import WhatsAppChannel, WhatsAppChannelConfig
2
from tac.channels.rcs import RCSChannel, RCSChannelConfig
3
from tac.models.outbound import InitiateMessagingConversationOptions
4
5
# WhatsApp — requires TWILIO_WHATSAPP_NUMBER env var
6
whatsapp_channel = WhatsAppChannel(tac, config=WhatsAppChannelConfig(memory_mode="always"))
7
8
result = await whatsapp_channel.initiate_outbound_conversation(
9
InitiateMessagingConversationOptions(
10
to="whatsapp:+16505551234",
11
message="Hi! Your appointment is confirmed for tomorrow at 2pm.",
12
)
13
)
14
15
# RCS — requires TWILIO_RCS_SENDER_ID env var
16
rcs_channel = RCSChannel(tac, config=RCSChannelConfig(memory_mode="always"))
17
18
result = await rcs_channel.initiate_outbound_conversation(
19
InitiateMessagingConversationOptions(
20
to="+16505551234",
21
message="Hi! Your appointment is confirmed for tomorrow at 2pm.",
22
)
23
)

Outbound conversations use the same on_message_ready callback as inbound conversations. When a customer replies to your outbound message or speaks during an outbound call, TAC delivers the message to your callback. You can distinguish inbound from outbound using the conversation session metadata if needed.


  • Channels: Learn more about channel configuration and supported channels.
  • Add TAC to your agent: Configure tools, knowledge, and memory alongside channels.