feat: add folder_name to Developer API and conversation webhook#6019
feat: add folder_name to Developer API and conversation webhook#6019syou6162 wants to merge 7 commits intoBasedHardware:mainfrom
Conversation
Add folder_name field to the GET /v1/dev/user/conversations, GET
/v1/dev/user/conversations/{id}, and PATCH /v1/dev/user/conversations/{id}
endpoints, and to the conversation_created webhook payload.
The folder_name is resolved from the user's folder settings via folder_id.
This avoids N+1 queries by fetching all folders in a single call for the
list endpoint, and uses a single get_folder lookup for the webhook.
Relates to the pattern established in BasedHardware#3962 for speaker_name enrichment.
…mple Add folder_id and folder_name fields to the response examples in the conversations API documentation (both with and without transcript variants), and add corresponding rows to the Response Fields table.
Add folder_id and folder_name fields to the conversation_created webhook payload example in the Integration Apps documentation.
|
do we have any tests? @syou6162 |
Greptile SummaryThis PR adds Confidence Score: 4/5Safe to merge after fixing the None guard in update_conversation_endpoint; all other changes are clean One targeted P1 fix remains: the missing None guard in update_conversation_endpoint before calling _add_folder_names_to_conversations. The fix is a single-line if-guard. Everything else — the batch helper, the webhook helper, the model changes, and docs — is correct and well-tested. backend/routers/developer.py — specifically the update_conversation_endpoint around line 1092 Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant DevRouter as developer.py
participant ConvDB as conversations_db
participant FoldersDB as folders_db
Client->>DevRouter: GET /v1/dev/user/conversations
DevRouter->>ConvDB: get_conversations(uid, ...)
ConvDB-->>DevRouter: [conv1, conv2, ...]
DevRouter->>FoldersDB: get_folders(uid) [single batch call]
FoldersDB-->>DevRouter: [{id, name}, ...]
Note over DevRouter: Build folder_map, enrich each conv with folder_name
DevRouter-->>Client: [{..., folder_id, folder_name}, ...]
Client->>DevRouter: PATCH /v1/dev/user/conversations/{id}
DevRouter->>ConvDB: get_conversation(uid, id) [existence check]
ConvDB-->>DevRouter: conv
DevRouter->>ConvDB: update_conversation / set_discarded
DevRouter->>ConvDB: get_conversation(uid, id) [re-fetch]
ConvDB-->>DevRouter: conv (or None on race condition ⚠️)
DevRouter->>FoldersDB: get_folders(uid)
FoldersDB-->>DevRouter: [{id, name}, ...]
DevRouter-->>Client: {..., folder_id, folder_name}
Note over DevRouter,FoldersDB: Webhook path uses get_folder(uid, folder_id) — single lookup
Reviews (1): Last reviewed commit: "style: fix black formatting in test file" | Re-trigger Greptile |
Prevent AttributeError when the conversation is deleted between the update and re-fetch calls in update_conversation_endpoint.
|
@beastoin Sorry about that. Added test cases in
|
Summary
Add
folder_nameto the Developer API conversation endpoints and theconversation_createdwebhook payload. This allows webhook consumers and API users to directly identify which folder a conversation belongs to, without needing to maintain a separatefolder_id→folder_namemapping.Background
Currently, the webhook payload and API responses include
folder_idbut notfolder_name. Users who want to process conversations by folder via webhooks (e.g., rule-based routing) must separately look up folder names. Since folders are user-created and well-suited for rule-based filtering (unlike AI-generatedcategory), includingfolder_namedirectly improves the developer experience.This follows the same pattern established in #3962 for adding
speaker_nameto the Developer API and webhook.Changes
Backend
backend/routers/developer.pyfolder_idandfolder_namefields to theConversationPydantic response model_add_folder_names_to_conversations(uid, conversations)helper that batch-fetches all user folders in a single query (N+1 avoidance)GET /v1/dev/user/conversations,GET /v1/dev/user/conversations/{id}, andPATCH /v1/dev/user/conversations/{id}backend/utils/webhooks.py_add_folder_name_to_payload(uid, payload)helper that resolvesfolder_namefromfolder_idconversation_created_webhookTests
backend/tests/unit/test_folder_name_enrichment.py: Unit tests for both_add_folder_names_to_conversationsand_add_folder_name_to_payload(10 test cases covering normal, edge, and N+1 avoidance scenarios)Documentation
docs/doc/developer/api/conversations.mdx: Addedfolder_idandfolder_nameto response examples and Response Fields tabledocs/doc/developer/apps/Integrations.mdx: Addedfolder_idandfolder_nameto webhook payload exampleRelated
speaker_nameaddition)