Skip to content

Commit 9ca59f8

Browse files
authored
feat(chat/session-management): new doc added (#452)
1 parent e7c5830 commit 9ca59f8

File tree

5 files changed

+262
-97
lines changed

5 files changed

+262
-97
lines changed

fern/chat/non-streaming.mdx

Lines changed: 12 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ Build a chat integration that receives complete responses after processing, perf
1010

1111
**What You'll Build:**
1212
* Simple request-response chat patterns with immediate complete responses
13-
* Session-based conversations that maintain context across multiple chats
13+
* Context management using `previousChatId` for linked conversations
1414
* Basic integration with predictable response timing
1515

16+
<Note>
17+
For comprehensive context management options including sessions, see **[Session management](/chat/session-management)**.
18+
</Note>
19+
1620
## Prerequisites
1721

1822
* Completed [Chat quickstart](/chat/quickstart) tutorial
@@ -21,7 +25,7 @@ Build a chat integration that receives complete responses after processing, perf
2125

2226
## Scenario
2327

24-
We'll build a help desk system for "TechFlow" that processes support messages through text chat and maintains conversation history using sessions.
28+
We'll build a help desk system for "TechFlow" that processes support messages through text chat and maintains conversation history using `previousChatId`.
2529

2630
---
2731

@@ -101,103 +105,13 @@ We'll build a help desk system for "TechFlow" that processes support messages th
101105

102106
---
103107

104-
## 2. Context Management with Sessions
105-
106-
<Steps>
107-
<Step title="Create a session for persistent context">
108-
Sessions allow multiple chats to share the same conversation context:
109-
110-
```bash title="Create Session"
111-
curl -X POST https://api.vapi.ai/session \
112-
-H "Authorization: Bearer YOUR_API_KEY" \
113-
-H "Content-Type: application/json" \
114-
-d '{
115-
"assistantId": "your-assistant-id"
116-
}'
117-
```
118-
</Step>
119-
<Step title="Use the session across multiple chats">
120-
Once you have a session ID, use it for related conversations:
121-
122-
```bash title="First Message with Session"
123-
curl -X POST https://api.vapi.ai/chat \
124-
-H "Authorization: Bearer YOUR_API_KEY" \
125-
-H "Content-Type: application/json" \
126-
-d '{
127-
"sessionId": "session_abc123",
128-
"input": "My account is locked and I can't access the dashboard"
129-
}'
130-
```
131-
132-
```bash title="Follow-up in Same Session"
133-
curl -X POST https://api.vapi.ai/chat \
134-
-H "Authorization: Bearer YOUR_API_KEY" \
135-
-H "Content-Type: application/json" \
136-
-d '{
137-
"sessionId": "session_abc123",
138-
"input": "I tried the suggestions but still can't get in"
139-
}'
140-
```
141-
</Step>
142-
<Step title="Implement session management in TypeScript">
143-
Build a session-aware chat manager:
144-
145-
```typescript title="session-manager.ts"
146-
async function createChatSession(assistantId: string): Promise<string> {
147-
const response = await fetch('https://api.vapi.ai/session', {
148-
method: 'POST',
149-
headers: {
150-
'Authorization': 'Bearer YOUR_API_KEY',
151-
'Content-Type': 'application/json'
152-
},
153-
body: JSON.stringify({ assistantId })
154-
});
155-
156-
const session = await response.json();
157-
return session.id;
158-
}
159-
160-
async function sendSessionMessage(
161-
sessionId: string,
162-
message: string
163-
): Promise<string> {
164-
const response = await fetch('https://api.vapi.ai/chat', {
165-
method: 'POST',
166-
headers: {
167-
'Authorization': 'Bearer YOUR_API_KEY',
168-
'Content-Type': 'application/json'
169-
},
170-
body: JSON.stringify({
171-
sessionId: sessionId,
172-
input: message
173-
})
174-
});
175-
176-
const chat = await response.json();
177-
return chat.output[0].content;
178-
}
179-
180-
// Usage example
181-
const sessionId = await createChatSession('your-assistant-id');
182-
183-
const response1 = await sendSessionMessage(sessionId, "I need help with billing");
184-
console.log('Response 1:', response1);
185-
186-
const response2 = await sendSessionMessage(sessionId, "Can you explain the charges?");
187-
console.log('Response 2:', response2); // Will remember the billing context
188-
```
189-
</Step>
190-
</Steps>
191-
192-
---
193-
194-
## 3. Using previousChatId for Context
108+
## 2. Context Management with previousChatId
195109

196110
<Steps>
197-
<Step title="Link chats without sessions">
198-
Alternative to sessions - link chats directly:
111+
<Step title="Link chats for conversation context">
112+
Use `previousChatId` to maintain context across multiple chats:
199113

200-
```typescript title="previous-chat-context.ts"
114+
```typescript title="conversation-chain.ts"
201115
async function createConversation() {
202116
let lastChatId: string | undefined;
203117

@@ -237,7 +151,7 @@ We'll build a help desk system for "TechFlow" that processes support messages th
237151

238152
---
239153

240-
## 4. Custom Assistant Configuration
154+
## 3. Custom Assistant Configuration
241155

242156
<Steps>
243157
<Step title="Use inline assistant configuration">
@@ -319,6 +233,7 @@ Enhance your non-streaming chat system further:
319233
* **[Add streaming capabilities](/chat/streaming)** - Upgrade to real-time responses for better UX
320234
* **[OpenAI compatibility](/chat/openai-compatibility)** - Use familiar OpenAI SDK patterns
321235
* **[Integrate tools](/tools)** - Enable your assistant to call external APIs and databases
236+
* **[Session management](/chat/session-management)** - Learn about advanced context management with sessions
322237
* **[Add voice capabilities](/calls/outbound-calling)** - Extend your text chat to voice interactions
323238

324239
<Callout>

fern/chat/quickstart.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Take your chat bot to the next level:
273273

274274
* **[Streaming responses](/chat/streaming)** - Add real-time typing indicators and progressive responses
275275
* **[Non-streaming responses](/chat/non-streaming)** - Learn about sessions and complex conversation flows
276+
* **[Session management](/chat/session-management)** - Learn advanced context management with sessions and previousChatId
276277
* **[OpenAI compatibility](/chat/openai-compatibility)** - Integrate with existing OpenAI workflows
277278

278279
<Callout>

0 commit comments

Comments
 (0)