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

@verkkokauppacom/teams-logger

v4.0.0

Published

Send messages to Microsoft Teams via a custom incoming webhook

Downloads

27

Readme

@verkkokauppacom/teams-logger

@verkkokauppacom/teams-logger version @verkkokauppacom/teams-logger monthly downloads @verkkokauppacom/teams-logger dependency status @verkkokauppacom/teams-logger GitHub Stars

A Node.js application for sending messages to Microsoft Teams via a custom incoming webhook.

The simple usage is to post messages formatted in Markdown, with optional link buttons that are added to the bottom of messages. More advanced usage is possible by sending the entire Office 365 Connector JSON.

Table of contents

  1. Installation
  2. Usage
    1. Configuration
    2. Simple CLI
    3. Advanced CLI
    4. Node.js API
    5. Docker
  3. Development
    1. Publishing

Installation

# npm
npm install --global @verkkokauppacom/teams-logger

# yarn
yarn add --global @verkkokauppacom/teams-logger

# Docker
docker pull ghcr.io/verkkokauppacom/teams-logger

Usage

❯ npx teams-logger --help
teams-logger [message]

Post Markdown to Microsoft Teams

Commands:
  teams-logger [message]     Post Markdown to Microsoft Teams          [default]
  teams-logger raw [json]    Post JSON message to Microsoft Teams

Positionals:
  message  Markdown message.

Options:
      --help           Show help                                       [boolean]
      --version        Show version number                             [boolean]
  -w, --webhook        Microsoft Teams Webhook [TEAMS_LOGGER_WEBHOOK] [required]
  -t, --timeout        Timeout in seconds before fail                   [number]
      --allow-failure  Exit with code 0 when failed   [boolean] [default: false]
  -l, --link           Add link buttons with Markdown syntax [Title](url)[array]

Configuration

The only required configuration is the Webhook URL for posting messages to a certain channel. After creating a Webhook connector to a channel, save its webhook URL and specify it to teams-logger via the TEAMS_LOGGER_WEBHOOK env variable or the --webhook command line flag.

Simple CLI

Post a message to a channel:

export WEBHOOK_URL="https://example.webhook.office.com/webhookb2/XXX/IncomingWebhook/YYY"
teams-logger "Hello, world\!"

Post Markdown to a channel:

export WEBHOOK_URL="https://example.webhook.office.com/webhookb2/XXX/IncomingWebhook/YYY"
echo "# Hello, world\!
----
This is the message body.
" | teams-logger

Add Link button to a message:

teams-logger "Click the button\!" --button "[The Button](https://example.com)" --webhook "https://example.webhook.office.com/webhookb2/XXX/IncomingWebhook/YYY"

Advanced CLI

You can learn how to create custom messages by following the Post an actionable message card to an Office 365 group tutorial:

export WEBHOOK_URL="https://example.webhook.office.com/webhookb2/XXX/IncomingWebhook/YYY"
cat my_json_message.json | teams-logger raw

Node.js API

teams-logger can be used through Node.js via the exported simpleLogger or rawLogger:

import { simpleLogger } from '@verkkokauppacom/teams-logger'

interface SimpleArgs {
    allowFailure?: boolean /** Whether to exit with code 0 even when request failed */
    links?: { label: string; href: string }[] /** Link buttons to add to the message */
    message: string /** Message formatted in Markdown */
    timeout?: number /** HTTP Request timeout */
    webhook: string /** Office 365 Incoming Webhook URL */
}

try {
    await simpleLogger({ allowFailure, links, message, timeout, webhook }: SimpleArgs)
} catch (error) {
    console.error(error)
}
import { rawLogger } from '@verkkokauppacom/teams-logger'

interface RawArgs {
    allowFailure?: boolean /** Whether to exit with code 0 even when request failed */
    json: SerializableObject /** JSON Message as JavaScript object */
    timeout?: number /** HTTP Request timeout in seconds */
    webhook: string /** Office 365 Incoming Webhook URL */
}

try {
    await rawLogger({ allowFailure, json, timeout, webhook }: RawArgs)
} catch (error) {
    console.error(error)
}

Docker

This repository contains a Dockerfile for building a small image based on node:alpine. The API of the container is the same as the cli:

❯ docker run ghcr.io/verkkokauppacom/teams-logger --help

Development

Publishing

This project adheres to the Conventional Commits specification. To create a new version:

  1. Run npm run version locally, and wait for the script to run
  2. If all prerelease checks pass, a new commit containing the version number bump, CHANGELOG.md and git tag will be created
  3. Push the new commit and tag by running git push --follow-tags
  4. The GitHub Actions will take over and publish new npm packages and Docker images