-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update code to fit library updates (#1401)
- Loading branch information
1 parent
fc7a801
commit b3bf9d9
Showing
2 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`. | ||
// | ||
|
@@ -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/", | ||
} | ||
}, | ||
}) | ||
); | ||
|
||
|
@@ -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); | ||
} | ||
**/ | ||
|
||
|
@@ -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); | ||
} | ||
**/ | ||
|
||
|
@@ -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) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters