npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

msteams-message-cards

v1.0.1

Published

A javascript library to create and message cards and send them to a MS Teams webhook.

Downloads

6

Readme

MS Teams Message Cards

npm Package Version License MIT GitHub Repo Native Typescript Support Coveralls Coverage GitHub Workflow Status

A javascript library that creates message cards for MS Teams and sends them to a webhook (aka "connector").

It uses the legacy actionable message card format.

This library only supports basic features of message cards (just the ones I needed). If you are missing a feature, feel free to create an issue or a pull request.

Supported Message Card Features:

  • title
  • text
  • summary
  • themeColor (can be set via a color name using color-name-to-code)
  • potentialAction (URL buttons only)
  • sections, containing:
    • text
    • activityTitle
    • activitySubtitle
    • activityText
    • activityImage
    • potentialAction (URL buttons only)
    • facts

Installation

This library is published to npm registry as msteams-message-cards.

You can install it:

# with npm
npm install --save msteams-message-cards

# with yarn
yarn add msteams-message-cards

ℹ️ HINT: This library is a pure ESM package. (You may want to read this.)

Usage Examples

import {
  createMessageCardPayload,
  sendMessageCard
} from 'msteams-message-cards';

const webhookURL = 'https://my-teams.com/webhook/123/';

// most simple usage
try {
  await sendMessageCard({
    webhookURL,
    text: 'Hello World!'
  });
} catch (error) {
  console.error(error);
}

// create and log payload before sending
try {
  const payload = createMessageCardPayload({ text: 'Hello World!' });
  console.log(`Message Payload:\n${JSON.stringify(payload, null, 2)}`);
  await sendMessageCard({ webhookURL, payload });
} catch (error) {
  console.error(error);
}

// using some more features
try {
  await sendMessageCard({
    webhookURL,
    title: 'This is great!',
    text: "And here's my awesome message.",
    summary: 'Awesome summary!',
    color: 'dodger blue',
    buttons: [{ label: 'More Awesomeness', url: 'https://awesome.com/' }],
    sections: [
      {
        facts: [
          { name: '1', value: 'Foo' },
          { name: '2', value: 'Bar' },
          { name: '3', value: 'Baz' }
        ]
      }
    ]
  });
} catch (error) {
  console.error(error);
}

API

sendMessageCard

async function sendMessageCard(options: Options): Promise<void>;

Options

type Options = {
  webhookURL: string;
  payload?: Payload;
} & PayloadOptions;
  • webhookURL: string (required)
    …defines the webhook URL for the MS Teams connector.

  • payload?: Payload (optional)
    …defines the fully formatted payload to send.
    Only required if there are no additional payload options present from which a payload could be generated.

The options for sendMessageCard can also include all payload options.

createMessageCardPayload

function createMessageCardPayload(options: PayloadOptions): Payload;

Payload Options

interface PayloadOptions {
  summary?: string;
  title?: string;
  text?: string;
  color?: string;
  buttons?: Button[];
  sections?: Section[];
}

type Button = { label: string; url: string } | [string, string];

interface Section {
  text?: string;
  buttons?: Button[];
  facts?: Fact[];
  activity?: Activity;
}

type Fact = { name: string; value: string } | [string, string];

interface Activity {
  title?: string;
  subtitle?: string;
  text?: string;
  image?: string;
}

For a valid minimum payload, at least text or summary needs to be present.

See also the official documentation for legacy actionable message cards for more details about the different message card options.

  • summary?: string
    …defines the message card summary. This is should be a one-liner and it used in Outlook notifications.

  • title?: string
    …defines the message card title.

  • text?: string
    …defines the message card text. It can contain basic HTML and CSS.

  • color?: string
    …defines the message card theme color. Should be either a color hex code or a color name that can be interpreted by color-name-to-code.

  • buttons?: Button[]
    …defines the message card buttons. It should be an array of either objects containing label:string and url:string or arrays where the first element is used as label and the second as URL.

  • sections?: Section[]
    …defines one or more message card sections with multiple optional features, of which at least one needs to be present:

    • text?: string
      …defines the section text.

    • buttons?: string
      …defines the section buttons. It should be an array of either objects containing label:string and url:string or arrays where the first element is used as label and the second as URL.

    • facts?: string
      …defines the facts table of a section. It should be an array of either objects containing name:string and value:string or arrays where the first element it used as name and the second as value.

    • activity?: Activity
      …defines an activity section which is suitable to represent and article or post. It's defined using an object with the following properties:

      • title?: string
        …defines the title for the activity.

      • subtitle?: string
        …defines the subtitle for the activity.

      • text?: string
        …defines the text for the activity.

      • image?: string
        …defines the image for the activity.

License

MIT © Simon Lepel