Back to Arky

Support

Fixed-step support flows, conversations by chat and email, replies, assignment, and resolution

Support has two records you configure or read:

  • a support flow is a fixed set of steps (messages, choices with buttons, questions, collecting an email contact, sending an email, handing the conversation to the team, and resolving it) with the entries that start it: the website chat, and new email to a receiving address;
  • a conversation is one customer’s chat, email thread, or both, with its messages. Chats and emails share one inbox in Admin.

Customers reach the store through the website chat, or by email to an address whose domain receives in the store’s own Resend account. Every reply comes from a person or from a flow’s fixed steps.

For the end-to-end setup, see the Support guide.

Support Flows

import type { Email, EpochMilliseconds, LocalizedText } from "arky-sdk";

interface SupportFlow {
	id: string;
	store_id: string;
	key: string;
	entries: SupportEntry[];
	steps: Record<string, SupportStep>;
	created_at: EpochMilliseconds;
	updated_at: EpochMilliseconds;
}

type SupportEntry =
	| { type: "chat"; start_step_key: string }
	| {
			type: "incoming_email";
			email_address_id: string;
			reply_language: string;
			reply: Email;
			start_step_key: string;
	  };

type SupportStep =
	| { type: "chat_message"; text: LocalizedText; next_step_key: string }
	| { type: "chat_choice"; text: LocalizedText; buttons: { label: LocalizedText; next_step_key: string }[] }
	| { type: "chat_question"; text: LocalizedText; input_type: "text" | "email" | "phone"; next_step_key: string }
	| {
			type: "collect_email_contact";
			text: LocalizedText;
			subject: LocalizedText;
			reply: Email;
			next_step_key: string;
	  }
	| { type: "send_email"; email: Email; next_step_key: string }
	| { type: "hand_to_team" }
	| { type: "resolve" };
StepWhat happens
chat_messageshows its text in the chat and goes straight on
chat_choicewaits for one of its buttons
chat_questionwaits for an answer of its input_type, saved under the step’s key
collect_email_contactasks for the customer’s email; the answer is an email contact in the chat’s language, and the chat becomes a chat and email conversation with this step’s subject and reply selection
send_emailemails its own complete selection of a support_message template to the conversation’s email contact
hand_to_teamgives the conversation to the team
resolveresolves the conversation
POST /v1/stores/{store_id}/support-flows
SDK: sdk.support.flow.create()
GET /v1/stores/{store_id}/support-flows
SDK: sdk.support.flow.find()
GET /v1/stores/{store_id}/support-flows/{id}
SDK: sdk.support.flow.get()
PUT /v1/stores/{store_id}/support-flows/{id}
SDK: sdk.support.flow.update()
DELETE /v1/stores/{store_id}/support-flows/{id}?expected_updated_at=
SDK: sdk.support.flow.delete()
import type { Email } from "arky-sdk";

const { creation_templates } = await sdk.store.emails.get({ store_id: storeId });
const supportReply: Email = {
	email_template_id: creation_templates.support_message,
	sending_address_id: supportAddress.id,
	from_name: "Northwind support",
	reply_to: { type: "address", email_address_id: supportAddress.id },
};

const flow = await sdk.support.flow.create({
	store_id: storeId,
	id: crypto.randomUUID(),
	key: "default",
	entries: [{ type: "chat", start_step_key: "greeting" }],
	steps: {
		greeting: {
			type: "chat_choice",
			text: { en: "Hi. Ask us anything, or leave your email." },
			buttons: [
				{ label: { en: "Ask a question" }, next_step_key: "question" },
				{ label: { en: "Talk to us" }, next_step_key: "email" },
			],
		},
		question: {
			type: "chat_message",
			text: { en: "Type your question below. The team answers here." },
			next_step_key: "team",
		},
		email: {
			type: "collect_email_contact",
			text: { en: "What's your email?" },
			subject: { en: "Your question to Northwind" },
			reply: supportReply,
			next_step_key: "thanks",
		},
		thanks: {
			type: "chat_message",
			text: { en: "Thanks, {{email}}. A team member will reply here or by email." },
			next_step_key: "team",
		},
		team: { type: "hand_to_team" },
	},
});

Rules checked when a flow is saved:

  • a flow has at least one entry and at most one chat entry; every entry’s start_step_key and every next_step_key name a step of this flow, and every step can be reached from an entry;
  • a receiving address belongs to at most one incoming_email entry across the store’s flows (409 SUPPORT_FLOW.ADDRESS_TAKEN), and an entry’s reply_language is a store language;
  • steps that don’t wait (chat_message, send_email) can’t loop without a waiting step between;
  • each {{key}} in a text names a chat_question or collect_email_contact step asked on every path before it;
  • every chat text has the same languages, and a language the flow doesn’t have yet must be one of the store’s; button labels are unique within a choice, at most 500 characters;
  • every send_email, entry reply and collect_email_contact reply is a complete selection of a support_message template whose subject prints {{conversation.subject}} and whose reply-to is one of the store’s addresses. A reply template prints the team’s message (409 SUPPORT.REPLY_TEMPLATE_UNSUITABLE); a send_email, which carries no message, can’t need one (409 SUPPORT_FLOW.EMAIL_TEMPLATE_UNSUITABLE). The starter support_message template serves both;
  • a path from an incoming_email entry never reaches a chat-only step, and a chat reaches a send_email only after a collect_email_contact;
  • at most 100 steps, 20 buttons on a choice, and 64 KiB per text.

A chat entry starts website chats. An incoming_email entry starts each new email to its address, with the entry’s reply_language and reply for everything the flow and the team send back. One flow can have both, sharing its steps. An update replaces the entries and steps in one write and carries the expected_updated_at it read; a key another flow uses is 409 SUPPORT_FLOW.KEY_TAKEN. A conversation keeps the copy of the steps it started with; only new conversations run the edit. A template or an address that a flow or a conversation still names can’t be deleted.

Storefront Chat

POST /v1/storefront/conversations
SDK: arky.support.conversation.start()
GET /v1/storefront/conversations/{conversation_id}
SDK: arky.support.conversation.get()
GET /v1/storefront/conversations/{conversation_id}/messages
SDK: arky.support.conversation.findMessages()
POST /v1/storefront/conversations/{conversation_id}/messages
SDK: arky.support.conversation.sendMessage()
GET /v1/storefront/conversations/{conversation_id}/messages/{message_id}
SDK: arky.support.conversation.getMessage()
import { initialize } from "arky-sdk/storefront";
import { createOrderToken } from "arky-sdk/utils";

const arky = initialize("arky_pk_...", {
	locale: "en",
	createVisitorIdentity: () => ({
		customer_id: crypto.randomUUID(),
		session_id: crypto.randomUUID(),
	}),
	createSessionId: () => crypto.randomUUID(),
	createId: () => crypto.randomUUID(),
	createOrderToken,
});

const started = await arky.support.conversation.start({
	language: "en",
	flow_key: "default",
});

localStorage.setItem("support-chat", started.conversation.id);

const choice = started.messages.findLast((message) => message.type.type === "flow_choice");

const reply = await arky.support.conversation.sendMessage({
	conversation_id: started.conversation.id,
	input: { type: "button", label: "Talk to us" },
	prompt_message_id: choice?.id,
});

Parameters

Name Type Description
id optional string The conversation id (UUID v4). Left out, the SDK takes it from the app's createId and keeps it for a retry.
language required string One of the store's languages, one the flow's chat texts have.
flow_key required string The support flow the chat starts with: one with a chat entry and text in the chat's language. A start without it is refused with `400`.
  • The start returns the conversation and its first messages. A chat belongs to the customer of the session that started it: the SDK starts or resumes the browser’s session first, and every later call needs only the conversation id under that session. There is no separate chat token. A retried start with the same id returns the same conversation; without an id, the same start sent again after a lost answer reuses the kept one.
  • A message input is { type: "button", label }, { type: "text", text } or { type: "email_contact", contact: { email, language } }. At a choice only a shown button counts; at a question the text is the answer, and an email answer must be an email address. A flow_email_contact prompt takes only an email contact, in one of the store’s languages (409 CONVERSATION.LANGUAGE_NOT_SUPPORTED otherwise). Once the team has the chat, text goes to the team.
  • Answers name the prompt they answer. While the chat waits at a choice, a question or an email prompt, prompt_message_id names the prompt message shown. If the chat moved on, the answer is refused with 409 CONVERSATION.STALE_PROMPT: read the conversation again and show the current prompt.
  • Each message carries an id, from the app’s createId unless you pass one. The SDK keeps it with a fingerprint of the message until the answer, so the same input for the same prompt sent again after a lost answer reuses it, and the repeat finds the message instead of adding a second one. A different message gets a new id.
  • A resolved chat takes no more messages (409 CONVERSATION.ENDED): start a new one. A new email from the customer, or a reply from the team, reopens a resolved conversation.
  • findMessages pages from the newest messages back, each page sorted by sequence. Poll the conversation every few seconds to pick up the team’s replies.

The storefront gets the messages a chat may show; staff details and email headers stay in Admin:

type StorefrontConversationMessageType =
	| { type: "customer_chat"; text: string }
	| { type: "received_email"; text: string }
	| { type: "flow_message"; text: string }
	| { type: "flow_choice"; text: string; buttons: string[] }
	| { type: "flow_question"; text: string; input_type: "text" | "email" | "phone" }
	| { type: "flow_email_contact"; text: string }
	| { type: "reply"; text: string };

A flow_choice tells the chat to show only its buttons; a flow_question tells it which field to show; a flow_email_contact asks for the email the team can reply to. A received_email appears only when staff showed it in the chat. The conversation’s state says who has it: flow, waiting_for_team or resolved, and its language is the one the chat runs in.

Email Conversations

Email reaches Arky through the store’s own Resend account: the connection’s domain receives, and Resend hands each received email to Arky through the account’s webhook at Arky’s address. Arky matches the recipient to the store’s address, never by the message’s own headers, and files the email in that store; an address that more than one live store holds sends the email to review:

  • An email that answers one of a conversation’s messages, by its In-Reply-To or References headers (the newest 21 ids), joins that conversation once; a matching subject alone never does. References that match nothing make it new email, and conflicting matches wait in review instead of a guess.
  • New email starts a conversation with its sender as the customer, run by the address’s incoming_email entry: its steps, its reply_language for what goes back, and its reply selection. An empty subject stays empty. Email to an address no entry names waits in review until an entry exists.
  • A flow’s automatic email, an email thread’s acknowledgment or a chat’s send_email step, goes to one address at most once a day per store: a chat then goes on to its next step, and automatic mail is never answered (Auto-Submitted, bulk or list mail, or a mailer daemon); the team gets those.
  • A customer’s email on a resolved conversation, or while its chat waits at a prompt, gives the conversation to the team.
  • Attachments, up to 10 and 20 MiB in all, are stored privately with their message. Staff open them through a link that expires after five minutes. An attachment over the limit, or one Resend still can’t hand over after a day, is left out, and the message lists it by file name and reason (left_out_attachments) so staff can ask for it again.
  • A received email or report Arky couldn’t file stays in the store’s Resend inbox in review: staff with support list it per connection with sdk.notification.resendEvent.find and apply it again or ignore it with resolve.

Admin Conversations

POST /v1/stores/{store_id}/conversations
SDK: sdk.support.conversation.startEmail()
GET /v1/stores/{store_id}/conversations
SDK: sdk.support.conversation.find()
GET /v1/stores/{store_id}/conversations/{conversation_id}
SDK: sdk.support.conversation.get()
GET /v1/stores/{store_id}/conversations/{conversation_id}/messages
SDK: sdk.support.conversation.findMessages()
POST /v1/stores/{store_id}/conversations/{conversation_id}/messages
SDK: sdk.support.conversation.reply()
POST /v1/stores/{store_id}/conversations/{conversation_id}/messages/{message_id}/chat-visibility
SDK: sdk.support.conversation.changeChatVisibility()
POST /v1/stores/{store_id}/conversations/{conversation_id}/reply-email
SDK: sdk.support.conversation.selectReplyEmail()
POST /v1/stores/{store_id}/conversations/{conversation_id}/assign
SDK: sdk.support.conversation.assign()
POST /v1/stores/{store_id}/conversations/{conversation_id}/resolve
SDK: sdk.support.conversation.resolve()
const inbox = await sdk.support.conversation.find({
	store_id: storeId,
	statuses: ["waiting_for_team"],
	limit: 25,
});
const conversation = inbox.items[0];

await sdk.support.conversation.reply({
	store_id: storeId,
	conversation_id: conversation.id,
	id: crypto.randomUUID(),
	expected_updated_at: conversation.updated_at,
	text: "I can help with that.",
	delivery: conversation.type.type === "chat" ? "chat" : "email",
	resolve: false,
});
import type { Email, EpochMilliseconds, SupportStep } from "arky-sdk";

interface Conversation {
	id: string;
	store_id: string;
	customer_id: string;
	assigned_account_id: string | null;
	state:
		| { type: "flow"; step_key: string; flow: ConversationFlow }
		| { type: "waiting_for_team"; flow: ConversationFlow | null }
		| { type: "resolved"; flow: ConversationFlow | null };
	type:
		| { type: "chat"; language: string }
		| { type: "email"; email: ConversationEmail }
		| { type: "chat_and_email"; chat_language: string; email: ConversationEmail };
	next_message_sequence: number;
	created_at: EpochMilliseconds;
	updated_at: EpochMilliseconds;
}

interface ConversationFlow {
	flow_id: string;
	steps: Record<string, SupportStep>;
	answers: Record<string, string>;
	failure: { step_key: string; reason: string; at: EpochMilliseconds } | null;
}

interface ConversationEmail {
	contact: { email: string; language: string };
	subject: string;
	reply: Email;
}
  • find filters by statuses (flow, waiting_for_team, resolved), contact (chat or email), customer_id, assigned_account_id and text.
  • A person’s reply is delivered by chat, email or chat_and_email, and gives the conversation to the team, or resolves it with resolve: true. An email reply goes to the conversation’s email contact with its reply selection, as a support_reply outgoing email; the message shows its send status and delivery report. selectReplyEmail({ expected_reply, reply }) changes that selection, naming the one it read; its template must print the team’s message (409 SUPPORT.REPLY_TEMPLATE_UNSUITABLE), and an email reply on a conversation without email is 409 CONVERSATION.NO_EMAIL.
  • startEmail starts an email thread with a customer: { id, message_id, customer_id, contact, subject, reply } plus its text, with a contact in a store language (409 CONVERSATION.LANGUAGE_NOT_SUPPORTED otherwise) and a nonempty subject. The conversation, its first staff reply and the outgoing email are saved together, it starts with the team, and a retry with the same ids sends nothing twice.
  • changeChatVisibility shows a received email in the conversation’s chat, or hides it again, with { expected_updated_at, visible_in_chat } of that message; a conversation without a chat is 409 CONVERSATION.NO_CHAT, and only a received email can be shown.
  • When a flow step can’t run, such as a selection whose sending address is gone, the team gets the conversation and its state.flow.failure says why.
  • assign({ expected_account_id, account_id }) names the assignee it read and an account with the support permission, or null (409 CONVERSATION.ASSIGNEE_NO_SUPPORT otherwise). Assigning and changing the reply email are refused with 409 GENERAL.CONFLICT only when that value changed since it was read, so a customer’s new message never refuses them, and repeating the value already in place answers the conversation unchanged. Taking a conversation over or resolving it stops nothing already waiting to be sent.
  • When a conversation becomes the team’s turn, because the customer’s email or chat hands it to the team or the customer answers a team reply, the store’s conversation_message_alert email goes to its recipients. Webhooks post conversation.created, conversation.updated and conversation_message.created.
  • Conversations have no delete of their own; they go with their customer or their store.

Notes on a conversation are staff-only:

await sdk.support.conversation.notes.create({
	store_id: storeId,
	conversation_id: conversation.id,
	id: crypto.randomUUID(),
	body: "Customer prefers email.",
});
Note

Every write here carries the id the app picked or the expected_updated_at it read. A retry with the same id returns the existing record; a stale expected_updated_at is refused with 409. See Core Concepts.