{"record":{"id":"4addf84d4cc5dae6","repo":"hcengineering/platform","slug":"accounts-url-or-token-is-not-defined-4addf8","errorCode":null,"errorMessage":"Accounts URL or token is not defined","messagePattern":"Accounts URL or token is not defined","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/telegram-resources/src/api.ts","lineNumber":85,"sourceCode":"}\n\nexport async function listChannels (phone: string): Promise<TelegramChannel[]> {\n  return await request('GET', `${phone}/chats`)\n}\n\nexport async function disconnect (phone: string): Promise<void> {\n  await request('DELETE', phone)\n}\n\nexport async function command (phone: string, command: 'start' | 'next', input?: string): Promise<IntegrationState> {\n  return await request('POST', phone, { command, input })\n}\n\nexport async function getIntegrationClient (): Promise<IntegrationClient> {\n  const accountsUrl = getMetadata(login.metadata.AccountsUrl)\n  const token = getMetadata(presentation.metadata.Token)\n  if (accountsUrl === undefined || token === undefined) {\n    throw new Error('Accounts URL or token is not defined')\n  }\n  return getIntegrationClientRaw(accountsUrl, token, telegramIntegrationKind, 'hulygram')\n}\n\nexport async function connect (phone: string, socialId: PersonId): Promise<Integration> {\n  const client = await getIntegrationClient()\n  const connection = await client.connect(socialId, {\n    phone\n  })\n  return await client.integrate(connection, getCurrentWorkspaceUuid())\n}\n","sourceCodeStart":67,"sourceCodeEnd":97,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/telegram-resources/src/api.ts#L67-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the accounts service URL is present in the server/client configuration so login.metadata.AccountsUrl is set","Ensure the user is logged in and presentation.metadata.Token is injected before calling integration functions","Log both metadata values (without printing the secret token) to see which one is missing","In tests, set both metadata values explicitly before invoking getIntegrationClient"],"exampleFix":"// before\nconst client = await getIntegrationClient() // throws if metadata missing\n// after\nconst accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || token === undefined) {\n  throw new Error('Telegram integration requires login; ensure accounts URL and token metadata are configured')\n}\nconst client = await getIntegrationClient()","handlingStrategy":"validation","validationCode":"const accountsUrl = getMetadata(login.metadata.AccountsUrl)\nconst token = getMetadata(presentation.metadata.Token)\nif (accountsUrl === undefined || accountsUrl === '' || token === undefined) {\n  throw new Error('Telegram integration requires AccountsUrl metadata and an authenticated token')\n}","typeGuard":"function hasTelegramMetadata (): boolean {\n  const url = getMetadata(login.metadata.AccountsUrl)\n  const token = getMetadata(presentation.metadata.Token)\n  return typeof url === 'string' && url.length > 0 && typeof token === 'string'\n}","tryCatchPattern":"try {\n  const client = await getIntegrationClient()\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Accounts URL or token')) {\n    redirectToLogin() // user session or server config is incomplete\n    return\n  }\n  throw err\n}","preventionTips":["Require login before exposing Telegram integration UI actions","Validate accounts service config at deployment startup","Gate test suites on explicit metadata setup for login/presentation"],"tags":["configuration","missing-metadata","telegram"],"backgroundTag":"missing-env-var","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}