Skip to content

feat: extract roomId from email text before checking headers#100

Merged
sweetmantech merged 8 commits intotestfrom
sweetmantech/myc-3875-api-email-webhook-before-checking
Jan 8, 2026
Merged

feat: extract roomId from email text before checking headers#100
sweetmantech merged 8 commits intotestfrom
sweetmantech/myc-3875-api-email-webhook-before-checking

Conversation

@sweetmantech
Copy link
Contributor

@sweetmantech sweetmantech commented Jan 8, 2026

Summary

  • Primary check now looks for Recoup chat link in email body text: https://chat.recoupable.com/chat/{uuid}
  • Falls back to references header lookup if not found in text
  • Fixed: Convert stored UI parts to ModelMessage format for AI SDK compatibility

Problem

  1. When a user replies to an email from Recoup, the email footer contains the chat link. We should extract the roomId from this link first, as it's more reliable than the references header.
  2. The stored memories contain UI-specific part types (step-start, dynamic-tool, reasoning with state) that don't match the ModelMessage[] schema the AI SDK expects, causing AI_InvalidPromptError.

Solution

  1. Added extractRoomIdFromText() helper that uses regex to find the UUID from the chat link pattern.
  2. Refactored getEmailRoomMessages() to convert UI parts to simple text-based ModelMessages, extracting only the text content from user and assistant messages.

🤖 Generated with Claude Code

sweetmantech and others added 2 commits January 8, 2026 10:44
Primary check now looks for Recoup chat link in email body text:
https://chat.recoupable.com/chat/{uuid}

Falls back to references header lookup if not found in text.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Jan 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
recoup-api Ready Ready Preview Jan 8, 2026 3:47pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Extract roomId from email text before checking headers
- Convert stored UI parts (step-start, dynamic-tool, reasoning) to
  simple text-based ModelMessages for AI SDK compatibility
- Fixes AI_InvalidPromptError when replying to email threads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename extractText to extractTextFromParts
- Move to lib/emails/inbound/extractTextFromParts.ts
- Add SRP/DRY/KISS principles to CLAUDE.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add comprehensive tests for extractRoomIdFromText covering valid chat links,
  edge cases (undefined, empty string, invalid UUIDs), and wrong domains
- Add tests for getEmailRoomId covering primary text extraction, fallback to
  references header, and various undefined scenarios
- Verify priority: chat link in email text takes precedence over headers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sweetmantech sweetmantech merged commit 6d79478 into test Jan 8, 2026
4 checks passed
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.

1 participant

Comments