hcengineering/platform · error

Accounts URL or token is not defined

Error message

Accounts URL or token is not defined

What it means

getIntegrationClient builds a Telegram integration client using the accounts service URL and the auth token, both read from client metadata (login.metadata.AccountsUrl, presentation.metadata.Token). If either is undefined it throws this error, since it cannot authenticate against the accounts service without them.

Source

Thrown at plugins/telegram-resources/src/api.ts:85

}

export async function listChannels (phone: string): Promise<TelegramChannel[]> {
  return await request('GET', `${phone}/chats`)
}

export async function disconnect (phone: string): Promise<void> {
  await request('DELETE', phone)
}

export async function command (phone: string, command: 'start' | 'next', input?: string): Promise<IntegrationState> {
  return await request('POST', phone, { command, input })
}

export async function getIntegrationClient (): Promise<IntegrationClient> {
  const accountsUrl = getMetadata(login.metadata.AccountsUrl)
  const token = getMetadata(presentation.metadata.Token)
  if (accountsUrl === undefined || token === undefined) {
    throw new Error('Accounts URL or token is not defined')
  }
  return getIntegrationClientRaw(accountsUrl, token, telegramIntegrationKind, 'hulygram')
}

export async function connect (phone: string, socialId: PersonId): Promise<Integration> {
  const client = await getIntegrationClient()
  const connection = await client.connect(socialId, {
    phone
  })
  return await client.integrate(connection, getCurrentWorkspaceUuid())
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Ensure the accounts service URL is present in the server/client configuration so login.metadata.AccountsUrl is set
  2. Ensure the user is logged in and presentation.metadata.Token is injected before calling integration functions
  3. Log both metadata values (without printing the secret token) to see which one is missing
  4. In tests, set both metadata values explicitly before invoking getIntegrationClient

Example fix

// before
const client = await getIntegrationClient() // throws if metadata missing
// after
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
if (accountsUrl === undefined || token === undefined) {
  throw new Error('Telegram integration requires login; ensure accounts URL and token metadata are configured')
}
const client = await getIntegrationClient()
Defensive patterns

Strategy: validation

Validate before calling

const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
if (accountsUrl === undefined || accountsUrl === '' || token === undefined) {
  throw new Error('Telegram integration requires AccountsUrl metadata and an authenticated token')
}

Type guard

function hasTelegramMetadata (): boolean {
  const url = getMetadata(login.metadata.AccountsUrl)
  const token = getMetadata(presentation.metadata.Token)
  return typeof url === 'string' && url.length > 0 && typeof token === 'string'
}

Try / catch

try {
  const client = await getIntegrationClient()
} catch (err) {
  if (err instanceof Error && err.message.includes('Accounts URL or token')) {
    redirectToLogin() // user session or server config is incomplete
    return
  }
  throw err
}

Prevention

When it happens

Trigger: Calling getIntegrationClient/connect (e.g. during Telegram integration setup) in a session where AccountsUrl or Token metadata was not injected — server misconfiguration, or client code running before login/metadata provisioning completed.

Common situations: Self-hosted deployments missing the accounts URL in config; calling integration code from a not-logged-in context so Token metadata is absent; tests without metadata setup.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/4addf84d4cc5dae6. Report an issue: GitHub.