How Chatbots Work
Before jumping into the flow editor, it helps to understand how chatbots think and why Sarufi is structured the way it is. This page explains the core concepts you'll encounter while building.
What Is a Chatbot?β
A chatbot is a program that talks to people using text (or voice). You can think of it as a virtual assistant that answers questions, collects information, or guides users through a process automatically.
For example: instead of your team manually answering every customer inquiry on WhatsApp, a chatbot can handle common questions 24/7 - booking appointments, taking orders, providing support - and only pass the conversation to a human when needed.
Sarufi is built specifically for this: it handles the hard parts (understanding language, managing conversation state) so you can focus on what your bot should say and when.
The Building Blocksβ
Every chatbot, at its core, is made of three things:
1. Intentsβ
An intent is what the user wants - the goal behind their message, regardless of how they phrase it.
The same intent can be expressed many different ways:
| User message | Intent |
|---|---|
| "I want to order food" | order_food |
| "Can I place an order?" | order_food |
| "Nataka kuagiza chakula" | order_food |
You teach your bot to recognise an intent by giving it example phrases. Sarufi's NLU (Natural Language Understanding) engine learns from these examples and can match new messages it hasn't seen before.
You don't need to list every possible sentence - just enough varied examples to give the model a clear picture of the intent.
2. Statesβ
A state is a single step in a conversation. When the bot is in a state, it typically:
- Sends a message to the user
- Waits for a response (or moves on automatically)
- Transitions to the next state based on what the user said
Think of states as the steps in a form: "What's your name?" β "How many items?" β "What's your address?" β "Confirm order?" - each question is a state.
A complete flow is a graph of states connected by transitions:
[greet] ββintent: order_foodββ> [ask_quantity] ββalwaysββ> [ask_address] ββalwaysββ> [confirm]
3. Dialog Managementβ
Dialog management is what keeps track of where the user is in a conversation. When the user answers a question, the bot records that response and decides which state to go to next.
Sarufi handles dialog management for you - you just define the states and transitions, and Sarufi makes sure the conversation flows correctly.
How Sarufi Handles Itβ
When a user sends a message, Sarufi does this automatically:
- Intent detection - identifies which intent the message matches
- State lookup - finds the right state for that intent (or the next state in the current flow)
- Response generation - sends the message defined in that state
- Memory - stores the user's response for use in later states
You define the intents, states, and messages. Sarufi handles the rest.
Variables: Referencing Previous Responsesβ
When a user replies to a state, their answer is stored under that state's name. You can embed it in a later message using:
{{state_name}}
Exampleβ
Imagine a flow with these states:
| State | Bot message |
|---|---|
ask_name | "What is your name?" |
ask_quantity | "{{ask_name}}, how many items would you like?" |
confirm | "Got it! I'll order {{ask_quantity}} item(s) for {{ask_name}}." |
If the user types "Amani" at ask_name, then later:
{{ask_name}}β "Amani"- At
confirm, the bot says: "Got it! I'll order 3 item(s) for Amani."
This makes conversations feel personal and contextual rather than generic.
Variables are scoped to the current flow session. {{state_name}} only works within the same flow - it cannot reference responses from a different flow.
The variable name is always the state name (the identifier you give the state, not the message text). Keep state names lowercase with underscores for clarity: ask_phone_number β referenced as {{ask_phone_number}}.
The Special cancel Intentβ
If you create an intent named exactly cancel, it has a special behaviour: if the user triggers it while in the middle of a flow, the conversation is immediately abandoned and the bot responds with the message in your cancel state.
This gives users a natural way to bail out of any multi-step conversation at any point.
What's Nextβ
Now that you understand the concepts, you're ready to start building:
- Conversation Flows - build a flow in the visual editor
- Chatbots - create and configure your first chatbot