Skip to content

Commit

Permalink
feat: remove adaptivecards-tools dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yukun-dong committed Aug 9, 2024
1 parent d92b163 commit ae3ae28
Show file tree
Hide file tree
Showing 30 changed files with 87 additions and 73 deletions.
3 changes: 2 additions & 1 deletion NPM-search-message-extension-codespaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"botbuilder": "^4.18.0",
"isomorphic-fetch": "^3.0.0",
"restify": "^10.0.0"
Expand Down
3 changes: 2 additions & 1 deletion adaptive-card-notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"dependencies": {
"@azure/storage-blob": "^12.9.0",
"@azure/identity": "^4.4.0",
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"@microsoft/teamsfx": "^2.0.0",
"botbuilder": "^4.18.0"
},
"devDependencies": {
"@azure/functions": "^1.2.3",
"@types/json-schema": "^7.0.15",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^14.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { notificationApp } from "./internal/initialize";
import notificationTemplate from "./adaptiveCards/notification-columnset.json";
import { ColumnsetData } from "./cardModels";
Expand Down Expand Up @@ -41,7 +41,7 @@ const httpTrigger: AzureFunction = async function (
const targets = pagedInstallations.data;
for (const target of targets) {
await target.sendAdaptiveCard(
AdaptiveCards.declare<ColumnsetData>(notificationTemplate).render(data)
new ACData.Template(notificationTemplate).expand({ $root: data })
);
}
} while (continuationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { notificationApp } from "./internal/initialize";
import notificationTemplate from "./adaptiveCards/notification-default.json";
import { CardData } from "./cardModels";
Expand All @@ -24,7 +24,7 @@ const httpTrigger: AzureFunction = async function (
const targets = pagedInstallations.data;
for (const target of targets) {
await target.sendAdaptiveCard(
AdaptiveCards.declare<CardData>(notificationTemplate).render(data)
new ACData.Template(notificationTemplate).expand({ $root: data })
);
}
} while (continuationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { notificationApp } from "./internal/initialize";
import notificationTemplate from "./adaptiveCards/notification-factset.json";
import { FactsetData } from "./cardModels";
Expand Down Expand Up @@ -29,7 +29,7 @@ const httpTrigger: AzureFunction = async function (
const targets = pagedInstallations.data;
for (const target of targets) {
await target.sendAdaptiveCard(
AdaptiveCards.declare<FactsetData>(notificationTemplate).render(data)
new ACData.Template(notificationTemplate).expand({ $root: data })
);
}
} while (continuationToken);
Expand Down
4 changes: 2 additions & 2 deletions adaptive-card-notification/src/listNotificationHttpTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { notificationApp } from "./internal/initialize";
import notificationTemplate from "./adaptiveCards/notification-list.json";
import { ListData } from "./cardModels";
Expand Down Expand Up @@ -29,7 +29,7 @@ const httpTrigger: AzureFunction = async function (
const targets = pagedInstallations.data;
for (const target of targets) {
await target.sendAdaptiveCard(
AdaptiveCards.declare<ListData>(notificationTemplate).render(data)
new ACData.Template(notificationTemplate).expand({ $root: data })
);
}
} while (continuationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { notificationApp } from "./internal/initialize";
import notificationTemplate from "./adaptiveCards/notification-mention.json";
import { MentionData } from "./cardModels";
Expand All @@ -26,7 +26,7 @@ const httpTrigger: AzureFunction = async function (
const targets = pagedInstallations.data;
for (const target of targets) {
await target.sendAdaptiveCard(
AdaptiveCards.declare<MentionData>(notificationTemplate).render(data)
new ACData.Template(notificationTemplate).expand({ $root: data })
);

/** List all members then notify each member
Expand Down
4 changes: 3 additions & 1 deletion hello-world-bot-with-tab/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"url": "https://github.com"
},
"dependencies": {
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"botbuilder": "^4.17.0",
"restify": "^11.1.0"
},
"devDependencies": {
"@types/restify": "8.5.5",
"@types/json-schema": "^7.0.15",
"@types/node": "^14.0.0",
"env-cmd": "^10.1.0",
"ts-node": "^10.4.0",
Expand Down
12 changes: 5 additions & 7 deletions hello-world-bot-with-tab/bot/teamsBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "botbuilder";
import rawWelcomeCard from "./adaptiveCards/welcome.json";
import rawLearnCard from "./adaptiveCards/learn.json";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";

export interface DataInterface {
likeCount: number;
Expand Down Expand Up @@ -35,13 +35,12 @@ export class TeamsBot extends TeamsActivityHandler {
// Trigger command by IM text
switch (txt) {
case "welcome": {
const card = AdaptiveCards.declareWithoutData(rawWelcomeCard).render();
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] });
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(rawWelcomeCard)] });
break;
}
case "learn": {
this.likeCountObj.likeCount = 0;
const card = AdaptiveCards.declare<DataInterface>(rawLearnCard).render(this.likeCountObj);
const card = new ACData.Template(rawLearnCard).expand({ $root: this.likeCountObj });
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] });
break;
}
Expand All @@ -61,8 +60,7 @@ export class TeamsBot extends TeamsActivityHandler {
const membersAdded = context.activity.membersAdded;
for (let cnt = 0; cnt < membersAdded.length; cnt++) {
if (membersAdded[cnt].id) {
const card = AdaptiveCards.declareWithoutData(rawWelcomeCard).render();
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(card)] });
await context.sendActivity({ attachments: [CardFactory.adaptiveCard(rawWelcomeCard)] });
break;
}
}
Expand All @@ -79,7 +77,7 @@ export class TeamsBot extends TeamsActivityHandler {
// The verb "userlike" is sent from the Adaptive Card defined in adaptiveCards/learn.json
if (invokeValue.action.verb === "userlike") {
this.likeCountObj.likeCount++;
const card = AdaptiveCards.declare<DataInterface>(rawLearnCard).render(this.likeCountObj);
const card = new ACData.Template(rawLearnCard).expand({ $root: this.likeCountObj });
await context.updateActivity({
type: "message",
id: context.activity.replyToId,
Expand Down
4 changes: 3 additions & 1 deletion incoming-webhook-notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
"url": "https://github.com"
},
"dependencies": {
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"axios": "^0.26.1"
},
"devDependencies": {
"@types/json-schema": "^7.0.15",
"nodemon": "^2.0.7",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
Expand Down
19 changes: 10 additions & 9 deletions incoming-webhook-notification/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { WebhookTarget } from "./webhookTarget";
import template from "./adaptiveCards/notification-default.json";

Expand All @@ -12,12 +12,13 @@ const webhookTarget = new WebhookTarget(new URL(webhookUrl));
* Send adaptive cards.
*/
webhookTarget.sendAdaptiveCard(
AdaptiveCards.declare(template).render(
{
"title": "New Event Occurred!",
"appName": "Contoso App",
"description": "Detailed description of what happened so the user knows what's going on.",
"notificationUrl" : "https://www.adaptivecards.io/"
new ACData.Template(template).expand({
$root: {
"title": "New Event Occurred!",
"appName": "Contoso App",
"description": "Detailed description of what happened so the user knows what's going on.",
"notificationUrl": "https://www.adaptivecards.io/"
},
}))
.then(() => console.log("Send adaptive card successfully."))
.catch(e => console.log(`Failed to send adaptive card. ${e}`));
.then(() => console.log("Send adaptive card successfully."))
.catch(e => console.log(`Failed to send adaptive card. ${e}`));
4 changes: 3 additions & 1 deletion large-scale-notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
"dependencies": {
"@azure/data-tables": "^13.2.2",
"@azure/service-bus": "^7.9.0",
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"@microsoft/teamsfx": "^2.3.0",
"botbuilder": "^4.18.0",
"durable-functions": "^2.1.2",
"luxon": "^3.3.0"
},
"devDependencies": {
"@azure/functions": "^3.5.0",
"@types/json-schema": "^7.0.15",
"@types/luxon": "^3.3.0",
"axios": "^1.4.0",
"azurite": "^3.16.0",
Expand Down
6 changes: 4 additions & 2 deletions large-scale-notification/src/httpTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import notificationTemplate from "./adaptiveCards/notification-default.json";
import { CardData } from "./cardModels";
import { notificationApp } from "./internal/initialize";
Expand All @@ -23,11 +23,13 @@ const httpTrigger: AzureFunction = async function (
// to every installation.
for (const target of await notificationApp.notification.installations()) {
await target.sendAdaptiveCard(
AdaptiveCards.declare<CardData>(notificationTemplate).render({
new ACData.Template(notificationTemplate).expand({
$root:{
title: "New Event Occurred!",
appName: "Contoso App Notification",
description: `This is a sample http-triggered notification to ${target.type}`,
notificationUrl: "https://aka.ms/teamsfx-notification-new",
}
})
);

Expand Down
3 changes: 2 additions & 1 deletion notification-codespaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"url": "https://github.com"
},
"dependencies": {
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"@microsoft/teamsfx": "^2.2.0",
"botbuilder": "^4.18.0",
"restify": "^10.0.0"
Expand Down
14 changes: 8 additions & 6 deletions notification-codespaces/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const notificationTemplate = require("./adaptiveCards/notification-default.json");
const { notificationApp } = require("./internal/initialize");
const { AdaptiveCards } = require("@microsoft/adaptivecards-tools");
const ACData = require("adaptivecards-templating");
const { TeamsBot } = require("./teamsBot");
const restify = require("restify");

Expand Down Expand Up @@ -29,11 +29,13 @@ server.post(

for (const target of installations) {
await target.sendAdaptiveCard(
AdaptiveCards.declare(notificationTemplate).render({
title: "New Event Occurred!",
appName: "Contoso App Notification",
description: `This is a sample http-triggered notification to ${target.type}`,
notificationUrl: "https://aka.ms/teamsfx-notification-new",
new ACData.Template(notificationTemplate).expand({
$root: {
title: "New Event Occurred!",
appName: "Contoso App Notification",
description: `This is a sample time-triggered notification (${timeStamp}).`,
notificationUrl: "https://aka.ms/teamsfx-notification-new",
}
})
);

Expand Down
4 changes: 3 additions & 1 deletion stocks-update-notification-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
"url": "https://github.com"
},
"dependencies": {
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"@microsoft/teamsfx": "^2.0.0",
"botbuilder": "^4.18.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"@azure/functions": "^1.2.3",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.14.182",
"@types/node": "^14.0.0",
"azurite": "^3.16.0",
Expand Down
8 changes: 4 additions & 4 deletions stocks-update-notification-bot/src/timerTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AzureFunction, Context } from '@azure/functions';
import { AdaptiveCards } from '@microsoft/adaptivecards-tools';
import * as ACData from "adaptivecards-templating";
import { AxiosInstance, BotBuilderCloudAdapter } from '@microsoft/teamsfx';
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
import TeamsBotInstallation = BotBuilderCloudAdapter.TeamsBotInstallation;
Expand All @@ -19,7 +19,7 @@ const timerTrigger: AzureFunction = async function (context: Context, myTimer: a
.then(quote => addCompanyName(quote)('Microsoft Corporation'))
.then(quote =>
getInstallations(notificationApp)
.then(targets => targets.map(target => sendCard(target)(AdaptiveCards)(template)(quote)))
.then(targets => targets.map(target => sendCard(target)()(template)(quote)))
)
.catch(err => handleError(err)(context));

Expand Down Expand Up @@ -89,10 +89,10 @@ const getInstallations =

const sendCard =
<T extends object>(target: TeamsBotInstallation) =>
(ac: typeof AdaptiveCards) =>
() =>
(template: object) =>
(quote: GlobalQuote): Promise<any> =>
target.sendAdaptiveCard(ac.declare<T>(template).render(quote as T));
target.sendAdaptiveCard(new ACData.Template(template).expand({ $root: quote }));

const handleError =
(err: Error) =>
Expand Down
4 changes: 3 additions & 1 deletion test-tool-sample-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"url": "https://github.com"
},
"dependencies": {
"@microsoft/adaptivecards-tools": "^1.0.0",
"adaptivecards-templating": "^2.3.1",
"adaptive-expressions": "^4.22.3",
"@microsoft/teamsfx": "^2.3.1",
"botbuilder": "^4.18.0",
"restify": "^10",
Expand All @@ -29,6 +30,7 @@
},
"devDependencies": {
"@types/restify": "8.4.2",
"@types/json-schema": "^7.0.15",
"env-cmd": "^10.1.0",
"nodemon": "^2.0.7",
"shx": "^0.3.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { TurnContext, InvokeResponse, TeamsInfo } from "botbuilder";
import { TeamsFxAdaptiveCardActionHandler, InvokeResponseFactory } from "@microsoft/teamsfx";
import responseCard from "../adaptiveCards/incidentReportedResponse.json";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { TurnContext, InvokeResponse } from "botbuilder";
import { TeamsFxAdaptiveCardActionHandler, InvokeResponseFactory } from "@microsoft/teamsfx";
import responseCard from "../adaptiveCards/doStuffActionResponse.json";
Expand Down
4 changes: 2 additions & 2 deletions test-tool-sample-app/src/cardActions/userLikeActionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import { TurnContext, InvokeResponse } from "botbuilder";
import { TeamsFxAdaptiveCardActionHandler, InvokeResponseFactory, AdaptiveCardResponse } from "@microsoft/teamsfx";
import learnCard from "../adaptiveCards/learn.json";
Expand All @@ -14,7 +14,7 @@ export class UserLikeActionHandler implements TeamsFxAdaptiveCardActionHandler {
async handleActionInvoked(context: TurnContext, actionData: any): Promise<InvokeResponse> {
console.log(actionData);
const count = parseInt(actionData['likeCount'], 10);
const cardJson = AdaptiveCards.declare(learnCard).render({'likeCount': `${count+1}`});
const cardJson = new ACData.Template(learnCard).expand({ $root: {'likeCount': `${count+1}`} });
return InvokeResponseFactory.adaptiveCard(cardJson);
}
}
4 changes: 2 additions & 2 deletions test-tool-sample-app/src/commands/helloworldCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Activity, CardFactory, MessageFactory, TurnContext } from "botbuilder";
import { CommandMessage, TeamsFxBotCommandHandler, TriggerPatterns } from "@microsoft/teamsfx";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as ACData from "adaptivecards-templating";
import helloWorldCard from "../adaptiveCards/helloworldCommandResponse.json";
import { HelloWorldCardData } from "../cardModels";

Expand All @@ -23,7 +23,7 @@ export class HelloWorldCommandHandler implements TeamsFxBotCommandHandler {
body: "Congratulations! Your hello world bot is running. Click the button below to trigger an action.",
};

const cardJson = AdaptiveCards.declare(helloWorldCard).render(cardData);
const cardJson = new ACData.Template(helloWorldCard).expand({ $root: cardData });
return MessageFactory.attachment(CardFactory.adaptiveCard(cardJson));
}
}
Loading

0 comments on commit ae3ae28

Please sign in to comment.