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 static/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
- Improved styling
- Simple UI customization
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.
- Build
- Start a local web server using
npm run start
and aim your browser athttp://localhost:8000/samples/standalone?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}/samples/standalone?[s={Direct Line Secret}|t={Direct Line Token}]" width="320" height="500"/>
- You will probably want to customize the supplied sample index.html page
(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.
- Build
- Include
botchat.js
and you will get an object calledBotChat
- For TypeScript users there is a type definition file called static/botchat.d.ts.
- Incorporate static/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 samples/standalone/index.html.
In this scenario you will incorporate WebChat's multiple JavaScript files into your React webapp.
- Build
- Incorporate the files in the /built folder into your build process
- Incorporate static/botchat.css into your website deployment
- For TypeScript users there is a definition file called static/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 samples/standalone/index.html.
NOTE: The provided backchannel [sample]((https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/standalone/index.html) requires a bot which can send and receive specific event messages. Follow the instructions here to deploy such a bot.
Backchannel is a way to send activities of type "event" (which are ignored by the actual webchat) between the page that hosts webchat and your bot web service. The backchannel sample provided in this project listens for events of name "changeBackground" and sends events of activity name "buttonClicked". This highlights the ability for a bot to communicate with a page that embeds the bot through WebChat. In other words, our bot can:
- Send events to a page that hosts an instance of WebChat - demonstrated by the bot sending an activity of type "event" and of name "changeBackground", which changes the background color of the parent page.
- Listen for events from the page that hosts an instance of WebChat - demonstrated by the bot responding "I see you clicked that button" when it receives an event named buttonClicked.
- 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