Bot Framework Adaptive Dialogs Runtime Core

4.23.3-preview · maintenance · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

This quickstart initializes a basic bot using `botbuilder-dialogs-adaptive-runtime`'s `getRuntimeServices` to set up adaptive dialog capabilities, demonstrating how 'runtime-core' elements contribute to the bot's operation.

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);
});

view raw JSON →