Skip to content

Commit f6be85f

Browse files
committed
Create GoogleChat notifier
1 parent 2460ca5 commit f6be85f

25 files changed

+1428
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitignore export-ignore
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat;
13+
14+
/**
15+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16+
*
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#builtinicons
18+
* @experimental in 5.1
19+
*/
20+
final class BuiltInIcons
21+
{
22+
const AIRPLANE = 'AIRPLANE';
23+
const BOOKMARK = 'BOOKMARK';
24+
const BUS = 'BUS';
25+
const CAR = 'CAR';
26+
const CLOCK = 'CLOCK';
27+
const CONFIRMATION_NUMBER_ICON = 'CONFIRMATION_NUMBER_ICON';
28+
const DESCRIPTION = 'DESCRIPTION';
29+
const DOLLAR = 'DOLLAR';
30+
const EMAIL = 'EMAIL';
31+
const EVENT_SEAT = 'EVENT_SEAT';
32+
const FLIGHT_ARRIVAL = 'FLIGHT_ARRIVAL';
33+
const FLIGHT_DEPARTURE = 'FLIGHT_DEPARTURE';
34+
const HOTEL = 'HOTEL';
35+
const HOTEL_ROOM_TYPE = 'HOTEL_ROOM_TYPE';
36+
const INVITE = 'INVITE';
37+
const MAP_PIN = 'MAP_PIN';
38+
const MEMBERSHIP = 'MEMBERSHIP';
39+
const MULTIPLE_PEOPLE = 'MULTIPLE_PEOPLE';
40+
const PERSON = 'PERSON';
41+
const PHONE = 'PHONE';
42+
const RESTAURANT_ICON = 'RESTAURANT_ICON';
43+
const SHOPPING_CART = 'SHOPPING_CART';
44+
const STAR = 'STAR';
45+
const STORE = 'STORE';
46+
const TICKET = 'TICKET';
47+
const TRAIN = 'TRAIN';
48+
const VIDEO_CAMERA = 'VIDEO_CAMERA';
49+
const VIDEO_PLAY = 'VIDEO_PLAY';
50+
51+
private function __construct()
52+
{
53+
}
54+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
5.0.0
5+
-----
6+
7+
* Added the bridge
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
13+
14+
/**
15+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16+
*
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
18+
*
19+
* @method Section end()
20+
*/
21+
final class ButtonsWidget implements WidgetInterface
22+
{
23+
use ComponentTrait;
24+
25+
public function __construct()
26+
{
27+
$this->options = ['buttons' => []];
28+
}
29+
30+
public function imageButton(string $icon, string $link)
31+
{
32+
$this->options['buttons'][] = (new ImageButton($icon, $link))->toArray();
33+
34+
return $this;
35+
}
36+
37+
public function textButton(string $text, string $link)
38+
{
39+
$this->options['buttons'][] = (new TextButton($text, $link))->toArray();
40+
41+
return $this;
42+
}
43+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
13+
14+
/**
15+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16+
*
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
18+
*/
19+
final class Card implements ComponentInterface
20+
{
21+
use ComponentTrait;
22+
23+
public function __construct(array $header = [], array $sections = [])
24+
{
25+
$this->options = [
26+
'sections' => $sections,
27+
];
28+
}
29+
30+
/**
31+
* @param string $subtitle
32+
* @param string $imageStyle square ("IMAGE") or circular ("AVATAR")
33+
*/
34+
public function header(string $title, string $subtitle = null, string $imageUrl = null, string $imageStyle = null)
35+
{
36+
$this->options['header'] = array_filter([
37+
'title' => $title,
38+
'subtitle' => $subtitle,
39+
'imageUrl' => $imageUrl,
40+
'imageStyle' => $imageStyle,
41+
]);
42+
43+
return $this;
44+
}
45+
46+
/**
47+
* @return Section
48+
*/
49+
public function section(string $header = null)
50+
{
51+
$section = new Section($header);
52+
$section->setEndCallback([$this, 'addSection']);
53+
$this->assertNotDirty($section);
54+
$this->dirty = $section;
55+
56+
return $section;
57+
}
58+
59+
/**
60+
* @return $this
61+
*/
62+
public function addSection(Section $section)
63+
{
64+
$this->assertNotDirty($section);
65+
66+
$this->options['sections'][] = $section->toArray();
67+
$this->dirty = null;
68+
69+
return $this;
70+
}
71+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
13+
14+
/**
15+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16+
*/
17+
interface ComponentInterface
18+
{
19+
public function toArray(): array;
20+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
13+
14+
use Symfony\Component\Notifier\Bridge\GoogleChat\Exception\NotEndedComponentException;
15+
16+
/**
17+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
18+
*/
19+
trait ComponentTrait
20+
{
21+
protected $options = [];
22+
protected $dirty = null;
23+
private $endCallback;
24+
25+
public function toArray(): array
26+
{
27+
if ($this->dirty) {
28+
throw new NotEndedComponentException(sprintf('Cannot export "%s", a "%s" has been created but not ended.', \get_class($this), \get_class($this->dirty)));
29+
}
30+
31+
return $this->options;
32+
}
33+
34+
public function end()
35+
{
36+
$endCallback = $this->endCallback;
37+
38+
if (null === $endCallback) {
39+
throw new \LogicException('Cannot call "end()" on a component.');
40+
}
41+
42+
// Remove circular reference
43+
$this->endCallback = null;
44+
45+
return $endCallback($this);
46+
}
47+
48+
/**
49+
* @internal
50+
*/
51+
public function setEndCallback(callable $endCallback)
52+
{
53+
$this->endCallback = $endCallback;
54+
}
55+
56+
private function assertNotDirty(ComponentInterface $component)
57+
{
58+
if (null !== $this->dirty && $component !== $this->dirty) {
59+
throw new NotEndedComponentException(sprintf('Cannot add "%s" to "%s", a "%s" has been created but not ended.', \get_class($component), \get_class($this), \get_class($this->dirty)));
60+
}
61+
}
62+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
13+
14+
/**
15+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16+
*
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
18+
*/
19+
final class ImageButton implements ComponentInterface
20+
{
21+
use ComponentTrait;
22+
23+
public function __construct(string $icon, string $link)
24+
{
25+
$this->options = [
26+
'imageButton' => [
27+
('http' === substr($icon, 0, 4) ? 'iconUrl' : 'icon') => $icon,
28+
'onClick' => [
29+
'openLink' => [
30+
'url' => $link,
31+
],
32+
],
33+
],
34+
];
35+
}
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
13+
14+
/**
15+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16+
*
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#image_widget
18+
*/
19+
final class ImageWidget implements WidgetInterface
20+
{
21+
use ComponentTrait;
22+
23+
public function __construct(string $imageUrl, string $link = null)
24+
{
25+
$this->options = [
26+
'image' => [
27+
'imageUrl' => $imageUrl,
28+
],
29+
];
30+
31+
if (null !== $link) {
32+
$this->link($link);
33+
}
34+
}
35+
36+
public function link(string $link)
37+
{
38+
$this->options['image']['onClick'] = [
39+
'openLink' => [
40+
'url' => $link,
41+
],
42+
];
43+
}
44+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy