Graine AI

Chat

The typed side of the assistant on every SDK — how the chat and the call take turns, showing the chat in React Native, iOS, Android, Flutter and Kotlin Multiplatform, the window size, conversations that continue and starting a new one, drawing your own, and the chat window's design.

The chat is the same agent, typed. It knows the screen the customer is on, can run your actions, and draws the same components as the call — a list of plans, a set of time slots — in the chat window, in your brand's design. Customers who cannot talk out loud, on a train or in an office, still get the agent.

The call and the chat

What a customer gets is the agent's setting, not your code: Agent → Embed & Widgets → Appearance → Setup.

What visitors getIn your app
Call and chatThe bar opens on the one Opens on names, and carries a switch to the other
Voice onlyThe call. No switch
Chat onlyThe chat. No microphone is opened and no call engine is loaded

One conversation runs at a time. Moving to the chat ends the call, and moving back closes the chat — otherwise the agent would answer twice, aloud and in writing. A native call ends a chat as it ends a call in the bar.

How it works

The chat windowdrawn by the SDK,in your design:header, bubbles,starters, composerThe Graine SDKthe message, the screen,who the customer isanswers actions,draws componentsYour agentthe same prompt,knowledge and actionsas the call, replyingin textmessage · taptext · screenreply · componentwords as they comeThe welcome message arrives as the first reply. A tap on a component is the customer's next message.

The same agent as the call, with the same screen context, actions and components — in text.

Every SDK opens a text connection of its own for the chat — the native chat on iOS, Android and Flutter from 0.7.0 — so the chat needs no microphone and no permission, and draws in your brand's design.

Show it

The chat window in one design on two phones: on an iPhone, the demo app mid-conversation, with the welcome, the customer's request, the reply and a card of three call times; on Android, the dashboard's preview of a new chat with the brand's starters above the composer

GraineVoiceBar already draws the chat window when the agent offers the chat, with the switch when it offers both. Nothing more to mount. To open on the chat for one screen, or follow which is open:

<GraineProvider … surface="chat" onSurfaceChange={(s) => analytics.track("agent_surface", { s })}>
 
const { surface, canSwitch, setSurface } = useGraineSurface();   // "voice" | "chat"

surface chooses among what the dashboard allows; it cannot add a surface the agent does not offer.

Window size

How big the chat opens is part of the design: the Garage's Chat window tab → Window size — Compact (the default), Large or Full screen — the same in light and dark. Each agent opens at its own design's size.

On a phoneOn a tabletOn a website, on a computer
CompactThe window above the bar, as it has always beenThe sameThe panel above the launcher, as it has always been
LargeA sheet from the bottom over about 92% of the screen, the app dimmed behind it. Swipe it down, tap the dimmed app, or press the header's chevron to close itA panel 420 wide and up to 760 tall in the bottom corner on the launcher's side; the app beside it stays usableThe same panel, above the launcher
Full screenThe whole screen, with the close chevron leading the headerThe whole screenThe larger panel

Every SDK's bar draws these sizes — React Native's GraineVoiceBar, iOS's GraineAgentBar, Android's GraineAgentBarView, Flutter's GraineAgentBar and the Kotlin Multiplatform bar — and so does the website's widget. The chat views you place yourself (GraineChatView, GraineChatViewController, GraineChatActivity, Flutter's GraineChat and React Native's GraineChatScreen) fill whatever space your app gives them.

A phone is a window whose shorter side is under 600 points — or, for a website, a browser window narrower than 640 px. There a website behaves like a phone: Large is a sheet over 92% of the page, Full screen the whole page; the launcher steps aside and the page stops scrolling while it is open.

At every size the composer stays above the keyboard, the conversation, its components and the earlier messages look the same, and moving between the call and the chat keeps the size.

Your app can choose, for every chat and for one open. One open's size wins, then the app's, then the design's; a size an SDK does not know is passed over. An open moves the bar on screen to the chat, at that size, until the chat closes.

chatSize on GraineProvider for every chat, and client.openChat({ size }) to move to the chat and open it now. GraineChatScreen is the chat as a screen of your own app: while it is up, the customer is in the chat and the bar steps aside.

<GraineProvider baseUrl="https://www.graine.ai" publishableKey="pk_live_…" chatSize="large">
 
const client = useGraineClient();
client.openChat({ size: "full" });
 
<Stack.Screen name="Help">
  {({ navigation }) => <GraineChatScreen onClose={navigation.goBack} />}
</Stack.Screen>

Give the bar safeArea={useSafeAreaInsets()} (react-native-safe-area-context) for exact insets on a sheet or a full screen.

What the chat carries

In the chat
The welcome messageThe agent's first reply — not when the conversation continues (below)
RepliesText, arriving as it is written
Screen context and who the customer isExactly as for the call
Your actionsRun in your handlers, answered as for the call
ComponentsDrawn in the chat window; a tap is the customer's next message, and the structured answer goes to your webhook
Replies your assistant suggestsChips under its message; a tap is the customer's next message — below
The end of the chatWhen your assistant ends it, the chat can ask how it went; the answer is kept with the conversation — below
MemoryWhen memory is on and the customer has an identifier: read at the start of each chat, and again when the customer refers to an earlier conversation — Memory
Earlier messagesFor a returning customer with memory on — below
Call HistoryThe conversation, its transcript and what happened in the app

Coming back to a conversation

For an identified customer with memory on, the chat continues where they left it — later that day, after the app was closed, on another of their devices — for 7 days after their last message with that agent. The chat window opens on the conversation instead of on a new chat:

  • The earlier messages, oldest first — up to the last 50 with this agent.
  • A voice call as one row: what was said on a call in your app or on your website shows as Voice call and the time it started, not as its transcript.
  • A date line — Today, Yesterday, or the date — wherever the day changes.
  • No starters, and no second welcome. The agent continues the conversation and the customer types next. A new call still opens with a greeting, and the agent knows what was said.

Each agent keeps its own conversation: the chat with your help desk never shows what was said to your sales agent. Messages still sending when the customer left stay at the end, and go when the chat connects.

The window opens on a new chat for an anonymous customer, a customer who turned memory off, a customer who was forgotten, and after 7 days without a message. forgetMemory() clears the chat on screen too, but only when it succeeds: a failure — Graine unavailable (503), another customer's device, no network — leaves the chat as it is, along with the memories. What is kept, and for how long: Memory → Conversations continue.

How long a conversation stays open

Closing the chat closes its session 15 seconds later — the grace covers a quick hop to the booking sheet or a component; set your own with the chatCloseDelaySeconds option (0 closes it at once, at most 300) — so a chat nobody is looking at is never an open, billed session. Closing it does not end the conversation: for an identified customer, opening the chat again continues it from where it was, with the earlier messages and no new welcome, and each closed session is listed in their past sessions. The app going to the background ends the session at once, as it ends a call (endOnBackground, on by default), and so does close().

A text chat is charged per session of up to 5 minutes; a longer chat counts one more session per further 5 minutes. Its time counts until its last message, so a chat left open afterwards is not charged for the wait. Talk is charged per minute, like a call. See Plans and tiers.

When Graine ends a conversation that sat idle, the chat does not start a new one by itself: the messages stay and the header says Disconnected. Opening the chat or sending a message connects again. A dropped network connection is different: the chat reconnects by itself, with Reconnecting… while it tries. From 0.14.3; 0.14.0 and 0.14.1 kept a chat connected for 5 idle minutes after it left the screen.

When the conversation cannot continue

The chat connects again by itself after a dropped connection, and when the customer opens it again after its conversation closed. When the conversation cannot continue (an anonymous customer, memory off, or earlier messages that could not be read in time), the agent starts a new one, and the chat window says so: a quiet line, Disconnected · new conversation, above the agent's new opening, with the earlier messages still above it. An opening the customer never answered is replaced instead, so a welcome never shows twice. A conversation that continues opens with no line at all. New in 0.14.0; a chat you draw yourself sees the same turns as before.

Start a new conversation

A support chat often wants a fresh thread. While the chat window holds earlier messages, its header shows New conversation — a compose icon beside close. Tapping it starts over at once, without asking: nothing is lost for your team, because Call History keeps every conversation.

Your app can do the same from a button of its own:

const client = useGraineClient();
await client.newConversation();
  • The agent's chat connection ends, Graine drops the conversation it kept for this agent and customer, the window clears, and a fresh chat opens — with the welcome message and the starters again.
  • Memory stays. What the agent remembers about the customer is untouched; to forget that, use forgetMemory().
  • Only this agent's conversation. With several agents, each starts over on its own: call it on the agent whose chat it is.
  • For an anonymous customer nothing was kept, so it only clears the window.
  • If Graine refuses — another customer's device, no network, Graine unavailable — nothing changes: the promise rejects (iOS and Flutter throw, Android's callback hears the error) and the chat is as it was.

Past sessions

New in native 0.14.3 and React Native 0.47.2. Your app can show an identified customer every earlier session they had with the agent — not only the conversation the chat continues — and open any of them, read-only, the way your team sees them in Call History. A session is one conversation: a chat from when it opened until it closed, a voice conversation in the bar, or a call either way.

State or actionWhat it does
chat.pastSessions{ sessions, loading, hasMore, error }: the customer's earlier sessions with this agent, newest first. Empty until your app refreshes it, and emptied when the customer changes (identify() with someone else, or with nobody).
chat.refreshPastSessions()Loads the first page, in place of what was loaded.
chat.loadMorePastSessions()Loads the next page and adds it after the others.
chat.sessionTranscript(id)One session in full: its messages, oldest first, each with who said it (customer or agent), the words and the time.

Each SDK spells these in its own idiom — Chat reference.

  • Each session says when it started and ended, how long it lasted, its channel — chat, voice or call — and for a call its direction: inbound when the customer called, outbound when the agent called them. Its status says how it ended, in plain words: completed, missed, declined, busy, voicemail or failed, and for a chat chat_closed, closed_inactive (closed after a while with nothing said), agent_ended or closed_time_limit. It also carries how many messages it holds, and a preview: the customer's first message, up to 120 characters.
  • Only the customer's own, on their own device. Sessions are listed per customer and per agent, and only on a device the customer is signed in on — the same rule as their memories, within the agent's devices per customer. Another customer's session is never listed, and opening one fails with not_found, as an id that never existed does.
  • Only sessions that have ended. The chat open now is the live chat, never a past session.
  • A page holds up to 20 sessions. hasMore says whether there is another.
  • When it cannot load, error says why and the sessions already shown stay: identity_required (nobody is identified), device_limit (this device is not one of the customer's), rate_limited or unavailable (try again).
  • What is not in it: summaries, analysis, costs and recordings stay with your team in Call History. Where a session did not record when each message was said, its messages carry the time the session started.

In the chat window

The chat window draws the style chosen in the Garage — the header, the bubbles, the wallpaper, the chips, the cards, the composer, the welcome and the rating (The Garage → The chat window) — and these behaviours on every SDK, with nothing in your code. A few take one line from your app.

What the chat is about

Pin what the conversation is about — the item, request or account on the screen the customer opened the chat from — and the chat draws it as a bar under the header or a card at the top of the thread, as the design says. A title, and if you like a line under it, a picture and a short badge. It is for the customer's eyes only: it is never sent to your assistant (tell your assistant about the screen with screen context, as always).

const { setChatPin } = useGraineAgent();
setChatPin({ title: "Getting started", subtitle: "Step 2 of 4", badge: "In progress" });
setChatPin(null); // take it away
  • One line each: a title up to 60 characters, a subtitle up to 80 and a badge up to 24; longer words are cut. A pin with no title is no pin.
  • A picture from an https address fills the thumbnail; with none, the title's first letter stands in.
  • It stays until you change it or take it away, also while the chat is closed. With Context card set to Off in the Garage, nothing is drawn.

Attachments

The composer shows a paperclip only where the design asks for one and your app handles attachments. A tap calls your handler; what happens next — a picker, a camera, an upload — is your app's. The SDK sends nothing itself.

<GraineProvider publishableKey="pk_live_…" onChatAttach={() => openYourPicker()}>

Replies your assistant suggests

When your assistant suggests replies for its message, they appear as chips — under the message, or above the composer, as the design places them. A tap sends the reply as the customer's own message, exactly as if typed. The chips go when the customer sends anything, when your assistant starts its next message, and when the chat ends.

Your assistant suggests replies when Suggested replies is on for it — in the agent's Embed & Widgets → Appearance, above the Garage. It is off until you turn it on. With it on, your assistant offers a few short replies where they help the customer answer, and none where it asked for something only they can type, such as a name or a number. Chats only: calls are never affected.

Drawing your own chat, the replies are yours to draw: React Native useGraineAgent().quickReplies and sendQuickReply(reply); iOS, Android and Flutter chat.quickReplies and chat.sendQuickReply(reply); Kotlin Multiplatform Graine.chat.quickReplies and Graine.chat.sendQuickReply(reply). Draw each reply's label; a tap sends its text.

When your assistant ends the chat

When your assistant ends a conversation, the chat stops typing, the suggested replies go and, where the design asks for it (Ask for a rating in the Garage), a card asks "How was this chat?" — or your own question — with thumbs, stars or faces. The chat stays connected for up to a minute for the answer; a message the customer sends instead carries the conversation on. One answer per conversation. It is kept with the conversation in Call History — on its row and in its details, as Rated 4 out of 5 or Thumbs up — and your app hears it:

useGraineEvents((e) => {
  if (e.type === "chat_rated") track(e.rating.value, e.rating.scale); // and e.rating.style
});

Thumbs are 1 (up) or 0 (down) out of 1; stars and faces 1 to 5 out of 5. The answer is also on the chat as it stands (rating, React Native chatRating). A customer who answers after the conversation has closed still sees their choice, and your app still hears it.

Reading and writing

  • Replies arrive smoothly, revealed as they are written, never in jumps. With reduced motion they appear as they come.
  • Light formatting in your assistant's messages is drawn — bold, italics, lists, links and code — never shown as markup. Links open in the browser, and only web, email and phone links are links.
  • A long press copies a message's words.
  • The typing indicator follows the design: its loader, dots, a wave, or words.
  • A message waits for the connection instead of failing: it shows as waiting and goes when the chat is back. One that could not be sent says Not sent · Tap to retry.
  • A calm banner under the header says "Reconnecting…" while a dropped chat comes back, or that messages will send when the customer is back online.
  • Scrolled up, the chat stays where the customer is reading, and a pill offers the latest message, with how many new ones have arrived.
  • For everyone: each message is one element to a screen reader — who said it, the words, the time and whether it was sent; every button has a label; text follows the system's text size; reduced motion stops the animations; and the whole window mirrors for right-to-left languages.
  • Long conversations stay quick: only the messages on screen are drawn.

Drawing your own chat

The SDK's chat window draws the design chosen in the dashboard. To draw your own in React Native, useGraineAgent() gives you messages, send(text) and connected, and useGraineWidget() the component on screen — Components → Drawing them yourself. Your own window stops following the dashboard's design; useGraineTheme() gives you its tokens to match. On iOS, Android, Flutter and Kotlin Multiplatform, draw from the chat's turns (messages on Android) and its state — Chat reference.

An earlier message put back when the conversation continued carries restored, and one said on a call carries channel voice: draw a run of those as one Voice call row, not as bubbles, and offer New conversation while any are on screen — GraineChatTurn. Every SDK hands you those rows, day separators included: React Native chatTurnRows(messages) (chatRows(items, read) for items of your own), iOS GraineChatRows.build(turns), Android ChatRows.build(messages), Flutter ChatRows.build(turns, now:) and Kotlin Multiplatform GraineChatRows.build(Graine.chat.turns.value) — GraineChatRows. To empty the chat on screen without ending the conversation: clear() (React Native clearChat()).

Its design

The chat window's style and every piece of it — the header, the bubbles and their times, the wallpaper, the chips, the cards, the composer, the welcome and the rating — and its size, words, avatar, starters and placeholder are set in the Garage, on the Chat tab, with the frame under Interior — The Garage → The chat window.

Troubleshooting

What you seeCheck
No chat, only the callWhat visitors get is Voice only
No switchThe agent offers one of the two, not both
A microphone on a chat-only agentAn SDK older than native chat: update it
The agent answers twice, aloud and in writingTwo conversations are open: in React Native, a launcher and the provider's own connection — pass autoConnect={false} on SDKs older than 0.34
The chat window is not in your designYour app draws its own, or the SDK predates the design
The chat keeps its old look after a chat style was chosenThe SDK is older than 0.13.0, or the app has not restarted since the design was saved
No paperclipThe design draws none, or your app sets no attachment handler
No context cardYour app has not pinned one, or Context card is Off in the Garage
A returning customer's chat opens emptyThey are not identified, memory is off for the agent or for them, it has been more than 7 days, or the SDK is older than 0.7.0 — Memory → Troubleshooting
Past sessions stay emptyThe customer is not identified, error is device_limit (they are signed in on the most devices allowed), the app has not called refreshPastSessions(), or the SDK is older than 0.14.3 (React Native 0.47.2)

Where next