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

Rebuild bot implementation - Solves #237 & #246 #257

Merged
merged 12 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export class BotManifestUpdater implements IManifestUpdater {
{
"title": "Help",
"description": "Shows help information"
},
{
"title": "Who am I?",
"description": "Shows information about your Teams user"
},
{
"title": "Mention me",
"description": "Let the bot @mention you"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-teams/src/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"debug": "4.3.2",
"dotenv": "10.0.0",
"express": "4.16.4",
"express-msteams-host": "1.8.0-preview",
"express-msteams-host": "1.9.0-preview",
"express-session": "1.15.6",
"morgan": "1.9.1",
"react": "^16.8.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ express.set("port", port);
// Start the webserver
http.createServer(express).listen(port, () => {
log(`Server running on ${port}`);
});
});
10 changes: 7 additions & 3 deletions packages/generator-teams/src/bot/BotGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,17 @@ export class BotGenerator extends Generator {
templateFiles.push(
"README-{botName}.md",
"src/server/{botName}/{botClassName}.ts",
"src/server/{botName}/dialogBot.ts"
);
// add additional files if we have a full bot implementation
if (this.options.bot) {
templateFiles.push(
"src/server/{botName}/dialogs/HelpDialog.ts",
"src/server/{botName}/dialogs/WelcomeCard.json",
"src/server/{botName}/dialogs/WelcomeDialog.ts"
"src/server/{botName}/dialogs/mainDialog.ts",
"src/server/{botName}/dialogs/helpDialog.ts",
"src/server/{botName}/dialogs/mentionUserDialog.ts",
"src/server/{botName}/dialogs/teamsInfoDialog.ts",
"src/server/{botName}/cards/welcomeCard.json",
"src/server/{botName}/cards/welcomeCard.ts"
);
if (this.options.unitTestsEnabled) {
templateFiles.push(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://raw.githubusercontent.com/pnp/media/master/parker/teams/300w/parker-teams-300.png",
"size": "Medium"
}
],
"verticalContentAlignment": "Center",
"spacing": "Large"
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"spacing": "Medium",
"size": "Large",
"weight": "Bolder",
"text": "Welcome to <%= title %>",
"wrap": true,
"maxLines": 0
},
{
"type": "TextBlock",
"size": "default",
"text": "Hello, nice to meet you! I'm <%= title %> created using #yoTeams and happy to assist you 😀",
"wrap": true,
"maxLines": 0
}
]
}
]
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"title": "Learn more about Yo Teams",
"url": "https://aka.ms/yoteams"
},
{
"type": "Action.OpenUrl",
"title": "Learn more about bots in Teams",
"url": "https://docs.microsoft.com/en-us/microsoftteams/platform/bots/what-are-bots"
}
],
"height": "stretch",
"horizontalAlignment": "Center"
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Who am I?",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "who am i?",
"text": "who"
}
}
},
{
"type": "Action.Submit",
"title": "Mention me",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "mention me",
"text": "mention"
}
}
},
{
"type": "Action.Submit",
"title": "Get help",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "get help",
"text": "help"
}
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const WelcomeCard = require("./welcomeCard.json");
export default WelcomeCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
ConversationState,
UserState,
TeamsActivityHandler,
TurnContext
} from "botbuilder";
import { MainDialog } from "./dialogs/mainDialog";

export class DialogBot extends TeamsActivityHandler {
public dialogState: any;

constructor(public conversationState: ConversationState, public userState: UserState, public dialog: MainDialog) {
super();
this.conversationState = conversationState;
this.userState = userState;
this.dialog = dialog;
this.dialogState = this.conversationState.createProperty('DialogState');

this.onMessage(async (context, next) => {
// Run the MainDialog with the new message Activity.
await this.dialog.run(context, this.dialogState);
await next();
});
}

public async run(context: TurnContext) {
await super.run(context);
// Save any state changes. The load happened during the execution of the Dialog.
await this.conversationState.saveChanges(context, false);
await this.userState.saveChanges(context, false);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import HelpDialog from "../HelpDialog";
import { HelpDialog } from "../helpDialog";
import { DialogTestClient } from "botbuilder-testing";

describe("bot:HelpDialog", () => {
const helpDialog = new HelpDialog("help");
const helpDialog = new HelpDialog();
const testClient = new DialogTestClient("msteams", helpDialog);

it("Should receive an answer", async () => {
const reply = await testClient.sendActivity("");
expect(reply.text).toEqual("I'm just a friendly but rather stupid bot, and right now I don't have any valuable help for you!");
expect(reply.text).toEqual(`I'm terribly sorry, but my developer hasn't trained me to do anything yet 😂. Please refer to [this link](https://docs.microsoft.com/en-us/microsoftteams/platform/bots/what-are-bots) to see how to develop bots for Teams`);
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
ComponentDialog,
DialogSet,
DialogState,
DialogTurnResult,
DialogTurnStatus,
TextPrompt,
WaterfallDialog,
WaterfallStepContext,
} from "botbuilder-dialogs";
import {
MessageFactory,
StatePropertyAccessor,
TurnContext
} from 'botbuilder';

const HELP_DIALOG_ID = 'helpDialog';
const HELP_WATERFALL_DIALOG_ID = 'helpWaterfallDialog';

export class HelpDialog extends ComponentDialog {
constructor() {
super(HELP_DIALOG_ID);
this.addDialog(new TextPrompt('TextPrompt'))
.addDialog(new WaterfallDialog(HELP_WATERFALL_DIALOG_ID, [
this.introStep.bind(this),
]));
this.initialDialogId = HELP_WATERFALL_DIALOG_ID;
}

public async run(context: TurnContext, accessor: StatePropertyAccessor<DialogState>) {
const dialogSet = new DialogSet(accessor);
dialogSet.add(this);
const dialogContext = await dialogSet.createContext(context);
const results = await dialogContext.continueDialog();
if (results.status === DialogTurnStatus.empty) {
await dialogContext.beginDialog(this.id);
}
}

private async introStep(stepContext: WaterfallStepContext): Promise<DialogTurnResult> {
const message = MessageFactory.text(`I'm terribly sorry, but my developer hasn't trained me to do anything yet 😂. Please refer to [this link](https://docs.microsoft.com/en-us/microsoftteams/platform/bots/what-are-bots) to see how to develop bots for Teams`);
stephanbisser marked this conversation as resolved.
Show resolved Hide resolved
await stepContext.context.sendActivity(message);
return await stepContext.endDialog();
}
}
Loading