Skip to content

Add Chat module for reading publication subscriber chats - #19

Closed
danwagnerco wants to merge 1 commit into
NHagar:masterfrom
danwagnerco:feat/dw/fetch-chats
Closed

Add Chat module for reading publication subscriber chats#19
danwagnerco wants to merge 1 commit into
NHagar:masterfrom
danwagnerco:feat/dw/fetch-chats

Conversation

@danwagnerco

Copy link
Copy Markdown

Introduces Chat, ChatThread, and ChatMessage classes that provide read access to Substack community chat threads and messages. Requires authentication via SubstackAuth.

Features:

  • Chat.get_threads() to list threads in a publication chat
  • ChatThread.get_messages() to read replies within a thread
  • Custom exceptions: ChatAuthenticationRequired, ChatAccessDenied, ChatNotFound, ThreadNotFound

Includes API reference docs, user guide updates, and full test coverage with self-contained fixtures.

Introduces Chat, ChatThread, and ChatMessage classes that provide
read access to Substack community chat threads and messages.
Requires authentication via SubstackAuth.

Features:
- Chat.get_threads() to list threads in a publication chat
- ChatThread.get_messages() to read replies within a thread
- Custom exceptions: ChatAuthenticationRequired, ChatAccessDenied,
  ChatNotFound, ThreadNotFound

Includes API reference docs, user guide updates, and full test
coverage with self-contained fixtures.
@NHagar

NHagar commented Mar 6, 2026

Copy link
Copy Markdown
Owner

Thanks for this contribution! The code is clean and well-structured — the Chat → ChatThread → ChatMessage hierarchy fits nicely with the existing patterns in the library, and the test coverage and documentation are thorough.

A few things I'd like to see addressed before merging:

  1. Unrelated changes should be split out. The .gitattributes file, the .gitignore additions (site/, .claude/, .devcontainer/), and the uv.lock churn (just upload-time metadata additions, no actual dependency changes) add noise to the PR. Could you remove these or submit them separately?
  2. Dead fixture paths in tests. The test fixtures try to load JSON from .claude/v1_community_publications_*.json, but that path is gitignored and not included in the PR. The fallback data works fine, so I'd suggest just removing the file-loading code path to avoid confusion.
  3. Client-side limit is misleading. get_threads(limit=5) fetches all threads from the API and slices locally. Same for get_messages(). This should either pass limit through to the API as a query param, or be clearly documented as client-side truncation of a single page.
  4. publication_id usability. The rest of the library works with subdomain strings, but Chat() requires a numeric publication ID. Would be great to accept a subdomain and resolve it internally, or at minimum document how users can find their publication ID.

amckenna added a commit to amckenna/substack_api that referenced this pull request May 25, 2026
Introduces Chat, ChatThread, and ChatMessage classes providing read
access to Substack community chat threads and messages via authenticated
requests. Addresses all feedback from PR NHagar#19 review.

Changes from original PR:
- Remove unrelated .gitattributes, .gitignore, and uv.lock changes
- Remove dead .claude/ fixture file paths from tests; use inline data only
- Document limit param as client-side truncation in get_threads/get_messages
- Accept subdomain string in Chat() and resolve to numeric ID automatically;
  falls back from the search API to the publication posts endpoint for
  publications not indexed by search
- Add ChatPaymentRequired (subclass of ChatAccessDenied) for 402 responses,
  covering both missing paid subscriptions and insufficient subscription tiers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@NHagar

NHagar commented May 28, 2026

Copy link
Copy Markdown
Owner

Closing in favor of #21

@NHagar NHagar closed this May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants