{"record":{"id":"26a88810a5d465c7","repo":"microsoft/ailab","slug":"direct-line-secret-not-defined","errorCode":null,"errorMessage":"Direct Line secret not defined.","messagePattern":"Direct Line secret not defined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"GoogleAssistantConnector/GoogleAssistant/DirectLineToActionsOnGoogleLib/index.js","lineNumber":14,"sourceCode":"'use strict';\n//=========================================================\n// Import modules\n//=========================================================\nconst fulfilment = require('./lib/fulfilment');\nconst express = require('express');\nconst bodyParser = require('body-parser');\n\nconst router = express.Router();\n\nlet middelware = (directlineSecret, messagesObj = null) => {\n\n    if (!directlineSecret) {\n        throw new Error('Direct Line secret not defined.');\n    }\n\n    router.use(bodyParser.json());\n    fulfilment(directlineSecret, messagesObj, router);\n\n    return { router };\n};\n\n\nmodule.exports = middelware;","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/microsoft/ailab/blob/89fe2fc62081145ec5408d42059cbcb7c4a033c8/GoogleAssistantConnector/GoogleAssistant/DirectLineToActionsOnGoogleLib/index.js#L1-L24","documentation":"The middelware() factory in the DirectLine-to-Actions-on-Google connector requires a Direct Line secret to proxy conversations between Google Assistant and the Bot Framework Direct Line channel. It throws immediately if the secret argument is falsy (undefined, null, or empty string). This is a fail-fast guard: the library cannot authenticate to Direct Line without the secret, so it refuses to set up the Express router.","triggerScenarios":"Calling middelware() with no argument, with undefined/null, or with an empty string, e.g. middelware(process.env.DIRECT_LINE_SECRET) where that env var is unset.","commonSituations":"Deploying without setting DIRECT_LINE_SECRET in the environment (local run, Azure App Service slot swap missing app settings, docker env file omitted); passing the Bot Framework app ID/password instead of a Direct Line secret; a typo in the env variable name.","solutions":["Set the Direct Line secret environment variable (e.g. DIRECT_LINE_SECRET=<secret from Direct Line channel in Azure Portal>) before starting the app","Pass the secret explicitly as the first argument to middelware(secret) and verify it is non-empty at startup","In Azure hosting, add the value to Application Settings / environment configuration for the deployed instance","Confirm you are using the Direct Line channel secret (from the Direct Line channel blade), not the bot's MicrosoftAppPassword"],"exampleFix":"// before\nconst { router } = middelware(process.env.DIRECT_LINE_SECRET);\n// after\nif (!process.env.DIRECT_LINE_SECRET) {\n  throw new Error('Set DIRECT_LINE_SECRET env var before starting.');\n}\nconst { router } = middelware(process.env.DIRECT_LINE_SECRET);","handlingStrategy":"validation","validationCode":"if (!process.env.DIRECT_LINE_SECRET) {\n  throw new Error('DIRECT_LINE_SECRET env var must be set before calling middelware()');\n}","typeGuard":"function hasDirectLineSecret(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"let mw;\ntry {\n  mw = middelware(process.env.DIRECT_LINE_SECRET);\n} catch (e) {\n  if (e.message.includes('Direct Line secret not defined')) {\n    console.error('Startup config error: set DIRECT_LINE_SECRET');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Validate required secrets at process startup before mounting routes","Use a config schema check (e.g. dotenv-safe or envalid) that fails fast on missing env vars","Keep Direct Line secret distinct from bot appId/password in config naming","Add a smoke test that builds the middleware with test config"],"tags":["nodejs","configuration","directline","startup"],"backgroundTag":"missing-api-key","analyzedSha":"89fe2fc62081145ec5408d42059cbcb7c4a033c8","analyzedAt":"2026-09-13T20:10:53.835Z","contentChangedAt":"2026-09-13T20:10:53.835Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}