Κοινή χρήση μέσω


Extend your Composer bot with code

APPLIES TO: Composer v2.x

Composer provides a powerful platform for creating complex conversation flows, and comes with a robust set of pre-built triggers and actions to use. However, sometimes there will be a need to perform an action, respond to a trigger, work with an external API or do something for which there's no pre-built functionality. Or there may be a need to do something more complex like author middleware, create a custom storage provider, or connect to a client using a custom adapter. To accomplish these tasks (and more) create coded extensions called bot components.

Bot creation in Composer creates the necessary files to build and run your bot, including a <mybot>.sln or index.js file you can use to open your bot in your favorite code IDE. The bot project has a dependency on the adaptive runtime package, which provides access to the breadth of the Bot Framework SDK and extension points for registering components.

Adaptive runtime

The adaptive runtime is responsible for registering and injecting components. The BotComponent interface in the adaptive runtime describes a single method that accepts Service Collection and Configuration instances. The Service Collection provides components access to the common set of Bot Framework things that comprise the runtime. The Configuration instance provides access to a scoped set of user-provided configurations (like connection strings or secrets).

This creates a flexible and safe method to extend a bot with code. Through the runtime, components have access to the power of the Bot Framework SDK, while ensuring that any created component can be easily packaged and reused across multiple bots.

Bot components

A component is a group of coded extensions for a bot that uses the BotComponent class to register itself with the adaptive runtime. Components can contain things like:

  • Actions
  • Triggers
  • Middleware
  • Adapters
  • Storage providers
  • Authentication providers
  • Controllers/routes

Typically, a bot component consists of these parts:

  • The coded extension, like custom actions or adapters.
  • An implementation of the BotComponent class to register the objects and services of the component at start time.
  • One or more .schema files that are used to register services in the component with the adaptive dialog stack.
  • A .uischema file to tell Composer where and how to show the component in application UI.

Next