Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft Adaptive Cards #1

Merged
merged 4 commits into from
Feb 27, 2025
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
97 changes: 97 additions & 0 deletions src/Actions/ActionOpenUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace NotificationChannels\MicrosoftTeams\Actions;

class ActionOpenUrl
{
/** @var string Property Type */
protected $type = 'Action.OpenUrl';

/** @var string Title of the Action */
protected $title;

/** @var string $mode Mode of the Action. (Primary, Secondary) */
protected $mode;

/** @var string $mode Style of the Action Button. (Positive, Destructive) */
protected $style;

/** @var string $url URL the Action goes to. */
protected $url;

/**
* @return self
*/
public static function create(): self
{
return new self();
}

/**
* Set the title.
*
* @param string $title
*
* @return ActionOpenUrl
*/
public function setTitle(string $title) : self
{
$this->title = $title;
return $this;
}

/**
* Set the mode.
*
* @param string $mode
*
* @return ActionOpenUrl
*/
public function setMode(string $mode) : self
{
$this->mode = $mode;
return $this;
}

/**
* Set the style.
*
* @param string $style
*
* @return ActionOpenUrl
*/
public function setStyle(string $style) : self
{
$this->style = $style;
return $this;
}

/**
* Set the url.
*
* @param string $url
*
* @return ActionOpenUrl
*/
public function setUrl(string $url) : self
{
$this->url = $url;
return $this;
}

/**
* Returns Action properties as an array.
*
* @return array
*/
public function toArray() : array
{
return [
'type' => $this->type,
'title' => $this->title,
'mode' => $this->mode,
'style' => $this->style,
'url' => $this->url
];
}
}
59 changes: 59 additions & 0 deletions src/ContentBlocks/Fact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace NotificationChannels\MicrosoftTeams\ContentBlocks;

class Fact
{
/** @var string Fact Title */
protected $title;

/** @var string Fact Value */
protected $value;

/**
* @return self
*/
public static function create(): self
{
return new self();
}

/**
* Set the title.
*
* @param string $title
*
* @return Fact
*/
public function setTitle(string $title) : self
{
$this->title = $title;
return $this;
}

/**
* Set the value.
*
* @param string $value
*
* @return Fact
*/
public function setValue(string $value) : self
{
$this->value = $value;
return $this;
}

/**
* Returns Fact properties as an array.
*
* @return array
*/
public function toArray() : array
{
return [
'title' => $this->title,
'value' => $this->value
];
}
}
86 changes: 86 additions & 0 deletions src/ContentBlocks/FactSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace NotificationChannels\MicrosoftTeams\ContentBlocks;

class FactSet
{
/** @var string Property Type */
protected $type = 'FactSet';

/** @var string Spacing of the FactSet. (None,Small,Default,Medium,Large,ExtraLarge,Padding) */
protected $spacing;

/** @var array Array of Facts. ([Fact::create()]) */
protected $facts = [];

/** @var bool FactSet Separator. */
protected $separator;

/**
* @return self
*/
public static function create(): self
{
return new self();
}

/**
* Set the spacing.
*
* @param string $spacing
*
* @return FactSet
*/
public function setSpacing(string $spacing) : self
{
$this->spacing = $spacing;
return $this;
}

/**
* Set the separator.
*
* @param bool $separator
*
* @return FactSet
*/
public function setSeparator(bool $separator) : self
{
$this->separator = $separator;
return $this;
}

/**
* Set the facts.
*
* @param array $facts
*
* @return FactSet
*/
public function setFacts(array $facts) : self
{
$this->facts = $facts;
return $this;
}

/**
* Returns FactSet properties as an array.
*
* @return array
*/
public function toArray() : array

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we update our toArray methods in all of these classes to be less dynamic:

return [
    'facts' => $this->facts->toArray(),
    ...
];

We can leave the MicrosoftTeamsAdaptiveCard as is because it follows the project pattern of using payload

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated methods

{
$facts = [];

foreach($this->facts as $fact) {
$facts[] = $fact->toArray();
}

return [
'type' => $this->type,
'spacing' => $this->spacing,
'facts' => $facts,
'seperator' => $this->separator
];
}
}
149 changes: 149 additions & 0 deletions src/ContentBlocks/Icon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

namespace NotificationChannels\MicrosoftTeams\ContentBlocks;

class Icon
{
/** @var string Property Type */
protected $type = 'Icon';

/** @var string Name of the Icon */
protected $name;

/** @var string Spacing of the Icon. (None,Small,Default,Medium,Large,ExtraLarge,Padding) */
protected $spacing;

/** @var bool Icon Separator. */
protected $separator;

/** @var string Horizontal Alignment of Icon. (Left,Center,Right) */
protected $horizontalAlignment;

/** @var string Style of Icon. (Regular,Filled) */
protected $style;

/** @var string Color of Icon. (Default,Dark,Light,Accent,Good,Warning,Attention) */
protected $color;

/** @var string Size of Icon. (xxSmall,xSmall,Small,Standard,Medium,Large,xLarge,xxLarge) */
protected $size;

/**
* @return self
*/
public static function create(): self
{
return new self();
}

/**
* Set the name.
*
* @param string $name
*
* @return Icon
*/
public function setName(string $name) : self
{
$this->name = $name;
return $this;
}

/**
* Set the color.
*
* @param string $color
*
* @return Icon
*/
public function setColor(string $color) : self
{
$this->color = $color;
return $this;
}

/**
* Set the spacing.
*
* @param string $spacing
*
* @return Icon
*/
public function setSpacing(string $spacing) : self
{
$this->spacing = $spacing;
return $this;
}

/**
* Set the seperator.
*
* @param bool $seperator
*
* @return Icon
*/
public function setSeparator(bool $separator) : self
{
$this->separator = $separator;
return $this;
}

/**
* Set the size.
*
* @param string $size
*
* @return Icon
*/
public function setSize(string $size) : self
{
$this->size = $size;
return $this;
}

/**
* Set the style.
*
* @param string $style
*
* @return Icon
*/
public function setStyle(string $style) : self
{
$this->style = $style;
return $this;
}

/**
* Set the horizontal alignment.
*
* @param string $horizontalAlignment
*
* @return Icon
*/
public function setHorizontalAlignment(string $horizontalAlignment) : self
{
$this->horizontalAlignment = $horizontalAlignment;
return $this;
}

/**
* Returns Icon properties as an array.
*
* @return array
*/
public function toArray() : array
{
return [
'type' => $this->type,
'name' => $this->name,
'spacing' => $this->spacing,
'separator' => $this->separator,
'horizontalAlignment' => $this->horizontalAlignment,
'style' => $this->style,
'color' => $this->color,
'size' => $this->size
];
}

}
Loading