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 2 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
67 changes: 67 additions & 0 deletions src/Actions/ActionOpenUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace NotificationChannels\MicrosoftTeams\Actions;

use BackedEnum;

use NotificationChannels\MicrosoftTeams\Enums\ButtonStyle;
use NotificationChannels\MicrosoftTeams\Enums\Mode;

class ActionOpenUrl
{
protected string $type = 'Action.OpenUrl';

protected string $title;

protected Mode $mode;

protected ButtonStyle $style;

protected string $url;

public function setTitle(string $title) : self
{
$this->title = $title;
return $this;
}

public function setMode(Mode $mode) : self
{
$this->mode = $mode;
return $this;
}

public function setStyle(ButtonStyle $style) : self
{
$this->style = $style;
return $this;
}

public function setUrl(string $url) : self
{
$this->url = $url;
return $this;
}

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

public function toArray() : array
{
$actionOpenUrl = [];
$properties = get_object_vars($this);
foreach ($properties as $propertyName => $propertyValue) {

if ($propertyValue instanceof BackedEnum) {
$actionOpenUrl[$propertyName] = $propertyValue->value;
continue;
}

$actionOpenUrl[$propertyName] = $propertyValue;
}

return $actionOpenUrl;
}
}
38 changes: 38 additions & 0 deletions src/ContentBlocks/Fact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace NotificationChannels\MicrosoftTeams\ContentBlocks;

class Fact
{
protected string $title;

protected string $value;

public function setTitle(string $title) : self
{
$this->title = $title;
return $this;
}

public function setValue(string $value) : self
{
$this->value = $value;
return $this;
}

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

public function toArray() : array
{
$fact = [];
$properties = get_object_vars($this);
foreach ($properties as $propertyName => $propertyValue) {
$fact[$propertyName] = $propertyValue;
}

return $fact;
}
}
66 changes: 66 additions & 0 deletions src/ContentBlocks/FactSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace NotificationChannels\MicrosoftTeams\ContentBlocks;

use BackedEnum;

use NotificationChannels\MicrosoftTeams\Enums\Spacing;

class FactSet
{
protected ?Spacing $spacing;

protected array $facts;

protected ?bool $separator;

protected string $type = 'FactSet';

public function setSpacing(Spacing $spacing) : self
{
$this->spacing = $spacing;
return $this;
}

public function setSeparator(bool $separator) : self
{
$this->separator = $separator;
return $this;
}

public function setFacts(array $facts) : self
{
$this->facts = $facts;
return $this;
}

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

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

{
$factSet = [];
$properties = get_object_vars($this);
foreach ($properties as $propertyName => $propertyValue) {

if ($propertyValue instanceof BackedEnum) {
$factSet[$propertyName] = $propertyValue->value;
continue;
}

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

continue;
}

$factSet[$propertyName] = $propertyValue;
}

return $factSet;
}
}
94 changes: 94 additions & 0 deletions src/ContentBlocks/Icon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace NotificationChannels\MicrosoftTeams\ContentBlocks;

use BackedEnum;
use NotificationChannels\MicrosoftTeams\Enums\Color;
use NotificationChannels\MicrosoftTeams\Enums\HorizontalAlignment;
use NotificationChannels\MicrosoftTeams\Enums\IconSize;
use NotificationChannels\MicrosoftTeams\Enums\IconStyle;
use NotificationChannels\MicrosoftTeams\Enums\Spacing;

class Icon
{
protected string $name;

protected ?Spacing $spacing;

protected ?bool $separator;

protected string $type = 'Icon';

protected ?HorizontalAlignment $horizontalAlignment;

protected ?IconStyle $style;

protected ?Color $color;

protected ?IconSize $size;

public function setName(string $name) : self
{
$this->name = $name;
return $this;
}

public function setColor(Color $color) : self
{
$this->color = $color;
return $this;
}

public function setSpacing(Spacing $spacing) : self
{
$this->spacing = $spacing;
return $this;
}

public function setSeparator(bool $separator) : self
{
$this->separator = $separator;
return $this;
}

public function setSize(IconSize $iconSize) : self
{
$this->size = $iconSize;
return $this;
}

public function setStyle(IconStyle $iconStyle) : self
{
$this->style = $iconStyle;
return $this;
}

public function setHorizontalAlignment(HorizontalAlignment $horizontalAlignment) : self
{
$this->horizontalAlignment = $horizontalAlignment;
return $this;
}

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

public function toArray() : array
{
$icon = [];
$properties = get_object_vars($this);
foreach ($properties as $propertyName => $propertyValue) {

if ($propertyValue instanceof BackedEnum) {
$icon[$propertyName] = $propertyValue->value;
continue;
}

$icon[$propertyName] = $propertyValue;
}

return $icon;
}

}
Loading