send2teams
Small CLI tool used to submit messages to Microsoft Teams.
Project home
See our GitHub repo for the latest
code, to file an issue or submit improvements for review and potential
inclusion into the project.
Overview
First of all, many thanks to the developer/contributors of the original
dasrick/go-teams-notify
package. While this project now uses a fork of that
original project, this project would likely not have been possible without the
efforts of the original developer.
This project provides:
send2teams
- Small CLI tool used to submit messages to Microsoft Teams.
send2teams
is
intended for use by Nagios, scripts or other actions that may need to submit
pass/fail results to a MS Teams channel.
Prior to v0.4.7
, this project also provided a teams
subpackage. All of
that functionality has since been migrated to the atc0005/go-teams-notify
project. All client code for that package has been updated to use
atc0005/go-teams-notify
in place of the previous teams
subpackage of this
project.
Features
- single binary, no outside dependencies
- minimal configuration
- very few build dependencies
- optional conversion of messages with Windows, Mac or Linux newlines to
<br>
to increase compatibility with Teams formatting
- message delivery retry support with retry and retry delay values
configurable via flag
Changelog
See the CHANGELOG.md
file for the changes associated with
each release of this application. Changes that have been merged to master
,
but not yet an official release may also be noted in the file under the
Unreleased
section. A helpful link to the Git commit history since the last
official release is also provided for further review.
Requirements
- Go 1.12+ (for building)
- GCC
- if building with custom options (as the provided
Makefile
does)
make
- if using the provided
Makefile
Tested using:
- Go 1.13+
- Windows 10 Version 1903
- Ubuntu Linux 16.04+
How to install it
- Download Go
- Install Go
- Clone the repo
cd /tmp
git clone https://github.com/atc0005/send2teams
cd send2teams
- Install dependencies (optional)
- for Ubuntu Linux
sudo apt-get install make gcc
- for CentOS Linux
sudo yum install make gcc
- Build
- for current operating system
go build -mod=vendor ./cmd/send2teams/
- forces build to use bundled dependencies in top-level
vendor
folder
- for all supported platforms (where
make
is installed)
- for Windows
- for Linux
- Copy the applicable binary to whatever systems needs to run it
- if using
Makefile
: look in /tmp/release_assets/send2teams/
- if using
go build
: look in /tmp/send2teams/
Configuration Options
Webhook URLs
Valid webhook URLs for Microsoft Teams use one of several (confirmed) FQDNs
patterns:
outlook.office.com
outlook.office365.com
*.webhook.office.com
- e.g.,
example.webhook.office.com
Using a webhook URL with any of these FQDN patterns appears to give identical
results.
Here are complete, equivalent example webhook URLs from Microsoft's
documentation using the FQDNs above:
All of these patterns should pass the default validation applied to
user-specified webhook URLs.
How to create a webhook URL (Connector)
- Open Microsoft Teams
- Navigate to the channel where you wish to receive incoming messages from
this application
- Select
⋯
next to the channel name and then choose Connectors.
- Scroll through the list of Connectors to Incoming Webhook, and choose Add.
- Enter a name for the webhook, upload an image to associate with data from
the webhook, and choose Create.
- Copy the webhook URL to the clipboard and save it. You'll need the webhook
URL for sending information to Microsoft Teams.
- NOTE: While you can create another easily enough, you should treat this
webhook URL as sensitive information as anyone with this unique URL is
able to send messages (without authentication) into the associated
channel.
- Choose Done.
Credit:
docs.microsoft.com,
gist comment from
shadabacc3934
Command-line
Currently send2teams
only supports command-line configuration flags.
Requests for other configuration sources will be considered.
Flag |
Required |
Default |
Possible |
Description |
h , help |
No |
N/A |
N/A |
Display Help; show available flags. |
v , version |
No |
false |
true , false |
Whether to display application version and then immediately exit application. |
channel |
Yes |
|
valid Microsoft Teams channel name |
The target channel where we will send a message. |
color |
No |
#832561 |
valid hex color code with leading # |
The hex color code used to set the desired trim color on submitted messages. |
message |
Yes |
|
valid message string |
The (optionally) Markdown-formatted message to submit. |
team |
Yes |
|
valid Microsoft Teams team name |
The name of the Team containing our target channel. |
title |
Yes |
|
valid title string |
The title for the message to submit. |
url |
Yes |
|
valid Microsoft Office 365 Webhook URL |
The Webhook URL provided by a pre-configured Connector. |
verbose |
No |
false |
true , false |
Whether detailed output should be shown after message submission success or failure |
silent |
No |
false |
true , false |
Whether ANY output should be shown after message submission success or failure |
convert-eol |
No |
false |
true , false |
Whether messages with Windows, Mac and Linux newlines are updated to use break statements before message submission |
retries |
No |
2 |
positive whole number |
The number of attempts that this application will make to deliver messages before giving up. |
retries-delay |
No |
2 |
positive whole number |
The number of seconds that this application will wait before making another delivery attempt. |
Examples
One-off
This example illustrates the basics of using the application to submit a
single message. This can serve as a starting point for use with Nagios,
scripts or any other tool that calls out to others in order to perform its
tasks.
./send2teams.exe -silent -channel "Testing" -message "Testing from command-line!" -title "Another test" -color "#832561" -url "https://outlook.office.com/webhook/www@xxx/IncomingWebhook/yyy/zzz"
Remove the -silent
flag in order to see pass or failure output, otherwise
look at the exit code ($?
) or Microsoft Teams to determine results.
Accidentally typing the wrong flag results in a message like this one:
flag provided but not defined: -fake-flag
License
From the LICENSE file:
MIT License
Copyright 2021 Adam Chalkley
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
References
-
Related projects
-
Webhook / Office 365
-
General Golang