{"record":{"id":"a071d12540763eae","repo":"koala73/worldmonitor","slug":"chatid-required-for-telegram-channel","errorCode":null,"errorMessage":"chatId required for telegram channel","messagePattern":"chatId required for telegram channel","errorType":"exception","errorClass":"ConvexError","httpStatus":null,"severity":"error","filePath":"convex/notificationChannels.ts","lineNumber":524,"sourceCode":"});\n\nexport const setChannel = mutation({\n  args: {\n    channelType: channelTypeValidator,\n    chatId: v.optional(v.string()),\n    webhookEnvelope: v.optional(v.string()),\n    email: v.optional(v.string()),\n    webhookLabel: v.optional(v.string()),\n  },\n  handler: async (ctx, args) => {\n    const identity = await ctx.auth.getUserIdentity();\n    if (!identity) throw new ConvexError(\"UNAUTHENTICATED\");\n    const userId = identity.subject;\n    await assertProEntitlement(ctx, userId);\n\n    const existing = await ctx.db\n      .query(\"notificationChannels\")\n      .withIndex(\"by_user_channel\", (q) =>\n        q.eq(\"userId\", userId).eq(\"channelType\", args.channelType),\n      )\n      .unique();\n\n    const now = Date.now();\n\n    if (args.channelType === \"telegram\") {\n      throw new ConvexError(\"telegram channel must be linked through bot pairing\");\n    } else if (args.channelType === \"slack\") {\n      if (!args.webhookEnvelope) throw new ConvexError(\"webhookEnvelope required for slack channel\");\n      const doc = { userId, channelType: \"slack\" as const, webhookEnvelope: args.webhookEnvelope, verified: true, linkedAt: now };\n      if (existing) {\n        await ctx.db.replace(existing._id, doc);\n      } else {\n        await ctx.db.insert(\"notificationChannels\", doc);\n      }\n    } else if (args.channelType === \"email\") {\n      const email = requireVerifiedAccountEmail(args.email, identity.emailVerified === true ? identity.email : undefined);","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/koala73/worldmonitor/blob/e586b8b4b80f595aa7ece295eec10d76f2921240/convex/notificationChannels.ts#L506-L542","documentation":"Channel-shape validation in setChannel: channelType is 'telegram' but args.chatId is missing. Telegram channels store the chat id as their payload, so the channel document cannot be constructed without it.","triggerScenarios":"Thrown at convex/notificationChannels.ts:493 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Collect the Telegram chat id (e.g. via the bot pairing flow) before saving the channel","Require the chatId field in the UI when telegram is the selected channel type"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e586b8b4b80f595aa7ece295eec10d76f2921240","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}