Bot Framework Activity Schema

4.23.3 · active · verified Tue Apr 21

The `botframework-schema` package provides the TypeScript interfaces and JSON schema definitions for activities exchanged within the Microsoft Bot Framework. This package defines the fundamental structure for messages, conversations, attachments, and other events that occur between a bot and its users across various communication channels. The current stable version is 4.23.3. It is an integral component of the broader Bot Framework JS SDK and follows a consistent release cadence, typically monthly or bi-monthly, synchronizing with the SDK's updates. Releases frequently address security patches, expand Node.js version support, and ensure compatibility with newer TypeScript versions. Its primary differentiation is serving as the canonical and universally recognized schema for all Bot Framework interactions, thereby guaranteeing interoperability and offering robust type safety for bot developers utilizing TypeScript.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import and create different types of `Activity` objects, including a `MessageActivity` and a generic `Trace` activity, conforming to the `botframework-schema` interfaces.

import { Activity, ActivityTypes, MessageActivity, ChannelAccount } from 'botframework-schema';

// Define a basic user account
const user: ChannelAccount = {
  id: 'user123',
  name: 'Test User',
  role: 'user'
};

// Define a basic bot account
const bot: ChannelAccount = {
  id: 'bot456',
  name: 'Test Bot',
  role: 'bot'
};

// Create a simple message activity conforming to the schema
const messageActivity: MessageActivity = {
  type: ActivityTypes.Message,
  id: 'message-1',
  timestamp: new Date().toISOString(),
  from: user,
  recipient: bot,
  conversation: {
    id: 'convo-abc',
    name: 'Test Conversation',
    isGroup: false,
    conversationType: 'personal'
  },
  channelId: 'emulator',
  text: 'Hello, bot! How are you?',
  locale: 'en-US'
};

console.log('Created a message activity:', messageActivity.text);

// You can also create a generic activity and cast it if needed
const genericActivity: Activity = {
  type: ActivityTypes.Trace,
  id: 'trace-1',
  timestamp: new Date().toISOString(),
  text: 'Trace activity initiated.',
  valueType: 'application/json',
  value: { method: 'GET', path: '/api/data' }
};

console.log('Created a trace activity:', genericActivity.type, genericActivity.id);

view raw JSON →