Skip to content

feat(ai-bot): make bot account email configurable via AI_BOT_EMAIL env var#10672

Open
dnplkndll wants to merge 2 commits intohcengineering:developfrom
ledoent:feat/configurable-aibot-email
Open

feat(ai-bot): make bot account email configurable via AI_BOT_EMAIL env var#10672
dnplkndll wants to merge 2 commits intohcengineering:developfrom
ledoent:feat/configurable-aibot-email

Conversation

@dnplkndll
Copy link
Contributor

Summary

Makes the AI bot account email configurable via AI_BOT_EMAIL env var instead of hardcoded to huly.ai.bot@hc.engineering.

Resolves hcengineering/huly-selfhost#239

Motivation

The bot email huly.ai.bot@hc.engineering is an @hc.engineering address embedded in every self-hosted deployment's account system. Self-hosters have no control over this domain, and it can cause bounce-back noise if an external SMTP notification service attempts to email all workspace members.

Design

  • setAiBotAccountEmail() / getAiBotAccountEmail() on @hcengineering/ai-bot — mutable at startup, defaults to original email
  • getAiBotEmailSocialKey() — derives social key from configured email at call time
  • Original aiBotAccountEmail and aiBotEmailSocialKey constants kept for client-side code
  • Client plugin unchanged — queries by default constant (bot retains original social identity)

Env vars

Service Var Default Required
ai-bot AI_BOT_EMAIL huly.ai.bot@hc.engineering No
transactor AI_BOT_EMAIL huly.ai.bot@hc.engineering No

Both must use the same value if set.

Changes (12 files)

File Change
plugins/ai-bot/src/index.ts Add get/setAiBotAccountEmail(), getAiBotEmailSocialKey()
services/ai-bot/pod-ai-bot/src/config.ts Add Email from AI_BOT_EMAIL (imports default from plugin)
services/ai-bot/pod-ai-bot/src/start.ts Call setAiBotAccountEmail(config.Email) on startup
services/ai-bot/pod-ai-bot/src/utils/account.ts Use getter functions
services/ai-bot/pod-ai-bot/src/utils/platform.ts Use getter functions
pods/server/src/__start.ts Read AI_BOT_EMAIL, call setAiBotAccountEmail()
foundations/server/packages/middleware/src/identity.ts Import from @hcengineering/ai-bot (was duplicate hardcoded string)
foundations/server/packages/middleware/src/pluginConfig.ts Use getter function
server-plugins/ai-bot-resources/src/index.ts Use getter function
**/package.json + pnpm-lock.yaml Add @hcengineering/ai-bot dependency

Not changed: plugins/ai-bot-resources/src/utils.ts (client-side, correctly uses constant), models/contact/src/migration.ts and dev/tool/src/db.ts (hardcoded strings reference historical data).

Testing

Deployed to self-hosted K8s cluster with AI_BOT_EMAIL=aibot@ledoweb.com:

  • ai-bot: 0 restarts, registers new social identity in CockroachDB
  • Original identity preserved (backwards compat)
  • DM with Huly AI works — bot receives and responds
  • Default behavior (no env var) unchanged

🤖 Generated with Claude Code

…v var

The AI bot email was hardcoded to huly.ai.bot@hc.engineering, causing
self-hosted deployments to send notifications to an unreachable address.

Add AI_BOT_EMAIL env var to the ai-bot service and transactor:
- ai-bot service: reads AI_BOT_EMAIL, calls setAiBotAccountEmail() on
  startup, uses it for signUp/assignWorkspace/identity lookups
- transactor: reads AI_BOT_EMAIL, calls setAiBotAccountEmail() so
  middleware recognizes the bot as a service account
- server plugin triggers: use getAiBotEmailSocialKey() for DB queries
- middleware: import from @hcengineering/ai-bot instead of duplicating
  the hardcoded string
- client plugin unchanged: queries by the default constant, which still
  works because the bot retains its original social identity

Defaults to huly.ai.bot@hc.engineering when unset (no behavior change).

Tested on self-hosted K8s: bot registers new social identity, DMs work,
0 restarts on both services.

Resolves hcengineering/huly-selfhost#239

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Don Kendall <kendall@donkendall.com>
@huly-github-staging
Copy link

Connected to Huly®: UBERF-16033

@dnplkndll
Copy link
Contributor Author

Alternative approach: Since no actual email is ever sent to or from this address (it's purely an account identity key), a simpler fix would be to just change the hardcoded default from huly.ai.bot@hc.engineering to something domain-neutral like ai-bot@huly — no env var needed.

The reason I went with the configurable approach is backwards compatibility: existing deployments already have the bot registered with huly.ai.bot@hc.engineering in their social_id table. Changing the constant would require a migration to update the social identity, otherwise the bot would create a duplicate account on next startup.

If a migration is acceptable, the simpler rename would be a ~5-line change. Happy to pivot to that approach if preferred.

setMetadata(serverNotification.metadata.MailAuthToken, config.mailAuthToken)
setMetadata(serverNotification.metadata.WebPushUrl, config.webPushUrl)
setMetadata(serverAiBot.metadata.EndpointURL, process.env.AI_BOT_URL)
if (process.env.AI_BOT_EMAIL !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is idiomaic to use metadata for such kind of configuration, i.e. something like:

setMetadata(serverAiBot.metadata.Email, process.env.AI_BOT_EMAIL)

and in the ai-bot plugin:

export function getAiBotEmailSocialKey (): string {
  return buildSocialIdString({
    type: SocialIdType.EMAIL,
    value:getMetadata(...) ?? aiBotAccountEmail
  })
}

Copy link
Member

@aonnikov aonnikov Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't think it has to be a email, ideally that should be a separate SocialIdType, but this is something that requires larger refactoring.

- Flutter mobile app with auth (OTP, password, OAuth), issue tracking
- Huly design system tokens and shared widgets (HulyButton, HulyChip, PriorityIcon)
- OAuth via ASWebAuthenticationSession (flutter_web_auth_2) with huly:// custom scheme
- Server-side mobileRedirect support in authProviders for custom scheme redirect
- TestFlight ExportOptions.plist, version 0.2.0+2

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Don Kendall <kendall@donkendall.com>
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.

Allow aibot email to be changed

2 participants