Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample verbiage & add new sample: migration from v3 to v4 #1398

Merged
merged 4 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `webpack`
- `[email protected]`
- `[email protected]`
- Fix [#1237](https://github.com/Microsoft/BotFramework-WebChat/issues/1237). Added new sample called `markdown`, by [@corinagum](https://github.com/corinagum) in PR [#1398](https://github.com/Microsoft/BotFramework-WebChat/pull/1398)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow... fix to 'migration'


## [4.1.0] - 2018-10-31
### Added
Expand Down
6 changes: 3 additions & 3 deletions samples/activity-decorator-button/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<script src="https://unpkg.com/[email protected]/dist/react-redux.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/index.js"></script>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/activity-decorator-highlight/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<script src="https://unpkg.com/[email protected]/dist/react-redux.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/index.js"></script>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/avatar-initials/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Web Chat: Avatar with initials</title>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/custom-attachment-github-repository/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/dist/react-redux.min.js"></script>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/custom-redux-store/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Web Chat: Custom Redux store</title>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js"
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/custom-style-options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Web Chat: Custom style options</title>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/custom-style-set/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Web Chat: Custom style set</title>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
6 changes: 3 additions & 3 deletions samples/es5-bundle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Web Chat: Full-featured bundle with ES5 polyfills</title>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat-es5.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat-es5.js".
Or locked down on a specific version "/4.1.0/webchat-es5.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat-es5.js"></script>
<style>
Expand Down
4 changes: 1 addition & 3 deletions samples/full-bundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ The `index.html` page has two main goals.
```

> For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
> When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
> Or locked down on a specific version "/4.1.0/webchat.js".
> For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js". When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js", or lock down on a specific version with the following format: "/4.1.0/webchat.js".

Next, the code to render Web Chat must be added to the body. Note that MockBot uses **tokens** rather than the **Direct Line secret**.
> It is **never recommended** to put the Direct Line secret in the browser or client app. To learn more about secrets and tokens for Direct Line, visit [this tutorial on authentication](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication).
Expand Down
6 changes: 3 additions & 3 deletions samples/full-bundle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<title>Web Chat: Full-featured bundle</title>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
4 changes: 1 addition & 3 deletions samples/integrate-with-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ We'll start by adding React and Babel to the head our template, based off of the
```

> For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
> When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
> Or locked down on a specific version "/4.1.0/webchat.js".
> For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js". When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js", or lock down on a specific version with the following format: "/4.1.0/webchat.js".

The core of this code both creates and renders the React component that displays Web Chat.

Expand Down
6 changes: 3 additions & 3 deletions samples/integrate-with-react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<!--
For demonstration purpose, we are using development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js".
Or locked down on a specific version "/4.1.0/webchat.js".
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
Expand Down
193 changes: 193 additions & 0 deletions samples/migration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Sample - Migrating Web Chat from v3 to v4

A simple web page with a maximized and full-featured Web Chat embed from a CDN. This shows the steps on how to migrate from a v3 Web Chat to v4.

> Note: This sample is __unrelated__ to the version of **Bot Framework** that the bot is using. This sample makes changes from the v3 Web Chat samples to ultimately match the [full-bundle CDN sample](./../full-bundle/README.md).

# Test out the hosted sample

- [Try out MockBot](https://microsoft.github.io/BotFramework-WebChat/full-bundle)
> Although there are two separate samples, one named `full-bundle` and the other named `migration`, the end-result html is exactly the same. Therefore, the `migration` sample links to the same `full-bundle` bot.

# How to run locally

- Fork this repository
- Navigate to `/Your-Local-WebChat/samples/migration` in command line
- Run `npx serve` in the migration directory
- Browse to [http://localhost:5000/](http://localhost:5000/)

# Things to try out

- Type `help`: you should see a full list of MockBot features
- Type `markdown`: you should see the sample of Markdown
- Type `card weather`: you should see a weather card built using Adaptive Cards
- Type `layout carousel`: you should see a carousel of cards
- Resize the window and see how the carousel changes size

# Code

> Jump to [completed code](#completed-code) to see the end-result `index.html`.

## Getting started

### Goals of this bot

This code features the migration requirements to update Web Chat from v3 to v4.
The `index.html` page in the migration directory has two main goals.
- To import the v4 Web Chat full bundle CDN script
- To render Web Chat using the v4 best practices

We'll start by using our old v3 `index.html` as our starting point.
```diff
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="https://cdn.botframework.com/botframework-webchat/0.13.1/botchat.css" rel="stylesheet" />
</head>
<body>
<div id="bot"/>
<script src="https://cdn.botframework.com/botframework-webchat/0.13.1/botchat.js"></script>
<script>
BotChat.App({
directLine: { secret: direct_line_secret },
user: { id: 'userid' },
bot: { id: 'botid' },
resize: 'detect'
}, document.getElementById("bot"));
</script>
</body>
</html>
```

> For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js". When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js", or lock down on a specific version with the following format: "/4.1.0/webchat.js".

Our first change is to update the CDN the webpage uses from v3 to v4.
```diff
<head>
- <link href="https://cdn.botframework.com/botframework-webchat/0.13.1/botchat.css" rel="stylesheet" />
+ <script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
</head>
<body>
- <div id="bot"/>
+ <div id="webchat"/>
- <script src="https://cdn.botframework.com/botframework-webchat/0.13.1/botchat.js"></script>
```

Next, the code to render Web Chat must be updated in the body. Note that MockBot uses **tokens** rather than the **Direct Line secret**.
> It is **never recommended** to put the Direct Line secret in the browser or client app. To learn more about secrets and tokens for Direct Line, visit [this tutorial on authentication](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication).

```diff
<body>
<div id="webchat"></div>
<script>
- BotChat.App({
- directLine: { secret: direct_line_secret },
- user: { id: 'userid' },
- bot: { id: 'botid' },
- resize: 'detect'
- }, document.getElementById("bot"));
+ (async function () {
+ const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
+ const { token } = await res.json();
+ window.WebChat.renderWebChat({
+ directLine: window.WebChat.createDirectLine({ token })
+ }, document.getElementById('webchat'));
+ })();
</script>
</body>
```

## Styling and Adding features

Next, you can add any other structure or DOM changes that will support Web Chat.

MockBot also features an autofocus on the Web Chat container, as well as push of any errors to the browser console. This is helpful for debugging.

```diff
(async function () {
- })();
+ document.querySelector('#webchat > *').focus();
+ })().catch(err => console.error(err));
</script>
```


Finally, we will add basic styling since there is no longer a stylesheet included on our page.
```diff
<head>
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
+ <style>
+ html, body { height: 100% }
+ body { margin: 0 }

+ #webchat,
+ #webchat > * {
+ height: 100%;
+ width: 100%;
+ }
+ </style>
</head>
```

## Completed code

Here is the finished `index.html`:

```diff
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Full-featured bundle</title>
+ <script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
+ <style>
+ html, body { height: 100% }
+ body { margin: 0 }
+ #webchat,
+ #webchat > * {
+ height: 100%;
+ width: 100%;
+ }
+ </style>
</head>
<body>
+ <div id="webchat"></div>
+ <script>
+ (async function () {
+ const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
+ const { token } = await res.json();

+ window.WebChat.renderWebChat({
+ directLine: window.WebChat.createDirectLine({ token })
+ }, document.getElementById('webchat'));

+ document.querySelector('#webchat > *').focus();
+ })().catch(err => console.error(err));
+ </script>
</body>
</html>
```

# Further reading

## Other CDN bundles

Check out the hosted samples and source code for other CDN bundle options below.

- [Full bundle with polyfills for ES5 browsers](https://microsoft.github.io/BotFramework-WebChat/es5-bundle) | [(source)](https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/es5-bundle)
- [Minimal bundle](https://microsoft.github.io/BotFramework-WebChat/minimal-bundle) | [(source)](https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/minimal-bundle)
- [Minimal bundle with Markdown](https://microsoft.github.io/BotFramework-WebChat/minimal-bundle-with-markdown) | [(source)](https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/minimal-bundle-with-markdown)

## CDN sunburst chart

[This chart](http://cdn.botframework.com/botframework-webchat/master/stats.html) provides a visual of the contents of the various Web Chat bundles

## Full list of Web Chat hosted samples

View the list of available samples by clicking [here](https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples)
42 changes: 42 additions & 0 deletions samples/migration/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Full-featured bundle</title>
<!--
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
html, body { height: 100% }
body { margin: 0 }

#webchat,
#webchat > * {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat"></div>
<script>
(async function () {
// In this demo, we are using Direct Line token from MockBot.
// To talk to your bot, you should use the token exchanged using your Direct Line secret.
// You should never put the Direct Line secret in the browser or client app.
// https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication

const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
const { token } = await res.json();

window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token })
}, document.getElementById('webchat'));

document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
</body>
</html>
Loading