Skip to content

Commit

Permalink
CardsV1 is deprecated we must use cardsV2 instead.
Browse files Browse the repository at this point in the history
Based on google developers api documentation.
https://developers.google.com/chat/api/reference/rest/v1/cards-v1
CardsV1 is deprecated we must use cardsV2 instead.
  • Loading branch information
daifma committed Dec 15, 2022
1 parent 233b9eb commit 514840a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function toArray(): array
}

/**
* @deprecated google chat cards-v1 deprecated, use "cardV2()" instead.
*
* @return $this
*/
public function card(array $card): static
Expand All @@ -71,6 +73,16 @@ public function card(array $card): static
return $this;
}

/**
* @return $this
*/
public function cardV2(array $card): static
{
$this->options['cardsV2'][] = $card;

return $this;
}

/**
* @return $this
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class GoogleChatOptionsTest extends TestCase
{
public function testToArray()
public function testToArray(): void
{
$options = new GoogleChatOptions();

Expand All @@ -34,7 +34,48 @@ public function testToArray()
$this->assertSame($expected, $options->toArray());
}

public function testOptionsWithThread()
public function testToArrayWithCardV2(): void
{
$options = new GoogleChatOptions();

$cardV2 = [
'header' => [
'title' => 'Sasha',
'subtitle' => 'Software Engineer',
'imageUrl' => 'https://developers.google.com/chat/images/quickstart-app-avatar.png',
'imageType' => 'CIRCLE',
'imageAltText' => 'Avatar for Sasha'
],
'sections' => [
[
'header' => 'Contact Info',
"collapsible" => true,
'widgets' => [
'decoratedText' => [
'startIcon' => ['knownIcon' => 'EMAIL'],
'text' => 'sasha@example.com',
]
]
]
]
];

$options
->text('Hello Bot')
->cardV2($cardV2)
;

$expected = [
'text' => 'Hello Bot',
'cardsV2' => [
$cardV2,
],
];

$this->assertSame($expected, $options->toArray());
}

public function testOptionsWithThread(): void
{
$thread = 'fgh.ijk';
$options = new GoogleChatOptions();
Expand Down

0 comments on commit 514840a

Please sign in to comment.