forked from qinezh/mybotapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
35 lines (30 loc) · 1.07 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Activity, CardFactory } from "botbuilder";
import { AdaptiveCards } from "@microsoft/adaptivecards-tools";
import * as cron from "node-cron";
import { TeamsFxBot } from "./sdk/bot";
import { adapter } from "./adapter";
import { server } from "./server";
import messageTemplate from "./message.template.json";
const teamsfxBot = new TeamsFxBot(adapter);
const message: Partial<Activity> = {
attachments: [
CardFactory.adaptiveCard(AdaptiveCards.declare(messageTemplate).render({
title: "Notification Test",
message: "This is a notification from TeamsFx bot."
}))
]
};
// HTTP trigger to send notification.
server.post("/api/notify/default", async (req, res) => {
await teamsfxBot.forEachSubscribers(async subscriber => {
await teamsfxBot.notifySubscriber(subscriber, message);
});
res.json({});
});
// Time trigger to send notification.
cron.schedule('*/1 * * * *', async () => {
// send notification every one minutes.
await teamsfxBot.forEachSubscribers(async subscriber => {
await teamsfxBot.notifySubscriber(subscriber, message);
});
});