Skip to content

Commit c6510c0

Browse files
committed
Add API integration and template syntax documentation
Document the new template engine features for conversation flows: - API integration with response mapping - Template syntax for variables, conditionals, and loops - Example portfolio message template
1 parent 2663d8c commit c6510c0

File tree

1 file changed

+100
-1
lines changed

1 file changed

+100
-1
lines changed

docs/src/content/docs/features/chatbot.mdx

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,111 @@ The visual flow builder allows you to:
195195
| **Input Validation** | Validate user responses with regex patterns |
196196
| **Variable Storage** | Store user inputs for later use in the conversation |
197197
| **Conditional Logic** | Branch based on user responses |
198-
| **API Integration** | Fetch data from external APIs during the flow |
198+
| **API Integration** | Fetch data from external APIs with response mapping |
199+
| **Template Engine** | Format messages with variables, conditionals, and loops |
199200
| **Webhook Headers** | Configure custom headers for API calls and completion webhooks |
200201
| **Agent Transfer** | Transfer to human agent when needed |
201202
| **WhatsApp Flows** | Integrate native WhatsApp Flows |
202203
| **Drag & Drop Ordering** | Reorder steps by dragging them to new positions |
203204

205+
### API Integration
206+
207+
The "Fetch from API" step type allows you to call external APIs and use the response data in your messages.
208+
209+
#### Configuring an API Step
210+
211+
<Steps>
212+
213+
1. **Set API URL and Method**
214+
215+
Enter the API endpoint URL and select the HTTP method (GET, POST, PUT, PATCH).
216+
Use `{{variable}}` syntax to include session data in the URL.
217+
218+
2. **Add Headers (Optional)**
219+
220+
Configure custom headers like Authorization tokens or API keys.
221+
222+
3. **Configure Request Body (POST/PUT/PATCH)**
223+
224+
Enter JSON body with variables: `{"phone": "{{phone_number}}", "name": "{{name}}"}`
225+
226+
4. **Set Response Mapping**
227+
228+
Map API response fields to session variables for use in templates:
229+
- `name` = `data.client.name`
230+
- `positions` = `data.portfolio.items`
231+
- `total_pnl` = `data.summary.pnl`
232+
233+
5. **Write Message Template**
234+
235+
Use the template syntax to format the API response data.
236+
237+
</Steps>
238+
239+
### Template Syntax
240+
241+
The template engine supports variables, conditionals, and loops for dynamic message formatting.
242+
243+
#### Variables
244+
245+
Access session data and API response fields:
246+
247+
```
248+
{{name}} Simple variable
249+
{{user.profile.name}} Nested path
250+
{{items[0].name}} Array index access
251+
```
252+
253+
#### Conditionals
254+
255+
Show different content based on conditions:
256+
257+
```
258+
{{if is_premium}}
259+
Welcome, premium member!
260+
{{else}}
261+
Upgrade to premium for more features.
262+
{{endif}}
263+
```
264+
265+
Supported operators:
266+
- `{{if variable}}` - Truthy check (non-empty, non-zero)
267+
- `{{if amount > 100}}` - Greater than
268+
- `{{if amount < 100}}` - Less than
269+
- `{{if amount >= 100}}` - Greater than or equal
270+
- `{{if amount <= 100}}` - Less than or equal
271+
- `{{if status == 'active'}}` - String equality
272+
- `{{if status != 'inactive'}}` - String inequality
273+
274+
#### Loops
275+
276+
Iterate over arrays from API responses:
277+
278+
```
279+
{{for item in items}}
280+
- {{item.name}}: {{item.quantity}} @ ₹{{item.price}}
281+
{{endfor}}
282+
```
283+
284+
#### Example: Portfolio Message
285+
286+
```
287+
Hi {{name}}, here are your positions:
288+
289+
{{for pos in positions}}
290+
📊 {{pos.symbol}}: {{pos.qty}} @ ₹{{pos.avg_price}}
291+
{{if pos.is_loss}} ⚠️ Loss: ₹{{pos.loss}}
292+
{{else}} ✅ Profit: ₹{{pos.profit}}
293+
{{endif}}
294+
{{endfor}}
295+
296+
Total P&L: {{if total_negative}}🔴{{else}}🟢{{endif}} ₹{{total_pnl}}
297+
```
298+
299+
<Aside type="tip">
300+
Variables set via response mapping are stored in the session and available in all subsequent steps, not just the current API fetch step.
301+
</Aside>
302+
204303
## Agent Transfers
205304

206305
Hand off conversations from the chatbot to human agents when needed.

0 commit comments

Comments
 (0)