Altered the web part to use the currently logged in user's username when sending messages. Also updated the README and cleaned up some unused references in the code.
This commit is contained in:
parent
318960f2a9
commit
354704dca4
|
@ -18,4 +18,6 @@
|
||||||
"lib": true,
|
"lib": true,
|
||||||
"temp": true
|
"temp": true
|
||||||
}
|
}
|
||||||
|
,
|
||||||
|
"typescript.check.workspaceVersion": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
# Microsoft Bot Framework Web Chat
|
# Microsoft Bot Framework Web Chat
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
Short summary on functionality and used technologies.
|
A web part that acts as a web chat component for bot's built on the Microsoft Bot Framework using the Direct Line API. When sending messages
|
||||||
|
the web part uses the username of the currently logged in user. The web part has settings for color for branding purposes.
|
||||||
|
|
||||||
[picture of the web part in action]
|
![bot framework client web part](screenshot.png)
|
||||||
|
|
||||||
## Applies to
|
## Applies to
|
||||||
|
|
||||||
|
@ -12,10 +13,10 @@ Short summary on functionality and used technologies.
|
||||||
* [Microsoft Bot Framework](http://dev.botframework.com)
|
* [Microsoft Bot Framework](http://dev.botframework.com)
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
> You need to have a bot created and registered using the Microsoft Bot Framework and registered to use the Direct Line Channel,
|
> You need to have a bot created and registered using the Microsoft Bot Framework and registered to use the Direct Line Channel,
|
||||||
which will give you the secret needed when adding this web part to the page. For more information on creating a bot and registering
|
which will give you the secret needed when adding this web part to the page. For more information on creating a bot and registering
|
||||||
the channel you can see the official web site at [dev.botframework.com](http://dev.botframework.com), as well as various tutorials
|
the channel you can see the official web site at [dev.botframework.com](http://dev.botframework.com), as well as various tutorials
|
||||||
over at [www.garypretty.co.uk/category/microsoft-bot-framework/](http://www.garypretty.co.uk/category/microsoft-bot-framework/)
|
over at [www.garypretty.co.uk/category/microsoft-bot-framework/](http://www.garypretty.co.uk/category/microsoft-bot-framework/)
|
||||||
|
|
||||||
## Solution
|
## Solution
|
||||||
|
@ -45,7 +46,7 @@ Version|Date|Comments
|
||||||
|
|
||||||
- Register your bot in the Microsoft Bot Framework Portal, configure the Direct Line channel on the bot and obtain your Direct Line secret.
|
- Register your bot in the Microsoft Bot Framework Portal, configure the Direct Line channel on the bot and obtain your Direct Line secret.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
This Web Part illustrates the following concepts on top of the SharePoint Framework:
|
This Web Part illustrates the following concepts on top of the SharePoint Framework:
|
||||||
|
|
||||||
- Connecting and communicating with a bot built on the Microsoft Bot Framework using the Direct Line Channel
|
- Connecting and communicating with a bot built on the Microsoft Bot Framework using the Direct Line Channel
|
||||||
|
@ -54,7 +55,7 @@ This Web Part illustrates the following concepts on top of the SharePoint Framew
|
||||||
- React
|
- React
|
||||||
|
|
||||||
When adding the web part to a page you need to obtain your Bot Direct Line Channel secret via the [Bot Framework Portal](http://dev.botframework.com).
|
When adding the web part to a page you need to obtain your Bot Direct Line Channel secret via the [Bot Framework Portal](http://dev.botframework.com).
|
||||||
You then add this secret via the Property Pane of the web part. If there is an error initializing the Direct Line Client with the bot then they will
|
You then add this secret via the Property Pane of the web part. If there is an error initializing the Direct Line Client with the bot then they will
|
||||||
be shown in the console within the browser.
|
be shown in the console within the browser.
|
||||||
|
|
||||||
Additional settings can be set to style the web part, including;
|
Additional settings can be set to style the web part, including;
|
||||||
|
@ -64,7 +65,7 @@ Additional settings can be set to style the web part, including;
|
||||||
- Placeholder text
|
- Placeholder text
|
||||||
- Foreground / background colors for messages, both from the user and from the bot
|
- Foreground / background colors for messages, both from the user and from the bot
|
||||||
|
|
||||||
Currently this web part only supports plain text conversations with a bot. Other message types,
|
Currently this web part only supports plain text conversations with a bot. Other message types,
|
||||||
such as Rich Cards and Attachments are not supported, but are on the roadmap for a future update.
|
such as Rich Cards and Attachments are not supported, but are on the roadmap for a future update.
|
||||||
|
|
||||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-bot-framework" />
|
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-bot-framework" />
|
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
|
@ -21,8 +21,7 @@
|
||||||
"botMessagesBackgroundColor": "c8c8c8",
|
"botMessagesBackgroundColor": "c8c8c8",
|
||||||
"botMessagesForegroundColor": "000000",
|
"botMessagesForegroundColor": "000000",
|
||||||
"userMessagesBackgroundColor": "c7e0f4",
|
"userMessagesBackgroundColor": "c7e0f4",
|
||||||
"userMessagesForegroundColor": "000000",
|
"userMessagesForegroundColor": "000000"
|
||||||
"directLineClientName": "DirectLineClient"
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
PropertyPaneTextField
|
PropertyPaneTextField
|
||||||
} from '@microsoft/sp-client-preview';
|
} from '@microsoft/sp-client-preview';
|
||||||
|
|
||||||
import * as strings from 'botFrameworkChatStrings';
|
|
||||||
import BotFrameworkChat, { IBotFrameworkChatProps } from './components/BotFrameworkChat';
|
import BotFrameworkChat, { IBotFrameworkChatProps } from './components/BotFrameworkChat';
|
||||||
import { IBotFrameworkChatWebPartProps } from './IBotFrameworkChatWebPartProps';
|
import { IBotFrameworkChatWebPartProps } from './IBotFrameworkChatWebPartProps';
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ export default class BotFrameworkChatWebPart extends BaseClientSideWebPart<IBotF
|
||||||
botMessagesForegroundColor: this.properties.botMessagesForegroundColor,
|
botMessagesForegroundColor: this.properties.botMessagesForegroundColor,
|
||||||
userMessagesBackgroundColor: this.properties.userMessagesBackgroundColor,
|
userMessagesBackgroundColor: this.properties.userMessagesBackgroundColor,
|
||||||
userMessagesForegroundColor: this.properties.userMessagesForegroundColor,
|
userMessagesForegroundColor: this.properties.userMessagesForegroundColor,
|
||||||
directLineClientName: this.properties.directLineClientName
|
context: this.context
|
||||||
});
|
});
|
||||||
|
|
||||||
ReactDom.render(element, this.domElement);
|
ReactDom.render(element, this.domElement);
|
||||||
|
@ -47,10 +46,7 @@ export default class BotFrameworkChatWebPart extends BaseClientSideWebPart<IBotF
|
||||||
groupName: 'Bot Connection',
|
groupName: 'Bot Connection',
|
||||||
groupFields: [
|
groupFields: [
|
||||||
PropertyPaneTextField('directLineSecret', {
|
PropertyPaneTextField('directLineSecret', {
|
||||||
label: 'Direct Line Channel Secret'
|
label: 'Direct Line Secret'
|
||||||
}),
|
|
||||||
PropertyPaneTextField('directLineClientName', {
|
|
||||||
label: 'Bot User Name (send messages as...)'
|
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -99,9 +95,8 @@ export default class BotFrameworkChatWebPart extends BaseClientSideWebPart<IBotF
|
||||||
|
|
||||||
private _validateColorPropertyAsync(value: string): string {
|
private _validateColorPropertyAsync(value: string): string {
|
||||||
var colorRegex = /^([a-zA-Z0-9]){6}$/;
|
var colorRegex = /^([a-zA-Z0-9]){6}$/;
|
||||||
if(!value || colorRegex.test(value) == false)
|
if (!value || colorRegex.test(value) == false) {
|
||||||
{
|
return "Please enter a valid 6 character hex color value";
|
||||||
return "Please enter a valid 6 character hex color value";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { IWebPartContext } from '@microsoft/sp-client-preview';
|
||||||
|
|
||||||
export interface IBotFrameworkChatWebPartProps {
|
export interface IBotFrameworkChatWebPartProps {
|
||||||
description: string;
|
description: string;
|
||||||
message: string;
|
message: string;
|
||||||
|
@ -9,5 +11,5 @@ export interface IBotFrameworkChatWebPartProps {
|
||||||
botMessagesForegroundColor: string;
|
botMessagesForegroundColor: string;
|
||||||
userMessagesBackgroundColor: string;
|
userMessagesBackgroundColor: string;
|
||||||
userMessagesForegroundColor: string;
|
userMessagesForegroundColor: string;
|
||||||
directLineClientName: string;
|
context: IWebPartContext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ export default class BotFrameworkChat extends React.Component<IBotFrameworkChatP
|
||||||
private directLineClientSwagger;
|
private directLineClientSwagger;
|
||||||
private messagesHtml;
|
private messagesHtml;
|
||||||
private currentMessageText;
|
private currentMessageText;
|
||||||
|
private sendAsUserName;
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
|
@ -63,6 +64,8 @@ export default class BotFrameworkChat extends React.Component<IBotFrameworkChatP
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.sendAsUserName = this.props.context.pageContext.user.loginName;
|
||||||
|
|
||||||
this.printMessage = this.printMessage.bind(this);
|
this.printMessage = this.printMessage.bind(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +101,7 @@ export default class BotFrameworkChat extends React.Component<IBotFrameworkChatP
|
||||||
{
|
{
|
||||||
conversationId: this.conversationId,
|
conversationId: this.conversationId,
|
||||||
message: {
|
message: {
|
||||||
from: this.props.directLineClientName,
|
from: this.sendAsUserName,
|
||||||
text: messageToSend
|
text: messageToSend
|
||||||
}
|
}
|
||||||
}).catch((err) => console.error('Error sending message:', err));
|
}).catch((err) => console.error('Error sending message:', err));
|
||||||
|
@ -114,17 +117,17 @@ export default class BotFrameworkChat extends React.Component<IBotFrameworkChatP
|
||||||
watermark = response.obj.watermark;
|
watermark = response.obj.watermark;
|
||||||
return response.obj.messages;
|
return response.obj.messages;
|
||||||
})
|
})
|
||||||
.then((messages) => this.printMessages(messages))
|
.then((messages) => this.printMessages(messages));
|
||||||
}, this.pollInterval);
|
}, this.pollInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected printMessages(messages) {
|
protected printMessages(messages) {
|
||||||
if (messages && messages.length) {
|
if (messages && messages.length) {
|
||||||
messages = messages.filter((m) => m.from !== this.props.directLineClientName);
|
messages = messages.filter((m) => m.from !== this.sendAsUserName);
|
||||||
if (messages.length) {
|
if (messages.length) {
|
||||||
messages.forEach(this.printMessage);
|
messages.forEach(this.printMessage);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected printMessage(message) {
|
protected printMessage(message) {
|
||||||
|
|
Loading…
Reference in New Issue