Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrebaltieri/teams.webhooks
Helper to send messages to Microsoft Teams through webhooks
https://github.com/andrebaltieri/teams.webhooks
Last synced: 2 months ago
JSON representation
Helper to send messages to Microsoft Teams through webhooks
- Host: GitHub
- URL: https://github.com/andrebaltieri/teams.webhooks
- Owner: andrebaltieri
- Created: 2021-07-23T17:37:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-23T18:04:41.000Z (over 3 years ago)
- Last Synced: 2024-10-04T12:45:23.356Z (3 months ago)
- Language: C#
- Size: 30.3 KB
- Stars: 29
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Microsoft Teams - Send a message to a channel
This package will help you to send a message to a channel in Microsoft Teams.## Creating a WebHook
The first step you need to do is create an **Incoming WebHook** in your Teams channel. Just open a teams channel and click on the **..** button on top right corner and select **Connectors**.On the new screen, search for **Incoming WebHooks** and click on **Add**. Copy the generated URL.
## Installing the package
To install the package, run the following command in the root of your project:
```
dotnet add package Teams.WebHooks --version 1.0.0
```## Creating a message
Moving to your code, first we`ll need to create a card like this:
```csharp
var card = new Message();
card.ThemeColor = "8625D2";
card.Summary = "Some summary here";
```### Sections
A card can be composed of many sections and we need at least one section to send a message.```csharp
card.Sections.Add(new Section
{
ActivityTitle = "Section Title here",
ActivitySubtitle = "Section Subtitle here",
ActivityImage = "https://some-image.png",
Markdown = true,
});
```#### Facts
You can have as many facts as you want, they will be shown in a separeted place of the card.```csharp
card.Sections.Add(new Section
{
ActivityTitle = "Section Title here",
ActivitySubtitle = "Section Subtitle here",
ActivityImage = "https://some-image.png",
Markdown = true,
Facts = new List()
{
new()
{
Name = "Assigned to",
Value = "[email protected]"
},
new()
{
Name = "Due date",
Value = "27/07/2021"
},
new()
{
Name = "Status",
Value = "Active"
}
},
});```
## Potential Actions
Cards can have potential actions, which are actions that can be taken when clicking on the buttons.```csharp
card.PotentialAction.Add(new PotentialAction
{
Name = "Comentar",
Inputs = new List()
{
new() {Id = "email", Title = "Email here", Type = "TextInput", IsMultiline = false},
new() {Id = "date", Title = "Date", Type = "DateInput", IsMultiline = false},
new InputMultiChoice()
{
Id = "mult", Title = "Data", Type = "DateInput", IsMultiline = false, Choices =
new List()
{
new() {Display = "item 1", Value = "1"},
new() {Display = "item 2", Value = "2"},
}
},
},
Actions = new List()
{
new()
{
Body = "comment={{email.value}}", // Capture the value of the input
Name = "Aprove",
Target = "https://your-api-endpoint"
}
}
});
```## Sending the message
```csharp
var result = await MessageClient.SendAsync(YOUR_WEBHOOK_URL, card);
Console.WriteLine(result);
```