microsoft/ailab · critical · Error
Direct Line secret not defined.
Error message
Direct Line secret not defined.
What it means
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.
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
Example fix
// before
const { router } = middelware(process.env.DIRECT_LINE_SECRET);
// after
if (!process.env.DIRECT_LINE_SECRET) {
throw new Error('Set DIRECT_LINE_SECRET env var before starting.');
}
const { router } = middelware(process.env.DIRECT_LINE_SECRET); Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.DIRECT_LINE_SECRET) {
throw new Error('DIRECT_LINE_SECRET env var must be set before calling middelware()');
} Type guard
function hasDirectLineSecret(v) {
return typeof v === 'string' && v.length > 0;
} Try / catch
let mw;
try {
mw = middelware(process.env.DIRECT_LINE_SECRET);
} catch (e) {
if (e.message.includes('Direct Line secret not defined')) {
console.error('Startup config error: set DIRECT_LINE_SECRET');
process.exit(1);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
AI-assisted analysis of microsoft/ailab@89fe2fc620 (2026-09-13).
Data as JSON: /api/errors/26a88810a5d465c7.
Report an issue: GitHub.
Appendix: source
Thrown at GoogleAssistantConnector/GoogleAssistant/DirectLineToActionsOnGoogleLib/index.js:14
'use strict';
//=========================================================
// Import modules
//=========================================================
const fulfilment = require('./lib/fulfilment');
const express = require('express');
const bodyParser = require('body-parser');
const router = express.Router();
let middelware = (directlineSecret, messagesObj = null) => {
if (!directlineSecret) {
throw new Error('Direct Line secret not defined.');
}
router.use(bodyParser.json());
fulfilment(directlineSecret, messagesObj, router);
return { router };
};
module.exports = middelware;View on GitHub (pinned to 89fe2fc620)