Skip to content

Commit 0f92433

Browse files
author
Adam Warner
authored
Merge pull request #14 from PromoFaux/development
V1.4 release
2 parents e85e0b3 + 70922fc commit 0f92433

23 files changed

+972
-281
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,6 @@ paket-files/
258258

259259
# Python Tools for Visual Studio (PTVS)
260260
__pycache__/
261-
*.pyc
261+
*.pyc
262+
/ManualTesting/config.json
263+
/ManualTests/config.json

ManualTests/Config.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace ManualTests
2+
{
3+
public class Config
4+
{
5+
/// <summary>
6+
/// The incoming webhook URL on the mattermost server
7+
/// </summary>
8+
public string incomingWebHookUrl { get; set; }
9+
/// <summary>
10+
/// For interactive buttons
11+
/// </summary>
12+
public string outgoingWebHookUrl { get; set; }
13+
/// <summary>
14+
/// Channel to post your test messages to
15+
/// </summary>
16+
public string testChannel { get; set; }
17+
}
18+
}

ManualTests/ManualTests.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\Matterhook.NET.MatterhookClient\Matterhook.NET.MatterhookClient.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

ManualTests/Program.cs

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using Matterhook.NET.MatterhookClient;
6+
using Newtonsoft.Json;
7+
8+
namespace ManualTests
9+
{
10+
internal class Program
11+
{
12+
private static void Main(string[] args)
13+
{
14+
//Make sure the file `config.json` exists with a `webhookURL` and `testChannel` properties (copy always)
15+
var _config = LoadConfig();
16+
17+
PostBasicMessage(_config);
18+
PostAdvancedMessage(_config);
19+
PostButtonsMessage(_config);
20+
PostMenuMessage(_config);
21+
PostChannelsMenuMessage(_config);
22+
PostUsersMenuMessage(_config);
23+
}
24+
25+
public static void PostBasicMessage(Config config)
26+
{
27+
var client = new MatterhookClient(config.incomingWebHookUrl);
28+
var message = new MattermostMessage
29+
{
30+
Text = "Hello, I was posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
31+
Channel = config.testChannel,
32+
Username = "Awesome-O-Matic"
33+
};
34+
Task.WaitAll(client.PostAsync(message));
35+
}
36+
37+
public static void PostAdvancedMessage(Config config)
38+
{
39+
var client = new MatterhookClient(config.incomingWebHookUrl);
40+
var message = new MattermostMessage
41+
{
42+
Text = "Hello, I was posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
43+
Channel = config.testChannel,
44+
Username = "Awesome-O-Matic",
45+
IconUrl =
46+
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",
47+
48+
Attachments = new List<MattermostAttachment>
49+
{
50+
new MattermostAttachment
51+
{
52+
Fallback = "test",
53+
Color = "#FF8000",
54+
Pretext = "This is optional pretext that shows above the attachment.",
55+
Text =
56+
"This is the text of the attachment. It should appear just above an image of the Mattermost logo. The left border of the attachment should be colored orange, and below the image it should include additional fields that are formatted in columns. At the top of the attachment, there should be an author name followed by a bolded title. Both the author name and the title should be hyperlinks.",
57+
AuthorName = "Mattermost",
58+
AuthorIcon = "http://www.mattermost.org/wp-content/uploads/2016/04/icon_WS.png",
59+
AuthorLink = "http://www.mattermost.org/",
60+
Title = "Example Attachment",
61+
TitleLink = "http://docs.mattermost.com/developer/message-attachments.html",
62+
63+
Fields = new List<MattermostField>
64+
{
65+
new MattermostField
66+
{
67+
Short = false,
68+
Title = "Long Field.",
69+
Value =
70+
"Testing with a very long piece of text that will take up the whole width of the table. And then some more text to make it extra long."
71+
},
72+
new MattermostField
73+
{
74+
Short = true,
75+
Title = "Column One",
76+
Value = "Testing"
77+
},
78+
new MattermostField
79+
{
80+
Short = true,
81+
Title = "Column Two",
82+
Value = "Testing"
83+
},
84+
new MattermostField
85+
{
86+
Short = false,
87+
Title = "Another Field",
88+
Value = "Testing"
89+
}
90+
},
91+
ImageUrl = "http://www.mattermost.org/wp-content/uploads/2016/03/logoHorizontal_WS.png"
92+
}
93+
}
94+
};
95+
Task.WaitAll(client.PostAsync(message));
96+
}
97+
98+
public static void PostButtonsMessage(Config config)
99+
{
100+
var client = new MatterhookClient(config.incomingWebHookUrl);
101+
var message = new MattermostMessage
102+
{
103+
Text = "Message Text Example",
104+
Channel = config.testChannel,
105+
Username = "Awesome-O-Matic",
106+
IconUrl =
107+
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",
108+
Attachments = new List<MattermostAttachment>
109+
{
110+
new MattermostAttachment
111+
{
112+
Text = "Attachment Text Example",
113+
Actions = new List<IMattermostAction>
114+
{
115+
new MattermostAction
116+
{
117+
Name = "Merge",
118+
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
119+
new Dictionary<string, object>
120+
{
121+
{"pr", 1234},
122+
{"action", "merge"}
123+
})
124+
},
125+
new MattermostAction
126+
{
127+
Name = "Notify",
128+
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
129+
new Dictionary<string, object>
130+
{
131+
{"text", "code was pushed."}
132+
})
133+
}
134+
}
135+
}
136+
}
137+
};
138+
Task.WaitAll(client.PostAsync(message));
139+
}
140+
141+
public static void PostMenuMessage(Config config)
142+
{
143+
var client = new MatterhookClient(config.incomingWebHookUrl);
144+
var message = new MattermostMessage
145+
{
146+
Text =
147+
"This is a menu message posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
148+
Channel = config.testChannel,
149+
Username = "Awesome-O-Matic",
150+
IconUrl =
151+
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",
152+
153+
Attachments = new List<MattermostAttachment>
154+
{
155+
new MattermostAttachment
156+
{
157+
Pretext = "This is optional pretext that shows above the attachment.",
158+
Text = "This is the text of the attachment. ",
159+
Actions = new List<IMattermostAction>
160+
{
161+
new MattermostMessageMenu
162+
{
163+
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
164+
new Dictionary<string, object>
165+
{
166+
{"text", "Some data to send always."}
167+
}),
168+
Name = "Test",
169+
Options = new List<MessageMenuOption>
170+
{
171+
new MessageMenuOption("Option1", "value1"),
172+
new MessageMenuOption("Option2", "value2"),
173+
new MessageMenuOption("Option3", "value3")
174+
}
175+
}
176+
}
177+
}
178+
}
179+
};
180+
Task.WaitAll(client.PostAsync(message));
181+
}
182+
183+
public static void PostChannelsMenuMessage(Config config)
184+
{
185+
var client = new MatterhookClient(config.incomingWebHookUrl);
186+
var message = new MattermostMessage
187+
{
188+
Text =
189+
"This is a message menu with channels source posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
190+
Channel = config.testChannel,
191+
Username = "Awesome-O-Matic",
192+
IconUrl =
193+
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",
194+
195+
Attachments = new List<MattermostAttachment>
196+
{
197+
new MattermostAttachment
198+
{
199+
Pretext = "This is optional pretext that shows above the attachment.",
200+
Text = "This is the text of the attachment. ",
201+
Actions = new List<IMattermostAction>
202+
{
203+
new MattermostMessageMenuChannels
204+
{
205+
Name = "channels",
206+
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
207+
new Dictionary<string, object>
208+
{
209+
{"active", "false"}
210+
})
211+
}
212+
}
213+
}
214+
}
215+
};
216+
Task.WaitAll(client.PostAsync(message));
217+
}
218+
219+
public static void PostUsersMenuMessage(Config config)
220+
{
221+
var client = new MatterhookClient(config.incomingWebHookUrl);
222+
var message = new MattermostMessage
223+
{
224+
Text =
225+
"This is a message menu with users source posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
226+
Channel = config.testChannel,
227+
Username = "Awesome-O-Matic",
228+
IconUrl =
229+
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",
230+
231+
Attachments = new List<MattermostAttachment>
232+
{
233+
new MattermostAttachment
234+
{
235+
Pretext = "This is optional pretext that shows above the attachment.",
236+
Text = "This is the text of the attachment. ",
237+
Actions = new List<IMattermostAction>
238+
{
239+
new MattermostMessageMenuUsers
240+
{
241+
Name = "Users",
242+
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
243+
new Dictionary<string, object>
244+
{
245+
{"mood", "sad"}
246+
})
247+
}
248+
}
249+
}
250+
}
251+
};
252+
Task.WaitAll(client.PostAsync(message));
253+
}
254+
255+
public static Config LoadConfig()
256+
{
257+
var configFile = "config.json";
258+
if (! File.Exists(configFile))
259+
{
260+
Console.WriteLine("No Config file found, make sure it exists first");
261+
Environment.Exit(1);
262+
return null;
263+
}
264+
265+
var jsonStr = File.ReadAllText(configFile);
266+
return JsonConvert.DeserializeObject<Config>(jsonStr);
267+
}
268+
}
269+
}

Matterhook.NET.MatterhookClient.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1111
README.md = README.md
1212
EndProjectSection
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManualTests", "ManualTests\ManualTests.csproj", "{7A252949-3DCA-454C-9436-1A953C1FC734}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{52ED8E2C-7DA3-4D7C-B14F-5AC25934ADB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{52ED8E2C-7DA3-4D7C-B14F-5AC25934ADB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{52ED8E2C-7DA3-4D7C-B14F-5AC25934ADB7}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{7A252949-3DCA-454C-9436-1A953C1FC734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{7A252949-3DCA-454C-9436-1A953C1FC734}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{7A252949-3DCA-454C-9436-1A953C1FC734}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{7A252949-3DCA-454C-9436-1A953C1FC734}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Matterhook.NET.MatterhookClient
2+
{
3+
/// <summary>
4+
/// Interface for a mattermost message action
5+
/// </summary>
6+
public interface IMattermostAction
7+
{
8+
/// <summary>
9+
/// Integration used by this action.
10+
/// </summary>
11+
MattermostIntegration Integration { get; set; }
12+
13+
/// <summary>
14+
/// Action's name.
15+
/// </summary>
16+
string Name { get; set; }
17+
}
18+
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net452;net461;netcoreapp1.0;netcoreapp2.0;netstandard2.0</TargetFrameworks>
5-
<Authors>Promofaux</Authors>
4+
<TargetFrameworks>net452;net461;net471;netcoreapp1.0;netcoreapp2.1;netstandard2.0</TargetFrameworks>
5+
<Authors>Promofaux, rgomez90</Authors>
66
<Company />
77
<Description>Simple HTTPclient to post messages to your Mattermost server</Description>
88
<Copyright>Promofaux</Copyright>
@@ -11,13 +11,14 @@
1111
<RepositoryUrl>https://github.com/PromoFaux/Matterhook.NET.MatterhookClient</RepositoryUrl>
1212
<AssemblyVersion>1.0.0.0</AssemblyVersion>
1313
<FileVersion>1.0.0.0</FileVersion>
14-
<Version>1.0.4</Version>
14+
<Version>1.0.4-asdad-cxcxc-2</Version>
1515
<PackageId>Matterhook.NET.MatterhookClient</PackageId>
16+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1617
</PropertyGroup>
1718

1819
<ItemGroup>
19-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
20-
<PackageReference Include="System.Net.Http" Version="4.3.2" />
20+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
21+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
2122
</ItemGroup>
2223

2324
</Project>

0 commit comments

Comments
 (0)