AzureRecipes

Introduction

The integration of the BotFramework web-chat component in the popular micro-frontend framework single-spa can be tricky. This reference implementation is created with:

  1. The single-spa CLI by generating a React module (Note: pure JS)
  2. Adoption of the official sample “06.recomposing-ui/a.minimizable-web-chat”

Additionally, some useful styling is provided as template as well as the automatic start of a conversation (welcome message) as soon as the component is loaded and the enrichment of each user input with additional piggyback/backchannel data.

Notes / learnings:

Getting Started

Deploy your bot service to Azure (no special configurations or prerequists necessary) and enable the Directline channel.

  1. Adjust the directline secret in minimizable-web-chat.js (or replace the method with a call to an according backend service)
  2. Run npm ci
  3. Run npm run start:standalone for local testing

The module can be integrated to the single-spa shell as any other module. If Content Security Policy (CSP) is configured in the shell application (meta property in index.html or index.ejs), make sure it allows to access the directline API. The definition may look like:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' https: localhost:*; script-src 'unsafe-inline' https: localhost:*; connect-src https: localhost:* ws://localhost:* ws://realtime-notifications.service.signalr.net ws://*.service.signalr.net wss://directline.botframework.com ; style-src 'unsafe-inline' https:; object-src 'none'; font-src 'self' data:; img-src 'self' data: blob:">

References