Problem Statement
The Chat SDK assumes one bot identity and one credential set per process. In a SaaS product, each customer connects their own Telegram bot, SMS number, or WhatsApp sender. We need many isolated bot runtimes on shared webhook routes without running one process per connection.
Proposed Solution
Add a built-in multi-tenant mode (or official helper) that:
- Resolves a connection from platform + connectionKey on each webhook
- Lazily creates a Chat instance per connection with its own adapter credentials
- Prefixes shared state keys so thread/subscription state does not collide
- Exposes connection context in message handlers (e.g. via AsyncLocalStorage)
- Caches runtimes with LRU eviction
Handlers would receive (ctx, thread, message) where ctx.connection identifies the tenant.
Alternatives Considered
- One global Chat and swap credentials per request: not safe for concurrent webhooks
- One Chat singleton per connection: too much memory at scale
- External wrapper package: works today, but belongs in the SDK long term
We ship option 3 as @delphi-ai/multi-tenant-chat until upstream support exists.
Use Case
Priority
Critical
Contribution
Additional Context
We already built and use this pattern. Reference implementation: https://github.com/delphi-ai/multi-tenant-chat.
Problem Statement
The Chat SDK assumes one bot identity and one credential set per process. In a SaaS product, each customer connects their own Telegram bot, SMS number, or WhatsApp sender. We need many isolated bot runtimes on shared webhook routes without running one process per connection.
Proposed Solution
Add a built-in multi-tenant mode (or official helper) that:
Handlers would receive (ctx, thread, message) where ctx.connection identifies the tenant.
Alternatives Considered
We ship option 3 as @delphi-ai/multi-tenant-chat until upstream support exists.
Use Case
Priority
Critical
Contribution
Additional Context
We already built and use this pattern. Reference implementation: https://github.com/delphi-ai/multi-tenant-chat.