Skip to content

Commit bc6c31d

Browse files
committed
Start Overhaul ReadMe for 1.4
See #24
1 parent 8885596 commit bc6c31d

File tree

1 file changed

+77
-17
lines changed

1 file changed

+77
-17
lines changed

README.md

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,47 @@
33

44
# Matterhook.NET.MatterhookClient
55

6-
Matterhook.NET.MatterhookClient is a simple webhook client to post messages to your Mattermost server using Webhooks.
6+
Matterhook.NET.MatterhookClient is a simple webhook client to post messages to your Mattermost server using Webhooks. It supports message buttons and menus (menus are only supported in Mattermost v5.4+).
77

8-
## Usage
8+
## Installation
99

10-
You can install the package from nuget using `Install-Package Matterhook.NET.MatterhookClient`,
10+
You can install the latest release by installing the package from NuGet using `Install-Package Matterhook.NET.MatterhookClient`.
1111

1212
Alternatively, clone/fork this repo and compile the source yourself.
1313

14-
### Simple Message:
15-
16-
```C#
14+
## Basic usage
1715

16+
Using this library is really easy. Just create a new MatterhookClient
17+
```csharp
1818
var client = new MatterhookClient("https://your.webhook.url/0892340923432");
19+
```
20+
21+
Create your message
22+
23+
```csharp
24+
var message = new MattermostMessage()
25+
{
26+
//MessageOptions
27+
};
28+
```
29+
30+
Post your message
31+
32+
```csharp
33+
Task.WaitAll(client.PostAsync(message));
34+
```
35+
36+
## Message Types
37+
38+
### Simple Message
1939

40+
```C#
2041
var message = new MattermostMessage
2142
{
2243
Text = "Hello, I was posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
2344
Channel = "general",
2445
Username = "Awesome-O-Matic"
2546
};
26-
27-
Task.WaitAll(client.PostAsync(message));
28-
2947
```
3048

3149
![](http://i.imgur.com/jLZsP4E.png)
@@ -35,8 +53,6 @@ Task.WaitAll(client.PostAsync(message));
3553
> Using example template from [Mattermost docs](https://docs.mattermost.com/developer/message-attachments.html#example-message-attachment)
3654
3755
```C#
38-
var client = new MatterhookClient("https://your.webhook.url/0892340923432");
39-
4056
var message = new MattermostMessage
4157
{
4258
Text = "Hello, I was posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
@@ -91,17 +107,13 @@ var message = new MattermostMessage
91107
}
92108
}
93109
};
94-
95-
Task.WaitAll(client.PostAsync(message));
96-
97110
```
98111

99112
![](https://i.imgur.com/n5ecwYb.png)
100113

101114
### Message with interactive buttons
102115

103116
```C#
104-
var client = new MatterhookClient("http://mattermost.url");
105117
var message = new MattermostMessage()
106118
{
107119
Text = "Message Text Example",
@@ -135,8 +147,8 @@ var message = new MattermostMessage()
135147
}
136148
}
137149
};
138-
Task.WaitAll(client.PostAsync(message));
139150
```
151+
140152
![](https://i.imgur.com/Eb8Ne2g.png)
141153

142154
Clicking `Merge` will trigger a POST request to `https://matterhook.example.com/merge` with following body
@@ -160,4 +172,52 @@ and clicking `Notify` will trigger a POST request to `https://matterhook.example
160172
"text": "New code was pushed."
161173
}
162174
}
163-
```
175+
```
176+
177+
### Message with menu buttons (supported in Mattermost 5.4+)
178+
179+
You also can post messages with menu buttons. It will post a message with a dropdown button where the users can select a value, which will be posted to the target integration.
180+
181+
Just add an attachment to your message as follows:
182+
183+
```csharp
184+
Attachments = new List<MattermostAttachment>
185+
{
186+
new MattermostAttachment
187+
{
188+
Pretext = "This is optional pretext that shows above the attachment.",
189+
Text = "This is the text of the attachment. ",
190+
Actions = new List<IMattermostAction>
191+
{
192+
new MattermostMessageMenu
193+
{
194+
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
195+
new Dictionary<string, object>
196+
{
197+
{"text", "Some data to send always."}
198+
}),
199+
Name = "Test",
200+
Options = new List<MessageMenuOption>
201+
{
202+
new MessageMenuOption("Option1", "value1"),
203+
new MessageMenuOption("Option2", "value2"),
204+
new MessageMenuOption("Option3", "value3")
205+
}
206+
}
207+
}
208+
}
209+
}
210+
```
211+
212+
You can add as many attachments of any type to a message as you want. Message menus and buttons can be used to for ex.:
213+
214+
* Mark a task complete in your project management tracker
215+
* Conduct a customer survey or a poll
216+
* Initiate a command to merge a branch into a release
217+
218+
## Contributing
219+
220+
We welcome everyone who wants to contribute to this repo!
221+
For it, just open an issue with your intention or make a comment in some open issue you would like to work on.
222+
223+

0 commit comments

Comments
 (0)