Skip to content

Commit 53cb260

Browse files
author
Adam Warner
committed
Update Readme.MD
Add optional parameter to PostAsync for specifying the length of a message.
1 parent a9118c7 commit 53cb260

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Matterhook.NET.MatterhookClient.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DD13AC46-A75C-44CE-A48F-0ADF1D2A5A47}"
99
ProjectSection(SolutionItems) = preProject
1010
appveyor.yml = appveyor.yml
11+
README.md = README.md
1112
EndProjectSection
1213
EndProject
1314
Global

Matterhook.NET.MatterhookClient/MatterhookClient.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ private static MattermostAttachment CloneAttachment(MattermostAttachment inAtt)
6464
/// Post Message to Mattermost server. Messages will be automatically split if total text length > 4000
6565
/// </summary>
6666
/// <param name="inMessage">The messsage you wish to send</param>
67+
/// <param name="maxMessageLength">(Optional) Defaulted to 3800, but can be set to any value (Check with your Mattermost server admin!)</param>
6768
/// <returns></returns>
68-
public async Task<HttpResponseMessage> PostAsync(MattermostMessage inMessage)
69+
public async Task<HttpResponseMessage> PostAsync(MattermostMessage inMessage, int maxMessageLength = 3800)
6970
{
7071

7172
try
@@ -84,11 +85,11 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage inMessage)
8485
//start with one cloned inMessage in the list
8586
outMessages.Add(CloneMessage(inMessage));
8687

87-
//add text from original. If we go over 3800, we'll split it to a new inMessage.
88+
//add text from original. If we go over 3800 (or whatever user chooses), we'll split it to a new inMessage.
8889
foreach (var line in lines)
8990
{
9091

91-
if (line.Length + outMessages[msgCount].Text.Length > 3800)
92+
if (line.Length + outMessages[msgCount].Text.Length > maxMessageLength)
9293
{
9394

9495
msgCount += 1;
@@ -122,7 +123,7 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage inMessage)
122123
//Get the total length of all attachments on the current outgoing message
123124
var lenAllAttsText = outMessages[msgCount].Attachments.Sum(a => a.Text.Length);
124125

125-
if (lenMessageText + lenAllAttsText + line.Length > 3800)
126+
if (lenMessageText + lenAllAttsText + line.Length > maxMessageLength)
126127
{
127128
msgCount += 1;
128129
attIndex = 0;

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[![Build status](https://ci.appveyor.com/api/projects/status/76x60eg4vjve4vcf?svg=true)](https://ci.appveyor.com/project/PromoFaux/matterhook-net-matterhookclient) [![NuGet](https://img.shields.io/nuget/v/Matterhook.NET.MatterhookClient.svg)](https://www.nuget.org/packages/Matterhook.NET.MatterhookClient/)
22
[![NuGet](https://img.shields.io/nuget/dt/Matterhook.NET.MatterhookClient.svg)](https://www.nuget.org/packages/Matterhook.NET.MatterhookClient/)
33

4-
# Matterhook.NET
4+
# Matterhook.NET.MatterhookClient
55

6-
Matterhook.NET 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.
77

88
## Usage
99

0 commit comments

Comments
 (0)