EvotecIT/PSTeams

creating a c# wrapper

mvit777 opened this issue · 1 comments

Hi for ease of use I created a c# wrapper library for sending cards.
Following below an example of what I mean:

public class ThumbnailCard : BaseCard
    {
        public override void SendCard(ref PowerShell ps)
        {
            //var command = "New-ThumbnailCard -Title " + Title + " " +
            //    "-SubTitle \"" + SubTitle + "\" " +
            //    "-Text \"" + Text + "\"" +
            //    "{\r\n    New-ThumbnailImage -Url 'https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png' " +
            //    "-AltText \"Bender Rodríguez\"\r\n} -Uri " + Uri + "";
            //ps.AddCommand(command);
            ps.AddCommand("New-ThumbnailCard")
            .AddParameter("Title", Title)
            .AddParameter("SubTitle", SubTitle)
            .AddParameter("Text", Text)
            .AddParameter("Uri", Uri)
            ;
            ps.Invoke();
            ps.Dispose();
        }
    }

when calling it from powershell script

Test-CardCmdlet -Json $jsonConfig -PsTeamsPath $PsTeamsPath -CardType $config.Type

I recieve an error about a missing parameter Content which I'm not sure what is referring to as it is not part of the api.
Also I'm not using addScript to import psteams into the c# lib but rather import via

initial.ImportPSModule(new string[] { PsTeamsPath });

Any idea?
Thanks again for excellent module

Found the problem.
It turned out that the thumbnail image is actually a mandatory field but it is named Content.
To fix it I had to do something like the following

ScriptBlock scriptBlock = ScriptBlock.Create("{\r\n    New-ThumbnailImage -Url 'https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png' -AltText \"Bender Rodríguez\"\r\n}");

and then

.AddParameter("Content", scriptBlock)