Text Chat in Mobile Apps
Voice is the main way to talk to the VableAI agent in a mobile app, but some users would rather type. The mobile SDKs come with a text chat for them. It talks to the same agent, which can do the same things in your app as it can on a call.
Text chat is in the Flutter, iOS and Android SDKs. The web widget has its own chat built in.
What the user sees
The chat is a panel that rises from the bottom of the screen. Your app stays visible and usable above it.
- Replies stream in as the agent writes them.
- Actions show as small lines, such as "⚡ Opening Orders", when the agent does something in your app. While it works, the panel drops to a small bar so the user can see the screen, and it comes back up when the answer arrives.
- The user can drag the panel to a small bar, half the screen, or nearly all of it.
- The button next to the text box sends what's typed. When the box is empty, it's a microphone that switches the conversation to a call.
- During a call, a keyboard button beside the end button switches the conversation back to the chat.
- The pencil button starts a new conversation.
One conversation for voice and chat
A call and the chat are two ways into the same conversation, so the user can switch between them freely and the agent remembers what was said.
- The user talks one way at a time. Opening the chat ends a call that's running, and starting a call closes the chat.
- Calls show in the chat as a line such as "Voice call · 2 min".
- The conversation is kept on the device and carries on the next time the app opens, so the agent still has it and the user sees what was typed.
- After an hour unused, the next call or chat starts a new conversation. The user can also start one with the pencil button.
Flutter
Add a chat button next to the button that starts a call, and open the chat with a BuildContext from below your MaterialApp:
Row(
children: [
ElevatedButton.icon(
onPressed: () => Vable.startVoiceChat(context),
icon: const Icon(Icons.mic),
label: const Text('Talk to us'),
),
IconButton(
tooltip: 'Chat',
onPressed: () => Vable.openChat(context),
icon: const Icon(Icons.chat_bubble_outline),
),
],
)
The agent sees the screen and runs your intents from the chat just as it does on a call.
| Method | What it does |
|---|---|
Vable.openChat(context) | Opens the chat |
Vable.closeChat() | Closes it. A reply that's still arriving is let finish first |
Vable.isChatOpen() | Whether the chat is on screen |
Vable.startNewChat() | Forgets the conversation and starts a new one |
Vable.setChatButtonVisible(false) | Hides the chat button on calls |
To follow the chat, for example to hide your own buttons while it's open:
Vable.onChatOpened = () => setState(() => chatOpen = true);
Vable.onChatClosed = () => setState(() => chatOpen = false);
Vable.onVoiceChatStarted = () => setState(() => onCall = true);
Vable.onVoiceChatEnded = () => setState(() => onCall = false);
onVoiceChatStarted is also called when the user starts a call from the chat's microphone button.
Your own chat UI
If you'd rather draw the chat yourself, send messages with sendMessage and read the conversation from chatMessages. Each change comes through: a new line, or a reply growing as it streams in.
await Vable.sendMessage('Where is my order?');
StreamBuilder<List<VableChatMessage>>(
stream: Vable.chatMessages,
initialData: Vable.currentChatMessages,
builder: (context, snapshot) {
final messages = snapshot.data ?? const [];
return ListView(
children: [
for (final message in messages)
Text('${message.role.name}: ${message.text}${message.isStreaming ? '…' : ''}'),
],
);
},
);
Each VableChatMessage has a role:
| Role | What it is |
|---|---|
user | Something the user typed |
assistant | The agent's reply. isStreaming is true while it's still arriving |
action | Something the agent did in your app |
error | A turn that failed, with a message for the user |
call | A call in the same conversation |
A turn that fails also calls Vable.onChatError with message_failed, tokens_exhausted or connection_failed. The chat already shows the user what went wrong.
iOS
import VableAI
// Beside your call button
Vable.shared.openChat()
| API | What it does |
|---|---|
openChat() | Opens the chat |
closeChat() | Closes it |
isChatOpen | Whether the chat is on screen |
sendMessage(_:) | Sends a message as the user, without the chat on screen |
chatMessages | The conversation's lines, oldest first |
setChatDelegate(_:) | Hears about new lines, failures, and the chat opening and closing |
startNewChat() | Forgets the conversation and starts a new one |
setChatButtonVisible(_:) | Shows or hides the chat button on calls |
final class ChatObserver: VableChatDelegate {
func vableChatDidUpdate(_ messages: [VableChatMessage]) {
// A new line, or a reply growing as it streams in
}
func vableChatDidFail(_ code: String) {}
}
Vable.shared.setChatDelegate(observer)
try await Vable.shared.sendMessage("Where is my order?")
The agent's actions reach your VableNavigationDelegate, as they do on a call, and you answer them with sendToolResult. The delegate's onVoiceChatStarted() is called when a call connects, including one started from the chat.
Android
import ai.vable.mobile.Vable
// Beside your call button
chatButton.setOnClickListener { Vable.openChat(this) }
| API | What it does |
|---|---|
Vable.openChat(activity) | Opens the chat over that activity. It follows the user to other activities |
Vable.closeChat() | Closes it |
Vable.isChatOpen() | Whether the chat is on screen |
Vable.sendMessage(text, callback) | Sends a message as the user, without the chat on screen |
Vable.chatMessages() | The conversation's lines, oldest first |
Vable.setChatListener(listener) | Hears about new lines, failures, and the chat opening and closing |
Vable.startNewChat() | Forgets the conversation and starts a new one |
Vable.setChatButtonVisible(visible) | Shows or hides the chat button on calls |
Vable.setChatListener(object : VableChatListener {
override fun onMessagesChanged(messages: List<VableChatMessage>) {
// A new line, or a reply growing as it streams in
}
override fun onError(code: String) {}
})
Vable.sendMessage("Where is my order?") { error -> /* null when it was sent */ }
The agent's actions reach your VableEventCallback, as they do on a call, and you answer them with Vable.sendToolResult. The callback's onVoiceChatStarted() is called when a call connects, including one started from the chat.