Embeddable web chat control for the Microsoft Bot Framework using the DirectLine API.
Used by the Bot Framework developer portal, Emulator, WebChat channel, and Azure Bot Service
You can easily play with a recent build using botchattest
WebChat is a React component built in TypeScript using Redux for state management and RxJS for wrangling async.
- As an IFRAME in any website using the standard Bot Framework WebChat channel. In this case you don't need this repo or any of the information in it.
- As a standalone website, primarily for testing purposes
- As an IFRAME in any website, pointed at an instance hosted by you, customized to your needs
- Inline in your non-React webapp, customized to your needs
- Inline in your React webapp, customized to your needs
See more detailed instructions below.
- Follow the below instructions to install and build
- Customize the visuals by altering the public/botchat.css file
- Or go farther and change the HTML/JSX and/or TypeScript
- File issues and submit pull requests!
Not the most formal one you'll ever see, but:
- Unit tests
- DirectLine 3.0 WebSocket support for retrieving messages
- Improved styling
- Simple UI customization
- npm package(s)
- CDN
Feel free to suggest features by filing an issue (please make sure one doesn't already exist).
- Add localized strings (see below)
- Report any unreported issues
- Propose new features
- Fix an outstanding issue and submit a pull request (please only commit source code, non-generated files)
- Clone this repo
npm install
npm run build
(to build on every changenpm run watch
, to build minifiednpm run minify
)
- If you haven't already, register your bot.
- Add a DirectLine channel, and generate a Direct Line Secret. Make sure to enable Direct Line 3.0.
- For testing you can use your Direct Line Secret as a security token, but for production you will likely want to exchange that Secret for a Token as detailed in the Direct Line documentation.
- Head over to the Bot Framework developer portal and add the WebChat channel to your bot. You don't need this repo or any of the information on this page.
This is a quick and dirty method, perfect for testing. It requires embedding your Direct Line Secret in the web page or querystring, and as such should primarily be used for local testing.
- Start a local web server using
npm run start
and aim your browser athttp://localhost:8000?s={Direct Line Secret}
In this scenario you will host two web pages, one for WebChat and one for the page which embeds it. They could be hosted by the same web server, or two entirely different web servers.
- Serve the botchat in its own standalone web page, as described above
- Optionally, on your web server, exchange the Direct Line Secret for a Token as detailed in the Direct Line documentation.
- In a second web page, embed the botchat via
<iframe src="http://{host}:{port}?[s={Direct Line Secret}|t={Direct Line Token}]" width="320" height="500"/>
(An example of this approach is botchattest)
In this scenario you will include a JavaScript file which embeds its own copy of React, which will run in a DOM element.
- Include public/botchat.js and you will get an object called
BotChat
- For TypeScript users there is a type definition file called public/botchat.d.ts.
- Incorporate public/botchat.css into your website deployment
- Optionally, on your web server, exchange the Direct Line Secret for a Token as detailed in the Direct Line documentation.
- Create an instance of
BotChat.DirectLine
using your Direct Line Secret or Token - Call
BotChat.App
with the DOM element where you want your chat instance, your DirectLine instance, user and bot identities, and other properties as demonstrated in public/index.html.
In this scenario you will incorporate WebChat's multiple JavaScript files into your React webapp.
- Incorporate the files in the /built folder into your build process
- Incorporate public/botchat.css into your website deployment
- For TypeScript users there is a definition file called public/botchat.d.ts.
- Optionally, on your web server, exchange the Direct Line Secret for a Token as detailed in the Direct Line documentation.
- Create an instance of
DirectLine
using your Direct Line Secret or Token - Call the
Chat
React component with your DirectLine instance, user and bot identities, and other properties as demonstrated in public/index.html.
- When IFRAMEd, set
window.frames["{iframe_id}"].botchatDebug = true
from the browser console - Otherwise set
window.botchatDebug = true
orvar botchatDebug = true
from the browser console
In src/Strings.ts :
- Add one or more locales (with associated localized strings) to
localizedStrings
- Add logic to map the requested locale to the support locale in
strings
- If you just adding a new locale for an existing set of strings, just update
strings
to return the existing locale's strings - ... and please help the community by submitting a pull request!
© 2016 Microsoft Corporation