Bot Framework Adaptive Dialogs Runtime Core
The `botbuilder-dialogs-adaptive-runtime-core` package provides the foundational, core components for building and running adaptive dialogs within the Microsoft Bot Framework SDK for JavaScript. As of version 4.23.3, it offers classes and interfaces like `ServiceCollection` and `Configuration` that enable dependency injection and configuration management for dynamic, context-aware conversational bots. It is a critical dependency for `botbuilder-dialogs-adaptive-runtime` and is part of a larger ecosystem designed to simplify bot development by allowing declarative dialog definitions and runtime adaptation to user input. The package is regularly updated with bug fixes, security patches, and support for newer Node.js and TypeScript versions. While this package provides the low-level building blocks, users typically interact with higher-level packages like `botbuilder-dialogs-adaptive-runtime` for complete bot runtime setup.
Common errors
-
Error: Node.js version is not supported. Minimum supported version is 18.
cause Attempting to run the bot with an unsupported Node.js version (e.g., Node.js 16 or earlier).fixUpgrade your Node.js environment to version 18.x or higher using a version manager like `nvm` (e.g., `nvm install 18 && nvm use 18`). -
TypeScript Error: This version of TypeScript is incompatible with the installed Node.js types. Expected >=5.9
cause Your project is using an older TypeScript version (e.g., 4.7) which is no longer compatible with the SDK's internal dependencies or type definitions.fixUpdate your TypeScript dependency in `package.json` to `^5.9.0` or newer, then run `npm install` or `yarn install` and rebuild your project. -
Error: Bot service must be an instance of ActivityHandler.
cause The configured bot within the runtime services is not correctly set up as an `ActivityHandler`, or the `getRuntimeServices` function failed to initialize it properly based on configuration.fixVerify your `appsettings.json` or equivalent configuration to ensure the 'bot' entry correctly points to your bot's implementation that extends `ActivityHandler`. Check for configuration file parsing errors or missing declarative assets.
Warnings
- breaking As of Bot Framework JS SDK 4.23.0, Node.js versions prior to 18 are no longer supported. This is due to updates in underlying Azure Identity and MSAL.Node packages.
- breaking As of Bot Framework JS SDK 4.23.3, support for TypeScript 4.7 has been dropped due to incompatibilities with newer Node.js types. TypeScript 5.9 is now supported.
- gotcha The default `MemoryStorage` implementation, often used in examples, is designed for testing purposes with a single bot host and does not provide durable storage. Data will not persist across restarts or scale-out scenarios.
- gotcha Federated Credentials for bot-to-channel authentication, introduced in Bot Framework JS SDK 4.23.2, are currently only supported for single-tenant applications.
- deprecated The entire Microsoft Bot Framework SDK for JavaScript project is scheduled for archiving no later than the end of December 2025, with support tickets no longer being serviced as of December 31, 2025.
Install
-
npm install botbuilder-dialogs-adaptive-runtime-core -
yarn add botbuilder-dialogs-adaptive-runtime-core -
pnpm add botbuilder-dialogs-adaptive-runtime-core
Imports
- ServiceCollection
const ServiceCollection = require('botbuilder-dialogs-adaptive-runtime-core').ServiceCollection;import { ServiceCollection } from 'botbuilder-dialogs-adaptive-runtime-core'; - Configuration
import { Configuration } from 'botbuilder-dialogs-adaptive-runtime-core'; - ConfigurationResourceExplorer
import { ConfigurationResourceExplorer } from 'botbuilder-dialogs-adaptive-runtime-core';
Quickstart
import { BotFrameworkAdapter, ActivityHandler } from 'botbuilder';
import { getRuntimeServices } from 'botbuilder-dialogs-adaptive-runtime';
import * as path from 'path';
import * as restify from 'restify';
// Basic bot implementation using the adaptive runtime.
// This demonstrates how 'runtime-core' components are leveraged indirectly
// through 'botbuilder-dialogs-adaptive-runtime' for a working bot.
class AdaptiveBot extends ActivityHandler {
private dialogManager: any; // In a real app, this would be DialogManager
constructor(dialogManager: any) {
super();
this.dialogManager = dialogManager;
this.onMessage(async (context, next) => {
console.log('Activity received:', context.activity.text);
// This would trigger the adaptive dialog turn
await this.dialogManager.onTurn(context);
// By default, if no adaptive dialog handles the turn, echo the message.
if (!context.responded) {
await context.sendActivity(`You said: '${context.activity.text}'`);
}
await next();
});
this.onMembersAdded(async (context, next) => {
const membersAdded = context.activity.membersAdded;
for (const member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity(`Hello and welcome!`);
}
}
await next();
});
}
}
async function main() {
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
console.log(`\n${server.name} listening to ${server.url}`);
console.log(`\nGet the Bot Framework Emulator: https://aka.ms/botframework-emulator`);
console.log(`\nTo talk to your bot, open the emulator and connect to: http://localhost:${process.env.port || process.env.PORT || 3978}/api/messages`);
});
// Retrieve runtime services using 'botbuilder-dialogs-adaptive-runtime'
// which internally uses 'botbuilder-dialogs-adaptive-runtime-core' components.
const [services, configuration] = await getRuntimeServices(path.resolve(__dirname, '..'), path.resolve(__dirname, '..', 'settings'));
// The services object will contain various components, including the configured bot.
const bot = services.get('bot');
if (!(bot instanceof ActivityHandler)) {
throw new Error('Bot service must be an instance of ActivityHandler.');
}
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId ?? '',
appPassword: process.env.MicrosoftAppPassword ?? ''
});
server.post('/api/messages', (req, res) => {
adapter.processActivity(req, res, async (context) => {
await bot.run(context);
});
});
}
main().catch((err) => {
console.error('Error starting bot:', err);
process.exit(1);
});