send-teams-message
v1.0.7
Published
Send teams message from your nodeJs scripts
Readme
send-teams-message
A lightweight Node.js package that allows you to send messages to Microsoft Teams channels using webhooks.
Installation
npm install send-teams-messageFeatures
- Send messages to Microsoft Teams channels using webhooks
- Support for Adaptive Cards
- TypeScript support
- Automatic message logging
- Simple and intuitive API
Usage
Basic Example
import { sendTeamsMessage } from 'send-teams-message';
const webhookUrl = 'YOUR_TEAMS_WEBHOOK_URL';
const message = {
type: 'AdaptiveCard',
body: [
{
type: 'TextBlock',
text: 'Hello from Node.js!',
size: 'large'
}
],
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
version: '1.0'
};
await sendTeamsMessage(webhookUrl, message);Getting a Webhook URL
- Go to your Teams channel
- Click on the three dots (...) next to the channel name
- Select "Manage channel"
- Go to "Connectors"
- Find "Incoming Webhook" and click "Configure"
- Create a new webhook and copy the URL
Creating Custom Cards
You can create custom Adaptive Cards using the Adaptive Cards Designer. After designing your card:
- Copy the JSON output
- Use it as the
configMsgparameter in thesendTeamsMessagefunction
API Reference
sendTeamsMessage(url: string, configMsg: Record<string, any>): Promise<string>
Sends a message to a Microsoft Teams channel.
Parameters
url(string): The webhook URL of your Teams channelconfigMsg(object): The Adaptive Card configuration object
Returns
- Promise: A string containing the response status and status text
Message Logging
The package automatically logs the last sent message to a file named lastTeamsMsg.txt in your project root directory. This file contains:
- The webhook URL used
- The complete message payload
License
MIT © topkat
