Skip to content

Commit

Permalink
fix: update code to fit library updates (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
QinghuiMeng-M authored Feb 12, 2025
1 parent fc7a801 commit b3bf9d9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 27 deletions.
96 changes: 70 additions & 26 deletions test-tool-sample-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ const teamsBot = new SimpleBot();
const expressApp = express();
expressApp.use(express.json());

const server = expressApp.listen(process.env.port || process.env.PORT || 3978, () => {
console.log(`\nBot Started, ${expressApp.name} listening to`, server.address());
});
const server = expressApp.listen(
process.env.port || process.env.PORT || 3979,
() => {
console.log(
`\nBot Started, ${expressApp.name} listening to`,
server.address()
);
}
);

// Register an API endpoint with `express`.
//
Expand All @@ -25,21 +31,28 @@ const server = expressApp.listen(process.env.port || process.env.PORT || 3978, (
//
// You can add authentication / authorization for this API. Refer to
// https://aka.ms/teamsfx-notification for more details.
expressApp.post(
"/api/notification",
async (req, res, next) => {
// By default this function will iterate all the installation points and send an Adaptive Card
// to every installation.
for (const target of await conversationBot.notification.installations()) {
expressApp.post("/api/notification", async (req, res, next) => {
// By default this function will iterate all the installation points and send an Adaptive Card
// to every installation.
const pageSize = 100;
let continuationToken: string | undefined = undefined;
do {
const pagedData = await conversationBot.notification.getPagedInstallations(
pageSize,
continuationToken
);
const installations = pagedData.data;
continuationToken = pagedData.continuationToken;

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

Expand All @@ -50,13 +63,20 @@ expressApp.post(
if (target.type === NotificationTargetType.Group) {
// You can send the Adaptive Card to the Group Chat
await target.sendAdaptiveCard(...);
// Or you can list all members in the Group Chat and send the Adaptive Card to each Team member
const members = await target.members();
for (const member of members) {
// You can even filter the members and only send the Adaptive Card to members that fit a criteria
await member.sendAdaptiveCard(...);
}
const pageSize = 100;
let continuationToken: string | undefined = undefined;
do {
const pagedData = await target.getPagedMembers(pageSize, continuationToken);
const members = pagedData.data;
continuationToken = pagedData.continuationToken;
for (const member of members) {
// You can even filter the members and only send the Adaptive Card to members that fit a criteria
await member.sendAdaptiveCard(...);
}
} while (continuationToken);
}
**/

Expand All @@ -65,18 +85,26 @@ expressApp.post(
if (target.type === NotificationTargetType.Channel) {
// If you send an Adaptive Card to the Team (the target), it sends it to the `General` channel of the Team
await target.sendAdaptiveCard(...);
// Alternatively, you can list all channels in the Team and send the Adaptive Card to each channel
const channels = await target.channels();
for (const channel of channels) {
await channel.sendAdaptiveCard(...);
}
// Or, you can list all members in the Team and send the Adaptive Card to each Team member
const members = await target.members();
for (const member of members) {
await member.sendAdaptiveCard(...);
}
const pageSize = 100;
let continuationToken: string | undefined = undefined;
do {
const pagedData = await target.getPagedMembers(pageSize, continuationToken);
const members = pagedData.data;
continuationToken = pagedData.continuationToken;
for (const member of members) {
// You can even filter the members and only send the Adaptive Card to members that fit a criteria
await member.sendAdaptiveCard(...);
}
} while (continuationToken);
}
**/

Expand All @@ -88,10 +116,26 @@ expressApp.post(
}
**/
}
} while (continuationToken);

res.json({});
/** You can also find someone and notify the individual person
const member = await notificationApp.notification.findMember(
async (m) => m.account.email === "[email protected]"
);
await member?.sendAdaptiveCard(...);
**/

/** Or find multiple people and notify them
const members = await notificationApp.notification.findAllMembers(
async (m) => m.account.email?.startsWith("test")
);
for (const member of members) {
await member.sendAdaptiveCard(...);
}
);
**/

res.json({});
});

expressApp.post("/api/messages", async (req, res, next) => {
await conversationBot.requestHandler(req, res, async (context) => {
Expand Down
3 changes: 2 additions & 1 deletion test-tool-sample-app/src/internal/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DoStuffActionHandler } from "../cardActions/doStuffActionHandler";
import { HelloWorldCommandHandler } from "../commands/helloworldCommandHandler";
import { ConversationBot } from "@microsoft/teamsfx";
import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
import config from "./config";
import { MembersCommandHandler } from "../commands/membersCommandHandler";
import { UserLikeActionHandler } from "../cardActions/userLikeActionHandler";
Expand Down

0 comments on commit b3bf9d9

Please sign in to comment.