ชุดสนทนา
ชุดสนทนาจัดกลุ่มข้อความที่เกี่ยวข้องเป็นการสนทนา AgentSend จะจัดกลุ่มข้อความโดยอัตโนมัติตาม header อีเมลมาตรฐาน ดังนั้นเอเจนต์ของคุณจะมีบริบททั้งหมดของการสนทนาเสมอ
ภาพรวม
ทุกการสนทนาทางอีเมลใน AgentSend จะถูกจัดระเบียบเป็นชุดสนทนา ชุดสนทนาจะรวบรวมข้อความที่เกี่ยวข้องทั้งหมด — อีเมลต้นฉบับ การตอบกลับทุกครั้ง และการตอบกลับต่อการตอบกลับ — เป็นอ็อบเจ็กต์การสนทนาเดียวที่เรียงลำดับ ซึ่งทำให้เอเจนต์อ่านประวัติทั้งหมดได้ง่ายก่อนที่จะเขียนการตอบกลับ
ชุดสนทนาถูกสร้างโดยอัตโนมัติ เมื่อ AgentSend ได้รับหรือส่งข้อความที่เริ่มการสนทนาใหม่ ชุดสนทนาจะถูกสร้าง เมื่อการตอบกลับมาถึง AgentSend จะจับคู่กับชุดสนทนาที่มีอยู่และเพิ่มข้อความใหม่
ชุดสนทนาถูกกำหนดขอบเขตให้กล่องจดหมาย ห่วงโซ่อีเมลเดียวกันที่ได้รับโดยกล่องจดหมายสองกล่องที่ต่างกันจะสร้างอ็อบเจ็กต์ชุดสนทนาแยกกันสองอัน
วิธีการทำงานของการจัดกลุ่มชุดสนทนา
AgentSend ปฏิบัติตามโมเดลการจัดกลุ่มชุดสนทนาอีเมลมาตรฐานที่ใช้โดยอีเมลไคลเอนต์หลักทุกตัว เมื่อการตอบกลับมาถึง AgentSend จะตรวจสอบ header In-Reply-To และ References เพื่อระบุว่าข้อความเป็นของชุดสนทนาใดที่มีอยู่ หากพบการจับคู่ ข้อความจะถูกเพิ่มในชุดสนทนานั้น หากไม่พบการจับคู่ จะสร้างชุดสนทนาใหม่
คุณยังสามารถเชื่อมโยงข้อความกับชุดสนทนาได้อย่างชัดเจนโดยรวมฟิลด์ threadId เมื่อส่ง สิ่งนี้มีประโยชน์เมื่อคุณเริ่มการติดตามจากฝั่งเอเจนต์และต้องการให้จัดกลุ่มกับการสนทนาก่อนหน้า แม้ว่าผู้รับจะเริ่มห่วงโซ่การตอบกลับใหม่
อ่าน threadId จาก payload ของ webhook ที่เข้ามาและส่งคืนเมื่อตอบกลับเสมอ สิ่งนี้รับประกันการจัดกลุ่มที่ถูกต้องแม้ว่าผู้รับจะเปลี่ยนหัวข้ออีเมล
Matching algorithm
- Check the
In-Reply-Toheader against all known message IDs in the inbox. - If no match, scan the
Referencesheader list from right (most recent) to left. - If still no match, create a new thread for this message.
Thread Properties
อ็อบเจ็กต์ชุดสนทนาแต่ละตัวมีฟิลด์ต่อไปนี้:
| คุณสมบัติ | ประเภท | คำอธิบาย |
|---|---|---|
id |
string | Unique identifier for the thread. |
inboxId |
string | The inbox this thread belongs to. |
subject |
string | Subject line of the first message in the thread. |
messageCount |
integer | Total number of messages in this thread. |
lastMessageAt |
string (ISO 8601) | Timestamp of the most recent message. |
createdAt |
string (ISO 8601) | Timestamp when the thread was first created. |
Listing Threads
เรียกดูชุดสนทนาทั้งหมดของกล่องจดหมายโดยใช้คำขอ GET ผลลัพธ์จะเรียงลำดับตาม lastMessageAt จากมากไปน้อย ดังนั้นการสนทนาที่ใช้งานมากที่สุดจะปรากฏก่อน
// GET /inboxes/{id}/threads?limit=20&offset=0 const res = await fetch( `https://api.agentsend.io/inboxes/${inboxId}/threads?limit=20&offset=0`, { headers: { "x-api-key": process.env.AGENTSEND_API_KEY } } ); const { data, total } = await res.json(); for (const thread of data) { console.log(thread.id, thread.subject, thread.messageCount); }
Query parameters
| พารามิเตอร์ | ประเภท | Default | คำอธิบาย |
|---|---|---|---|
limit |
integer | 20 | Maximum number of threads to return. Max 100. |
offset |
integer | 0 | Number of threads to skip for pagination. |
Getting Thread Messages
ดึงทุกข้อความในชุดสนทนาตามลำดับเวลา สิ่งนี้จะให้ประวัติการสนทนาที่สมบูรณ์แก่เอเจนต์ของคุณเพื่อที่จะเขียนการตอบกลับที่รับรู้บริบทได้
// GET /threads/{id}/messages const res = await fetch( `https://api.agentsend.io/threads/${threadId}/messages`, { headers: { "x-api-key": process.env.AGENTSEND_API_KEY } } ); const { data } = await res.json(); // Build a conversation history for your LLM const history = data.map(msg => ({ role: msg.direction === "outbound" ? "assistant" : "user", content: msg.bodyText, })); console.log(`Loaded ${history.length} messages from thread`);
ข้อความภายในชุดสนทนาจะถูกส่งคืนตามลำดับเวลาจากน้อยไปมาก (sentAt เก่าสุดก่อน) ซึ่งตรงกับลำดับธรรมชาติที่คาดหวังโดย LLM conversation APIs ส่วนใหญ่
Replying in a Thread
ในการสนทนาที่มีอยู่ ให้รวม threadId เมื่อส่งข้อความ AgentSend จะตั้งค่า header In-Reply-To และ References ที่ถูกต้องโดยอัตโนมัติ เพื่อให้การตอบกลับปรากฏในอีเมลไคลเอนต์ของผู้รับเป็นส่วนหนึ่งของการสนทนาเดียวกัน
// POST /inboxes/{id}/messages — reply within an existing thread await fetch(`https://api.agentsend.io/inboxes/${inboxId}/messages`, { method: "POST", headers: { "x-api-key": process.env.AGENTSEND_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ to: ["customer@example.com"], subject: "Re: Your support request", bodyText: "Thanks for reaching out! Here is the information you requested...", threadId: "thrd_abc123", // ties this message to the existing conversation }), });
หากคุณละเว้น threadId ข้อความขาออกจะเริ่มชุดสนทนาใหม่แม้ว่าคุณจะใช้หัวข้อเดียวกัน ส่ง threadId เสมอเมื่อดำเนินการสนทนาต่อ
Use Cases
ชุดสนทนาเปิดใช้งานเวิร์กโฟลว์ชุดหนึ่งที่ต้องการความจำข้ามการแลกเปลี่ยนอีเมลหลายครั้ง
- Customer support — Load the full thread before generating a reply so your support agent has all prior context. Assign threads to human agents only when needed.
- Sales follow-ups — Track multi-touch outreach sequences. Know when a prospect last replied and how many messages are in a chain before escalating.
- Scheduling & coordination — Run back-and-forth negotiations (meeting times, contract terms) inside a single thread so the conversation history is always accessible.
- Research collection — Send an initial query, collect responses, and follow up with clarifying questions — all within one organized thread per contact.