Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,6 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
/ManualTesting/config.json
/ManualTests/config.json
18 changes: 18 additions & 0 deletions ManualTests/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ManualTests
{
public class Config
{
/// <summary>
/// The incoming webhook URL on the mattermost server
/// </summary>
public string incomingWebHookUrl { get; set; }
/// <summary>
/// For interactive buttons
/// </summary>
public string outgoingWebHookUrl { get; set; }
/// <summary>
/// Channel to post your test messages to
/// </summary>
public string testChannel { get; set; }
}
}
12 changes: 12 additions & 0 deletions ManualTests/ManualTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Matterhook.NET.MatterhookClient\Matterhook.NET.MatterhookClient.csproj" />
</ItemGroup>

</Project>
269 changes: 269 additions & 0 deletions ManualTests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Matterhook.NET.MatterhookClient;
using Newtonsoft.Json;

namespace ManualTests
{
internal class Program
{
private static void Main(string[] args)
{
//Make sure the file `config.json` exists with a `webhookURL` and `testChannel` properties (copy always)
var _config = LoadConfig();

PostBasicMessage(_config);
PostAdvancedMessage(_config);
PostButtonsMessage(_config);
PostMenuMessage(_config);
PostChannelsMenuMessage(_config);
PostUsersMenuMessage(_config);
}

public static void PostBasicMessage(Config config)
{
var client = new MatterhookClient(config.incomingWebHookUrl);
var message = new MattermostMessage
{
Text = "Hello, I was posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
Channel = config.testChannel,
Username = "Awesome-O-Matic"
};
Task.WaitAll(client.PostAsync(message));
}

public static void PostAdvancedMessage(Config config)
{
var client = new MatterhookClient(config.incomingWebHookUrl);
var message = new MattermostMessage
{
Text = "Hello, I was posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
Channel = config.testChannel,
Username = "Awesome-O-Matic",
IconUrl =
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",

Attachments = new List<MattermostAttachment>
{
new MattermostAttachment
{
Fallback = "test",
Color = "#FF8000",
Pretext = "This is optional pretext that shows above the attachment.",
Text =
"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.",
AuthorName = "Mattermost",
AuthorIcon = "http://www.mattermost.org/wp-content/uploads/2016/04/icon_WS.png",
AuthorLink = "http://www.mattermost.org/",
Title = "Example Attachment",
TitleLink = "http://docs.mattermost.com/developer/message-attachments.html",

Fields = new List<MattermostField>
{
new MattermostField
{
Short = false,
Title = "Long Field.",
Value =
"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."
},
new MattermostField
{
Short = true,
Title = "Column One",
Value = "Testing"
},
new MattermostField
{
Short = true,
Title = "Column Two",
Value = "Testing"
},
new MattermostField
{
Short = false,
Title = "Another Field",
Value = "Testing"
}
},
ImageUrl = "http://www.mattermost.org/wp-content/uploads/2016/03/logoHorizontal_WS.png"
}
}
};
Task.WaitAll(client.PostAsync(message));
}

public static void PostButtonsMessage(Config config)
{
var client = new MatterhookClient(config.incomingWebHookUrl);
var message = new MattermostMessage
{
Text = "Message Text Example",
Channel = config.testChannel,
Username = "Awesome-O-Matic",
IconUrl =
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",
Attachments = new List<MattermostAttachment>
{
new MattermostAttachment
{
Text = "Attachment Text Example",
Actions = new List<IMattermostAction>
{
new MattermostAction
{
Name = "Merge",
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
new Dictionary<string, object>
{
{"pr", 1234},
{"action", "merge"}
})
},
new MattermostAction
{
Name = "Notify",
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
new Dictionary<string, object>
{
{"text", "code was pushed."}
})
}
}
}
}
};
Task.WaitAll(client.PostAsync(message));
}

public static void PostMenuMessage(Config config)
{
var client = new MatterhookClient(config.incomingWebHookUrl);
var message = new MattermostMessage
{
Text =
"This is a menu message posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
Channel = config.testChannel,
Username = "Awesome-O-Matic",
IconUrl =
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",

Attachments = new List<MattermostAttachment>
{
new MattermostAttachment
{
Pretext = "This is optional pretext that shows above the attachment.",
Text = "This is the text of the attachment. ",
Actions = new List<IMattermostAction>
{
new MattermostMessageMenu
{
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
new Dictionary<string, object>
{
{"text", "Some data to send always."}
}),
Name = "Test",
Options = new List<MessageMenuOption>
{
new MessageMenuOption("Option1", "value1"),
new MessageMenuOption("Option2", "value2"),
new MessageMenuOption("Option3", "value3")
}
}
}
}
}
};
Task.WaitAll(client.PostAsync(message));
}

public static void PostChannelsMenuMessage(Config config)
{
var client = new MatterhookClient(config.incomingWebHookUrl);
var message = new MattermostMessage
{
Text =
"This is a message menu with channels source posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
Channel = config.testChannel,
Username = "Awesome-O-Matic",
IconUrl =
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",

Attachments = new List<MattermostAttachment>
{
new MattermostAttachment
{
Pretext = "This is optional pretext that shows above the attachment.",
Text = "This is the text of the attachment. ",
Actions = new List<IMattermostAction>
{
new MattermostMessageMenuChannels
{
Name = "channels",
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
new Dictionary<string, object>
{
{"active", "false"}
})
}
}
}
}
};
Task.WaitAll(client.PostAsync(message));
}

public static void PostUsersMenuMessage(Config config)
{
var client = new MatterhookClient(config.incomingWebHookUrl);
var message = new MattermostMessage
{
Text =
"This is a message menu with users source posted using [Matterhook.NET](https://github.com/promofaux/Matterhook.NET)",
Channel = config.testChannel,
Username = "Awesome-O-Matic",
IconUrl =
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/2000px-Robot_icon.svg.png",

Attachments = new List<MattermostAttachment>
{
new MattermostAttachment
{
Pretext = "This is optional pretext that shows above the attachment.",
Text = "This is the text of the attachment. ",
Actions = new List<IMattermostAction>
{
new MattermostMessageMenuUsers
{
Name = "Users",
Integration = new MattermostIntegration(config.outgoingWebHookUrl,
new Dictionary<string, object>
{
{"mood", "sad"}
})
}
}
}
}
};
Task.WaitAll(client.PostAsync(message));
}

public static Config LoadConfig()
{
var configFile = "config.json";
if (! File.Exists(configFile))
{
Console.WriteLine("No Config file found, make sure it exists first");
Environment.Exit(1);
return null;
}

var jsonStr = File.ReadAllText(configFile);
return JsonConvert.DeserializeObject<Config>(jsonStr);
}
}
}
6 changes: 6 additions & 0 deletions Matterhook.NET.MatterhookClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManualTests", "ManualTests\ManualTests.csproj", "{7A252949-3DCA-454C-9436-1A953C1FC734}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{52ED8E2C-7DA3-4D7C-B14F-5AC25934ADB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52ED8E2C-7DA3-4D7C-B14F-5AC25934ADB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52ED8E2C-7DA3-4D7C-B14F-5AC25934ADB7}.Release|Any CPU.Build.0 = Release|Any CPU
{7A252949-3DCA-454C-9436-1A953C1FC734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A252949-3DCA-454C-9436-1A953C1FC734}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A252949-3DCA-454C-9436-1A953C1FC734}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A252949-3DCA-454C-9436-1A953C1FC734}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
18 changes: 18 additions & 0 deletions Matterhook.NET.MatterhookClient/IMattermostAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Matterhook.NET.MatterhookClient
{
/// <summary>
/// Interface for a mattermost message action
/// </summary>
public interface IMattermostAction
{
/// <summary>
/// Integration used by this action.
/// </summary>
MattermostIntegration Integration { get; set; }

/// <summary>
/// Action's name.
/// </summary>
string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net452;net461;netcoreapp1.0;netcoreapp2.0;netstandard2.0</TargetFrameworks>
<Authors>Promofaux</Authors>
<TargetFrameworks>net452;net461;net471;netcoreapp1.0;netcoreapp2.1;netstandard2.0</TargetFrameworks>
<Authors>Promofaux, rgomez90</Authors>
<Company />
<Description>Simple HTTPclient to post messages to your Mattermost server</Description>
<Copyright>Promofaux</Copyright>
Expand All @@ -11,13 +11,14 @@
<RepositoryUrl>https://github.com/PromoFaux/Matterhook.NET.MatterhookClient</RepositoryUrl>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.4</Version>
<Version>1.0.4-asdad-cxcxc-2</Version>
<PackageId>Matterhook.NET.MatterhookClient</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

</Project>
Loading