Curnow.biz.MessageCard 1.0.0

.NET Standard 2.0
NuGet\Install-Package Curnow.biz.MessageCard -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package Curnow.biz.MessageCard --version 1.0.0
<PackageReference Include="Curnow.biz.MessageCard" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Curnow.biz.MessageCard --version 1.0.0
#r "nuget: Curnow.biz.MessageCard, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Curnow.biz.MessageCard as a Cake Addin
#addin nuget:?package=Curnow.biz.MessageCard&version=1.0.0

// Install Curnow.biz.MessageCard as a Cake Tool
#tool nuget:?package=Curnow.biz.MessageCard&version=1.0.0

Curnow.biz.MessageCard

Legacy actionable message card model for .NET based applications. Ideal for sending actionable message cards to Microsoft Teams using objects instead of JSON strings.

There are several classes provided that offers a complete implementation of the Actionable Message Card JSON schema. A complete description of the MessageCard schema and layout can be found on Github here.

Namespaces

You must include the following usings in your code to use the classes:

using Curnow.biz.MessageCard;
using Curnow.biz.MessageCard.Actions;
using Curnow.biz.MessageCard.Inputs;
using Curnow.biz.MessageCard.Section;

Constructing a MessageCard in Code

The example below takes the following MessageCard JSON string and implements it using the MessageCard classes.

{
  "summary": "Card \"Test card\"",
  "themeColor": "0078D7",
  "title": "Card created: \"Name of card\"",
  "sections": [
    {
      "activityTitle": "David Claux",
      "activitySubtitle": "9/13/2016, 3:34pm",
      "activityImage": "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg",
      "facts": [
        {
          "name": "Board:",
          "value": "Name of board"
        },
        {
          "name": "List:",
          "value": "Name of list"
        },
        {
          "name": "Assigned to:",
          "value": "(none)"
        },
        {
          "name": "Due date:",
          "value": "(none)"
        }
      ],
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
    }
  ],
  "potentialAction": [
    {
      "@type": "ActionCard",
      "name": "Set due date",
      "inputs": [
        {
          "@type": "DateInput",
          "id": "dueDate",
          "title": "Select a date"
        }
      ],
      "actions": [
        {
          "@type": "HttpPOST",
          "name": "OK",
          "target": "https://..."
        }
      ]
    },
    {
      "@type": "ActionCard",
      "name": "Move",
      "inputs": [
        {
          "@type": "MultichoiceInput",
          "id": "move",
          "title": "Pick a list",
          "choices": [
            { "display": "List 1", "value": "l1" },
            { "display": "List 2", "value": "l2" }
          ]
        }
      ],
      "actions": [
        {
          "@type": "HttpPOST",
          "name": "OK",
          "target": "https://..."
        }
      ]
    },
    {
      "@type": "ActionCard",
      "name": "Add a comment",
      "inputs": [
        {
          "@type": "TextInput",
          "id": "comment",
          "isMultiline": true,
          "title": "Enter your comment"
        }
      ],
      "actions": [
        {
          "@type": "HttpPOST",
          "name": "OK",
          "target": "https://..."
        }
      ]
    },
    {
      "@type": "OpenUri",
      "name": "View in Trello",
      "targets": [
        { "os": "default", "uri": "https://..." }
      ]
    }
  ]
}

When building the card, everything starts with a MessageCard object, as follows:

MessageCard card = new MessageCard
{ 
    Summary = "Card \"Test Card\"",
    ThemeColor = "0078D7",
    Title = "Card created: \"Name of card\""
};

Sections

To add the card Section information, we need to populate the Sections collection property of the MessageCard object with one or more Section objects, as follows:

card.Sections = new List<Section>()
{
    new Section
    {
        ActivityTitle = "David Claux",
        ActivitySubtitle = "9/13/2016, 3:34pm",
        ActivityImage = "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg",
        Facts = new List<Fact>()
        {
            new Fact { Name = "Board:", Value = "Name of board"},
            new Fact { Name = "List:", Value = "Name of list"},
            new Fact { Name = "Assigned to:", Value = "(none)"},
            new Fact { Name = "Due date:", Value = "(none)"}
        },
        Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
    }
};

In the example above, the Section contains Facts, so the Section object Fact collection property is populated with multiple Fact objects.

Card Actions

We can now move on to populating the MessageCard objects Actions collection property. This property is a collection of objects whose base type is ActionBase. The Actions available are:

  • ActionCard
  • HttpPOSTAction
  • OpenUriAction
  • InvokeAddInCommandAction

These classes implement all of the properties defined in the MessageCard JSON schema for Action types.

card.Actions = new List<ActionBase>()
{
    new ActionCard
    {
        Name = "Set due date",
        Inputs = new List<InputBase>()
        {
            new DateInput { Id = "dueDate", Title = "Select a date"}
        },
        Actions = new List<ActionBase>()
        {
            new HttpPOSTAction { Name = "OK", Target="https://..."}
        }
    },
    new ActionCard
    {
        Name = "Move",
        Inputs = new List<InputBase>()
        {
            new MultiChoiceInput
            { 
                Id = "move",
                Title = "Pick a list",
                Style = Style.Expanded,
                Choices = new List<Choice>()
                {
                    new Choice { Display = "List 1", Value = "l1"},
                    new Choice { Display = "List 2", Value = "l2"}
                }
            }
        },
        Actions = new List<ActionBase>()
        {
            new HttpPOSTAction { Name = "OK", Target = "https://..."}
        }
    },
    new ActionCard
    {
        Name = "Add a comment",
        Inputs = new List<InputBase>()
        {
            new TextInput { Id = "comment", IsMultiLine = true, Title = "Enter your comment"}
        },
        Actions = new List<ActionBase>()
        {
            new HttpPOSTAction
            {
                Name = "OK",
                Target = "https://...",
                Body = "comment={{comment.value}}"
            }
        }
    },
    new OpenUriAction
    {
        Name = "View in Trello",
        Targets = new List<Target>
        {
            new Target { OS = TargetOS.Default, Uri="https://..."}
        }
    }
};

ActionCard Inputs collection

The Inputs property is a collection of objects whose base type is InputBase. The input types are:

  • TextInput
  • DateInput
  • MultiChoiceInput

These classes implement all of the properties defined in the MessageCard JSON schema for Input types.

Returning a JSON string from a MessageCard Object

In order for the card to be sent to Teams (or any other application that supports message cards), raw JSON needs to be posted to an incoming webhook. The MessageCard class implements a simple method called ToJson() and is used as follows (assuming the variable card is an instance of MessageCard):

string json = card.ToJson();
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 311 7/6/2020

First release of library