{"record":{"id":"af551bf970777811","repo":"Budibase/budibase","slug":"channel-provider-is-required","errorCode":null,"errorMessage":"channel.provider is required","messagePattern":"channel\\.provider is required","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/chatConversations.ts","lineNumber":470,"sourceCode":"\nexport async function webhookChat({\n  chat,\n  user,\n  onAssistantStream,\n}: {\n  chat: ChatConversationRequest\n  user: ContextUser\n  onAssistantStream?: (stream: WebhookAssistantStream) => Promise<void>\n}): Promise<WebhookChatCompleteResult> {\n  const agentId = chat.agentId\n  if (!agentId) {\n    throw new HTTPError(\"agentId is required\", 400)\n  }\n\n  const agent = await sdk.ai.agents.getOrThrow(agentId)\n  const provider = chat.channel?.provider\n  if (!provider) {\n    throw new HTTPError(\"channel.provider is required\", 400)\n  }\n  const chatId = chat._id ?? docIds.generateChatConversationID()\n  const sessionId = `${provider}:${chatId}`\n  let trackingHandle: AgentRequestTrackingHandle\n  const run = await prepareAgentChatRun({\n    agent,\n    agentId,\n    chat,\n    errorLabel: \"webhook chat\",\n    sessionId,\n    user,\n    getRequestId: () => trackingHandle?.requestId,\n  })\n  const title = run.latestQuestion\n    ? truncateTitle(run.latestQuestion)\n    : chat.title\n\n  const userId = user.globalId || user.userId || user._id || \"\"","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/chatConversations.ts#L452-L488","documentation":"webhookChat requires chat.channel.provider to identify which external channel (Slack, MS Teams, etc.) the message arrived on; it is used to build the session id (`${provider}:${chatId}`) and tracking. If channel or channel.provider is absent the request is rejected with HTTP 400 after agent validation.","triggerScenarios":"An inbound webhook payload missing the channel object, or containing channel without a provider field — e.g. calling webhookChat directly with only { _id, agentId }, or an integration that builds the channel metadata incompletely.","commonSituations":"Custom webhook integrations that don't mimic the official Slack/Teams payload shape; a provider enum value not set when constructing the ChatConversationRequest; refactored integration code dropping the channel field; provider values removed/renamed in a version change.","solutions":["Include channel: { provider: AgentChannelProvider.<SLACK|MSTEAMS|...> } in the chat payload","Fix the channel integration so it populates provider when constructing webhook chat requests","Confirm the provider value matches a valid AgentChannelProvider enum member","Inspect the inbound webhook body to ensure the provider field is not stripped by middleware"],"exampleFix":"// before\nawait webhookChat({ chat: { agentId, _id: chatId }, user })\n// after\nawait webhookChat({ chat: { agentId, _id: chatId, channel: { provider: AgentChannelProvider.SLACK } }, user })","handlingStrategy":"validation","validationCode":"if (!chat.channel?.provider) throw new Error(\"chat.channel.provider must be set for webhook chat\")","typeGuard":"function hasChannelProvider(chat: ChatConversationRequest): chat is ChatConversationRequest & { channel: { provider: AgentChannelProvider } } {\n  return !!chat.channel && typeof chat.channel.provider === \"string\"\n}","tryCatchPattern":"try {\n  await webhookChat({ chat, user })\n} catch (e) {\n  if (e instanceof HTTPError && e.status === 400 && e.message === \"channel.provider is required\") {\n    // inspect integration payload construction\n  }\n  throw e\n}","preventionTips":["Build webhook chat requests via a shared factory that sets channel.provider from the integration type","Validate AgentChannelProvider enum values before sending","Add integration-level tests asserting the payload includes channel.provider","Keep the payload shape in sync when channel metadata changes"],"tags":["validation","webhook","chat-channel"],"backgroundTag":"missing-required-field","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}