GithubHelp home page GithubHelp logo

mybotapp's Introduction

TeamsFx Notification

Try It

Install the latest version of VS Code extension Teams Toolkit, and press F5 to launch the app in Teams.

Basic Usage

await teamsfxBot.forEachSubscribers(async subscriber => {
  await teamsfxBot.notifySubscriber(subscriber, MessageFactory.text(`Hello world!`));
});

Check index.ts for more details.

Options to create TeamsFx Bot

  • 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"
  })
});

More Usages

Case 1: Time trigger for the notification.

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

Case 2: Send notification to all the members of the subscribed team/group chat.

Sample usage:

await teamsfxBot.forEachSubscribers(async subscriber => {
  for (const member of await subscriber.members) {
    await teamsfxBot.notifyMember(member, MessageFactory.text(`Hello ${member.account.name}!`));
  }
});

Case 3: send notification to particular channel of the subscribed team.

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
    }
  }
});

Case 4: send notification to the Teams channels which can be configured.

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!`));
    }
  }
});

Case 5: reply to particular conversation in a subscribed Teams channel.

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`));
  }
});

mybotapp's People

Contributors

qinezh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.