Install the latest version of VS Code extension Teams Toolkit, and press F5
to launch the app in Teams.
await teamsfxBot.forEachSubscribers(async subscriber => {
await teamsfxBot.notifySubscriber(subscriber, MessageFactory.text(`Hello world!`));
});
Check index.ts for more details.
storage
: specify the storage to save subscribers info, by default it's local file storage, and you could use Azure Blob instead.welcomeMessage
: setup welcome message once bot is install.appSettingsProvider
: Setup notification settings.
Sample usage:
// create TeamsFx Bot with options.
const teamsfxBot = new TeamsFxBot(adapter, {
// You could also use Azure Blob storage to save subscribers info.
storage: new BlobsStorage(process.env.blobConnectionString, process.env.blobContainerName),
welcomeMessage: {
message: MessageFactory.text("Hello, this is notification bot created by TeamsFx.")
},
settingsProvider: new AppSettingsProvider({
commandName: "settings"
})
});
Scheduled job to send notification to the default place (Teams/Group Chat/Personal Chat) where the bot is installed.
Sample usage:
setInterval(async () => {
await teamsfxBot.forEachSubscribers(async subscriber => {
await teamsfxBot.notifySubscriber(subscriber, MessageFactory.text(`Hello world! (this is a scheduled notification.)`));
});
}, 30 * 1000); // every 30 seconds
Sample usage:
await teamsfxBot.forEachSubscribers(async subscriber => {
for (const member of await subscriber.members) {
await teamsfxBot.notifyMember(member, MessageFactory.text(`Hello ${member.account.name}!`));
}
});
Sample usage:
await teamsfxBot.forEachSubscribers(async subscriber => {
for (const channel of await subscriber.channels) {
switch (channel.info.name) {
case "Test":
await teamsfxBot.notifyChannel(channel, MessageFactory.text(`Hello world!`));
break;
default:
// pass
}
}
});
Type bot command settings
in Teams to select the channels that needs to be notified.
Sample usage:
await teamsfxBot.forEachSubscribers(async subscriber => {
const settings = await subscriber.settings;
for (const channel of await subscriber.channels) {
// check if the channel is enabled.
if (settings[channel.info.id]) {
await teamsfxBot.notifyChannel(channel, MessageFactory.text(`Hello world!`));
}
}
});
Sample usage:
await teamsfxBot.forEachSubscribers(async subscriber => {
const channels = await subscriber.channels;
const channel = channels.find(c => c.info.name === "Test");
if (channel) {
// send notification as a new conversation.
const messageId = await teamsfxBot.notifyChannel(channel, MessageFactory.text(`Ping`));
// send notification as a reply to an existing conversation.
await teamsfxBot.replyConversation(channel, messageId, MessageFactory.text(`Pong`));
}
});