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+ }
0 commit comments