Skip to content

Commit

Permalink
More String changes (OfficeDev#767)
Browse files Browse the repository at this point in the history
* fix(): rename Teams App Framework to Teams Framework

* fix(): revert sso payload comments

* fix(): add to gitignore the package-lock.json from templates

* fix(): bots

* fix(): amend bot intro messages

* fix(): fix message extension templates

* fix(): formatting

* fix(): readme wip

* fix(): conflict cruft
  • Loading branch information
zhenyasav authored May 10, 2021
1 parent c62a8d5 commit 400f35f
Show file tree
Hide file tree
Showing 21 changed files with 1,050 additions and 706 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,7 @@ coverage
test-results.*

# simple auth
SimpleAuth.zip
SimpleAuth.zip

# so you can npm install inside a template and not worry about committing
templates/*/*/package-lock.json
1 change: 1 addition & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tabWidth: 4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Teams Developer Platform offers a collection of solutions for Teams develope
- IDE extensions for Visual Studio and Visual Studio Code named "Teams Toolkit"
- Docs, samples
- Code libraries including Teams Framework `teamsfx` and the Teams Client Library `teams-js`
- A command line tool `teamsfx` for automation and CI
- A command line tool `teamsfx` for terminal users, automation, and CI

This repository contains the following packages:
| Package | Description |
Expand Down
11 changes: 7 additions & 4 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
"type-enum": [2, "always", ["chore", "docs", "feat", "fix", "refactor", "style", "test"]],
"scope-empty": [2, "never"]
};

"type-enum": [
2,
"always",
["chore", "docs", "feat", "fix", "refactor", "style", "test"],
],
"scope-empty": [2, "never"],
};
92 changes: 63 additions & 29 deletions templates/bot-msgext/js/dialogs/mainDialog.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const { DialogSet, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs');
const { RootDialog } = require('./rootDialog');
const { tokenExchangeOperationName, ActivityTypes, CardFactory } = require("botbuilder");
const {
DialogSet,
DialogTurnStatus,
WaterfallDialog,
} = require("botbuilder-dialogs");
const { RootDialog } = require("./rootDialog");
const {
tokenExchangeOperationName,
ActivityTypes,
CardFactory,
} = require("botbuilder");

const MAIN_DIALOG = 'MainDialog';
const MAIN_WATERFALL_DIALOG = 'MainWaterfallDialog';
const MAIN_DIALOG = "MainDialog";
const MAIN_WATERFALL_DIALOG = "MainWaterfallDialog";
const TEAMS_SSO_PROMPT_ID = "TeamsFxSsoPrompt";

const { polyfills } = require('isomorphic-fetch');
const { polyfills } = require("isomorphic-fetch");
const {
createMicrosoftGraphClient,
loadConfiguration,
OnBehalfOfUserCredential,
TeamsBotSsoPrompt
TeamsBotSsoPrompt,
} = require("teamsdev-client");
const { ResponseType } = require('@microsoft/microsoft-graph-client');
const { ResponseType } = require("@microsoft/microsoft-graph-client");

class MainDialog extends RootDialog {
constructor(dedupStorage) {
super(MAIN_DIALOG);
this.requiredScopes = ["User.Read"]; // hard code the scopes for demo purpose only
loadConfiguration();
this.addDialog(new TeamsBotSsoPrompt(TEAMS_SSO_PROMPT_ID, {
scopes: this.requiredScopes,
endOnInvalidMessage: true
}));
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.ssoStep.bind(this),
this.showUserInfo.bind(this)
]));
this.addDialog(
new TeamsBotSsoPrompt(TEAMS_SSO_PROMPT_ID, {
scopes: this.requiredScopes,
endOnInvalidMessage: true,
})
);
this.addDialog(
new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.ssoStep.bind(this),
this.showUserInfo.bind(this),
])
);

this.initialDialogId = MAIN_WATERFALL_DIALOG;
this.dedupStorage = dedupStorage;
Expand Down Expand Up @@ -60,38 +72,60 @@ class MainDialog extends RootDialog {
async showUserInfo(stepContext) {
const tokenResponse = stepContext.result;
if (tokenResponse) {
await stepContext.context.sendActivity("Call Microsoft Graph on behalf of user...");
await stepContext.context.sendActivity(
"Call Microsoft Graph on behalf of user..."
);

// Call Microsoft Graph on behalf of user
const oboCredential = new OnBehalfOfUserCredential(tokenResponse.ssoToken);
const graphClient = createMicrosoftGraphClient(oboCredential, ["User.Read"]);
const oboCredential = new OnBehalfOfUserCredential(
tokenResponse.ssoToken
);
const graphClient = createMicrosoftGraphClient(oboCredential, [
"User.Read",
]);
const me = await graphClient.api("/me").get();
if (me) {
await stepContext.context.sendActivity(`You're logged in as ${me.displayName} (${me.userPrincipalName}); your job title is: ${me.jobTitle}.`);
await stepContext.context.sendActivity(
`You're logged in as ${me.displayName} (${me.userPrincipalName}); your job title is: ${me.jobTitle}.`
);

// show user picture
var photoBinary = await graphClient.api("/me/photo/$value").responseType(ResponseType.ARRAYBUFFER).get();
var photoBinary = await graphClient
.api("/me/photo/$value")
.responseType(ResponseType.ARRAYBUFFER)
.get();
const buffer = Buffer.from(photoBinary);
const imageUri = 'data:image/png;base64,' + buffer.toString('base64');
const card = CardFactory.thumbnailCard("User Picture", CardFactory.images([imageUri]));
const imageUri =
"data:image/png;base64," + buffer.toString("base64");
const card = CardFactory.thumbnailCard(
"User Picture",
CardFactory.images([imageUri])
);
await stepContext.context.sendActivity({ attachments: [card] });
}
else {
await stepContext.context.sendActivity("Getting profile from Microsoft Graph failed! ");
} else {
await stepContext.context.sendActivity(
"Getting profile from Microsoft Graph failed! "
);
}

return await stepContext.endDialog();
}

await stepContext.context.sendActivity("Login was not successful please try again.");
await stepContext.context.sendActivity(
"Login was not successful please try again."
);
return await stepContext.endDialog();
}

async onEndDialog(context, instance, reason) {
const conversationId = context.activity.conversation.id;
const currentDedupKeys = this.dedupStorageKeys.filter(key => key.indexOf(conversationId) > 0);
const currentDedupKeys = this.dedupStorageKeys.filter(
(key) => key.indexOf(conversationId) > 0
);
await this.dedupStorage.delete(currentDedupKeys);
this.dedupStorageKeys = this.dedupStorageKeys.filter(key => key.indexOf(conversationId) < 0);
this.dedupStorageKeys = this.dedupStorageKeys.filter(
(key) => key.indexOf(conversationId) < 0
);
}

// If a user is signed into multiple Teams clients, the Bot might receive a "signin/tokenExchange" from each client.
Expand Down
68 changes: 42 additions & 26 deletions templates/bot-msgext/js/dialogs/rootDialog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const { ComponentDialog } = require('botbuilder-dialogs');
const { TurnContext, ActionTypes, CardFactory, TextFormatTypes } = require('botbuilder');
const { ComponentDialog } = require("botbuilder-dialogs");
const {
TurnContext,
ActionTypes,
CardFactory,
TextFormatTypes,
} = require("botbuilder");

class RootDialog extends ComponentDialog {
constructor(id) {
Expand All @@ -23,48 +28,59 @@ class RootDialog extends ComponentDialog {
}

async triggerCommand(innerDc) {
const removedMentionText = TurnContext.removeRecipientMention(innerDc.context.activity, innerDc.context.activity.recipient.id);
let text = '';
const removedMentionText = TurnContext.removeRecipientMention(
innerDc.context.activity,
innerDc.context.activity.recipient.id
);
let text = "";
if (removedMentionText) {
text = removedMentionText.toLowerCase().replace(/\n|\r/g, ''); // Remove the line break
text = removedMentionText.toLowerCase().replace(/\n|\r/g, ""); // Remove the line break
}
switch (text) {
case 'show': {
case "show": {
if (innerDc.context.activity.conversation.isGroup) {
await innerDc.context.sendActivity("Sorry, currently TeamsFX SDK hasn't support Group/Team/Meeting Bot SSO. To try this command please install this app as Personal Bot and send \"show\".");
await innerDc.context.sendActivity(
`Sorry, currently TeamsFX SDK doesn't support Group/Team/Meeting Bot SSO. To try this command please install this app as Personal Bot and send "show".`
);
return await innerDc.cancelAllDialogs();
}
break;
}
case 'intro': {
const cardButtons = [{ type: ActionTypes.ImBack, title: 'Show Profile', value: 'show' }];
case "intro": {
const cardButtons = [
{
type: ActionTypes.ImBack,
title: "Show Profile",
value: "show",
},
];
const card = CardFactory.heroCard(
'Introduction',
"Introduction",
null,
cardButtons,
{
text: `This Bot has implemented single sign-on (SSO) using Teams Account
which user logged in Teams client, check <a href=\"placeholder\">TeamsFx authentication document</a>
and code in <pre>bot/dialogs/mainDialog.js</pre> to learn more about SSO.
Type <strong>show</strong> or click the button below to show your profile by calling Microsoft Graph API with SSO.
To learn more about building Bot using Microsoft Teams Framework, please refer to the <a href=\"placeholder\">TeamsFx document</a> .`
});
text: `This Bot has implemented single sign-on (SSO) using the identity of the user signed into the Teams client. See the <a href="https://aka.ms/teamsfx-docs-auth">TeamsFx authentication document</a> and code in <pre>bot/dialogs/mainDialog.js</pre> to learn more about SSO.<br>Type <strong>show</strong> or click the button below to show your profile by calling Microsoft Graph API with SSO. To learn more about building Bot using Microsoft Teams Framework, please refer to the <a href="https://aka.ms/teamsfx-docs">TeamsFx documentation</a>.`,
}
);

await innerDc.context.sendActivity({ attachments: [card] });
return await innerDc.cancelAllDialogs();
}
default: {
if (innerDc.context.activity.textFormat === TextFormatTypes.Plain) {
const cardButtons = [{ type: ActionTypes.ImBack, title: 'Show introduction card', value: 'intro' }];
const card = CardFactory.heroCard(
'',
null,
cardButtons,
if (
innerDc.context.activity.textFormat ===
TextFormatTypes.Plain
) {
const cardButtons = [
{
text: `This is a hello world Bot built by Microsoft Teams Framework,
which is designed only for illustration Bot purpose. This Bot by default will not handle any specific question or task.
Please type <strong>intro</strong> to see the introduction card.`
});
type: ActionTypes.ImBack,
title: "Show introduction card",
value: "intro",
},
];
const card = CardFactory.heroCard("", null, cardButtons, {
text: `This is a hello world Bot built with Microsoft Teams Framework, which is designed for illustration purposes. This Bot by default will not handle any specific question or task.<br>Please type <strong>intro</strong> to see the introduction card.`,
});
await innerDc.context.sendActivity({ attachments: [card] });
}
return await innerDc.cancelAllDialogs();
Expand Down
Loading

0 comments on commit 400f35f

Please sign in to comment.