Skip to content

Commit

Permalink
Merge branch 'master' into 2747
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurnford authored Jan 3, 2020
2 parents 890b1a9 + 7946bde commit 8364bf9
Show file tree
Hide file tree
Showing 467 changed files with 1,380 additions and 1,506 deletions.
4 changes: 2 additions & 2 deletions ACTIVITYTYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Although the Direct Line channel and Web Chat channel support the following acti

When developing your bot's web page, you may discover that the bot sends an activity type that needs to be supported by Web Chat. Luckily, it is possible to create renderers for different activities through the [`activityMiddleware`](https://github.com/microsoft/BotFramework-WebChat#web-chat-api-reference). To learn more, check out the following tutorials:

1. [Customize Web Chat with Reaction Buttons](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/09.customization-reaction-buttons/)
1. [Customize Web Chat with GitHub Stargazer Components](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/10.a.customization-card-components)
1. [Customize Web Chat with Reaction Buttons](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/05.custom-components/d.reaction-buttons/)
1. [Customize Web Chat with GitHub Stargazer Components](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/05.custom-components/e.card-components)

Note: We do not recommend creating custom activity types. Instead, please use the `event` activity type.
57 changes: 29 additions & 28 deletions CHANGELOG.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions DIRECT_LINE_SPEECH.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We assume you have already set up a bot and have Web Chat running on a page.

Direct Line Speech is designed for Voice Assistant scenario. For example, smart display, automotive dashboard, navigation system with low-latency requirement on _single-page application_ and _progressive web apps_ (PWA). These apps usually are made with highly-customized UI and do not show conversation transcripts.

You can look at our sample [13.a.customization-speech-ui](https://microsoft.github.io/BotFramework-WebChat/samples/13.a.customization-speech-ui) and [13.b.smart-display](https://microsoft.github.io/BotFramework-WebChat/samples/13.b.customization-smart-display) for target scenarios.
You can look at our sample [06.recomposing-ui/b.speech-ui](https://microsoft.github.io/BotFramework-WebChat/samples/06.recomposing-ui/b.speech-ui) and [06.recomposing-ui/c.smart-display](https://microsoft.github.io/BotFramework-WebChat/samples/06.recomposing-ui/c.smart-display) for target scenarios.

Direct Line Speech is not recommended to use on traditional websites where its primary UI is transcript-based.

Expand Down Expand Up @@ -241,7 +241,7 @@ Direct Line Speech shares the same requirements as Cognitive Services Speech Ser

Before start, please create corresponding Azure resources. You can follow [this tutorial for enabling voice in your bot](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/tutorial-voice-enable-your-bot-speech-sdk). You do not need to follow the steps for creating C# client, you will replace the client with Web Chat.

Please look at our sample `06.i.direct-line-speech` to embedding Web Chat on your web app via Direct Line Speech channel.
Please look at our sample `03.speech/a.direct-line-speech` to embedding Web Chat on your web app via Direct Line Speech channel.

> You will need to use Web Chat 4.7 or higher for Direct Line Speech.
Expand Down Expand Up @@ -340,7 +340,7 @@ Direct Line Speech is not targeting a transcript-based experience. Thus, our ser

> Please vote on [this bug](https://github.com/microsoft/BotFramework-WebChat/issues/2680) if this behavior is not desirable.
When using text-based experience, we allow developers to piggyback additional information to outgoing messages. This is demonstrated in [sample 15.a "piggyback data on every outgoing activity"](15.a.backchannel-piggyback-on-outgoing-activities).
When using text-based experience, we allow developers to piggyback additional information to outgoing messages. This is demonstrated in [sample 15.a "piggyback data on every outgoing activity"](04.api/b.piggyback-on-outgoing-activities).

With Direct Line Speech, you can no longer piggyback additional data to all speech-based outgoing activities.

Expand Down
2 changes: 1 addition & 1 deletion HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Web Chat is designed to be highly customizable. In order to build your own UI, you can use React Hooks to hook your UI component into Web Chat API.

To enable Web Chat API, all UI components must be located under the [`<Composer>`](https://github.com/microsoft/BotFramework-WebChat/blob/master/packages/component/src/Composer.js) component. You can refer to our [plain UI customization](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/21.customization-plain-ui) sample for details.
To enable Web Chat API, all UI components must be located under the [`<Composer>`](https://github.com/microsoft/BotFramework-WebChat/blob/master/packages/component/src/Composer.js) component. You can refer to our [plain UI customization](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.recomposing-ui/d.plain-ui) sample for details.

## Why React Hooks

Expand Down
117 changes: 62 additions & 55 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ ReactDOM.render(
);
```

The full sample can be found at [/samples/10.a.customization-card-components/](samples/10.a.customization-card-components/).
The full sample can be found at [/samples/05.custom-components/e.card-components/](samples/05.custom-components/e.card-components/).

In this sample, we are adding a new React component called `GitHubRepositoryAttachment`:

Expand Down
4 changes: 2 additions & 2 deletions SPEECH.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ Using this approach, you can also combine two polyfills of different types. For

[authenticate requests to azure cognitive services]: https://docs.microsoft.com/en-us/azure/cognitive-services/authentication
[get started with custom voice]: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/how-to-custom-voice
[sample: integrating with cognitive services speech services]: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.c.cognitive-services-speech-services-js
[sample: using hybrid speech engine]: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.f.hybrid-speech
[sample: integrating with cognitive services speech services]: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/03.speech/b.cognitive-speech-services-js
[sample: using hybrid speech engine]: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/03.speech/g.hybrid-speech
[speech synthesis markup language]: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-synthesis-markup
[try cognitive services]: https://azure.microsoft.com/en-us/try/cognitive-services/my-apis/#speech
[web audio api support]: https://caniuse.com/#feat=audio-api
Expand Down
190 changes: 107 additions & 83 deletions WELCOME_MESSAGE.md
Original file line number Diff line number Diff line change
@@ -1,131 +1,155 @@
Here is how Welcome Messages in Web Chat should be handled with the updates to the Direct Line Connector Service.

# Web Chat Welcome Messages
Channels generally send two conversation update events when the conversation is initialized - the first for the bot and another for the user. The second conversation update - the event for the user - is intended to trigger the welcome message. At the moment, Web Chat has two different welcome message scenarios that are slightly different from other channels and based on how the developer generates the Direct Line token.

Channels generally send two conversation update events when the conversation is initialized - the first for the bot and another for the user. The second conversation update - the event for the user - is intended to trigger the welcome message. At the moment, Web Chat has two different welcome message scenarios that are slightly different from other channels and based on how the developer generates the Direct Line token.

## Tokens with User IDs

The first scenario is dependent on the token request including a user ID. If the developer includes a user ID when generating the token, Direct Line will only send one conversation update event to the bot that includes two user IDs in the activity's `membersAdded` property - one for the bot and one for the user. Following this configuration should trigger the traditional welcome message in the `onMembersAdded` handler before the user messages the bot.

In the example below, the user ID is added to the token request and the welcome message is sent from the `onMembersAdded` handler.

### Web Chat

```javascript
(async function () {
// Note, for the simplicity of this example, we are generating the Direct Line token on client side;
// however, this is not a recommended practice and you should create and manage your tokens from the server.
// 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 secret = '<DIRECT_LINE_SECRET> | <WEB_CHAT_SECRET>';
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
body: JSON.stringify({ user: { id: 'dl_user_id', name: 'username' }}),
headers: {
Authorization: `Bearer ${secret}`,
'Content-type': 'application/json'
},
method: 'POST',
});
const { token } = await res.json();

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

document.querySelector('#webchat > *').focus();
(async function() {
// Note, for the simplicity of this example, we are generating the Direct Line token on client side;
// however, this is not a recommended practice and you should create and manage your tokens from the server.
// 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 secret = '<DIRECT_LINE_SECRET> | <WEB_CHAT_SECRET>';
const res = await fetch(
'https://directline.botframework.com/v3/directline/tokens/generate',
{
body: JSON.stringify({ user: { id: 'dl_user_id', name: 'username' } }),
headers: {
Authorization: `Bearer ${secret}`,
'Content-type': 'application/json'
},
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));
```

### Bot Framework SDK v4 (Node.js)

```javascript
this.onMembersAdded(async (context, next) => {
const { membersAdded } = context.activity;

for (let member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity("Welcome Message from `onMembersAdded` handler!");
}
}
await next();
const { membersAdded } = context.activity;

for (let member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity(
'Welcome Message from `onMembersAdded` handler!'
);
}
}
await next();
});
```

### Tokens, User IDs, and iFrames
To achieve this in an iFrame of Web Chat, retrieve your token with user ID as described above and pass the token within the `src` attribute of the iFrame:
```<iframe src='https://webchat.botframework.com/embed/YOUR_BOT_HERE?t=YOUR_TOKEN_HERE' style='min-width: 400px; width: 100%; min-height: 500px;'></iframe>```

To achieve this in an iFrame of Web Chat, retrieve your token with user ID as described above and pass the token within the `src` attribute of the iFrame:
`<iframe src='https://webchat.botframework.com/embed/YOUR_BOT_HERE?t=YOUR_TOKEN_HERE' style='min-width: 400px; width: 100%; min-height: 500px;'></iframe>`

## Secrets and Tokens without User IDs

Alternatively, conversations created with tokens that do not include a user ID send two conversation update events. Direct Line sends the first conversation update - the one for the bot - when the connection with the bot is established. Direct Line sends the second conversation update for the user after they send their first message.

Generally, users anticipate the bot to send a welcome message before they send a message. To do this, you can dispatch a backchannel welcome event from Web Chat's store middleware when the Direct Line connection is established. Then in the `onEvent` handler, you can send a welcome message. Note, in the `onMembersAdded` handler you should check which channel is sending the event before sending the welcome message. If the channel id is "webchat" or "directline" you should not send the traditional welcome message to avoid sending multiple welcome messages.

### Web Chat

```javascript
(async function () {
// Note, for the simplicity of this example, we are generating the Direct Line token on client side;
// however, this is not a recommended practice and you should create and manage your tokens from the server.
// 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 secret = '<DIRECT_LINE_SECRET> | <WEB_CHAT_SECRET>';
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
headers: {
Authorization: `Bearer ${secret}`,
},
method: 'POST'
});
const { token } = await res.json();

const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
}
});
(async function() {
// Note, for the simplicity of this example, we are generating the Direct Line token on client side;
// however, this is not a recommended practice and you should create and manage your tokens from the server.
// 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 secret = '<DIRECT_LINE_SECRET> | <WEB_CHAT_SECRET>';
const res = await fetch(
'https://directline.botframework.com/v3/directline/tokens/generate',
{
headers: {
Authorization: `Bearer ${secret}`
},
method: 'POST'
}
);
const { token } = await res.json();

const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join'
}
});
}
return next(action);
}
return next(action);
}
);
);

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

document.querySelector('#webchat > *').focus();
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
```

### Bot Framework SDK v4 (Node.js)

```javascript
this.onEvent(async (context, next) => {
if (context.activity.name === 'webchat/join') {
await context.sendActivity('Back Channel Welcome Message!');
}
await next();
if (context.activity.name === 'webchat/join') {
await context.sendActivity('Back Channel Welcome Message!');
}
await next();
});

this.onMembersAdded(async (context, next) => {
const { channelId, membersAdded } = context.activity;

if (channelId !== 'directline' && channelId !== 'webchat') {
for (let member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity("Welcome Message from `onMembersAdded` handler!");
const { channelId, membersAdded } = context.activity;

if (channelId !== 'directline' && channelId !== 'webchat') {
for (let member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity(
'Welcome Message from `onMembersAdded` handler!'
);
}
}
}
}
await next();
}
await next();
});
```

For more details regarding backchannel welcome events in Web Chat, take a look at this [sample](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event).
For more details regarding backchannel welcome events in Web Chat, take a look at this [sample](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/a.welcome-event).

### Additional Context
- [Bot Framework Direct Line Authentication](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0)
- [Using WebChat with Azure Bot Service’s Authentication](https://blog.botframework.com/2018/09/01/using-webchat-with-azure-bot-services-authentication/)
- [Bot Framework Welcome Message Sample - Node SDK](https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/03.welcome-users)
- [Bot Framework Welcome Message Sample - C# SDK](https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/03.welcome-user)
- [Web Chat Backchannel Welcome Event Sample](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event)

- [Bot Framework Direct Line Authentication](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0)
- [Using WebChat with Azure Bot Service’s Authentication](https://blog.botframework.com/2018/09/01/using-webchat-with-azure-bot-services-authentication/)
- [Bot Framework Welcome Message Sample - Node SDK](https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/03.welcome-users)
- [Bot Framework Welcome Message Sample - C# SDK](https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/03.welcome-user)
- [Web Chat Backchannel Welcome Event Sample](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/a.welcome-event)
2 changes: 1 addition & 1 deletion __tests__/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Automated testing in Web Chat is using multiple open-source technologies.

- [Azure DevOps](https://azure.microsoft.com/en-us/services/devops/) for automatic testing
- Test against [MockBot](https://github.com/compulim/BotFramework-MockBot)
- Try it out with this [live demo](https://microsoft.github.io/BotFramework-WebChat/01.a.getting-started-full-bundle)
- Try it out with this [live demo](https://microsoft.github.io/BotFramework-WebChat/01.getting-started/a.full-bundle)
- Visual regression tests (a.k.a. compare screenshots)
- Generated on [Chrome on Docker](https://github.com/SeleniumHQ/docker-selenium)
- Compared using [`pixelmatch`](https://npmjs.com/package/pixelmatch) via [`jest-image-snapshot`](https://npmjs.com/package/jest-image-snapshot)
Expand Down
16 changes: 8 additions & 8 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"lerna": "3.19.0",
"packages": [
"packages/*",
"samples/12.customization-minimizable-web-chat",
"samples/13.a.customization-speech-ui",
"samples/13.b.customization-smart-display",
"samples/14.customization-piping-to-redux",
"samples/16.customization-selectable-activity",
"samples/17.a.chat-send-history",
"samples/17.b.clear-after-idle",
"samples/21.customization-plain-ui"
"samples/04.api/e.piping-to-redux",
"samples/04.api/f.selectable-activity",
"samples/04.api/g.chat-send-history",
"samples/04.api/h.clear-after-idle",
"samples/06.recomposing-ui/a.minimizable-web-chat",
"samples/06.recomposing-ui/b.speech-ui",
"samples/06.recomposing-ui/c.smart-display",
"samples/06.recomposing-ui/d.plain-ui"
],
"version": "0.0.0"
}
Loading

0 comments on commit 8364bf9

Please sign in to comment.