Data source: Google Chat
1Presentation
Google Chat allows to create communication spaces, where it is possible to send notifications.
If you have correctly configured the Google Chat connection parameters, Temma automatically creates an object of type \Temma\Datasources\GoogleChat, with which you can send notifications. By convention, we'll assume that you've named this connection gchat in the etc/temma.php file (see configuration documentation).
In controllers, the Google Chat connection is then available by writing:
$gchat = $this->gchat;
In other objects managed by the dependency injection component, the Google Chat connection is accessible by writing:
$gchat = $loader->dataSources->gchat;
$gchat = $loader->dataSources['gchat'];
2Configuration
To send messages to Google Chat, you must first create a webhook. Each webhook is linked to a space in which it can post messages.
In the etc/temma.php file (see configuration documentation), you declare the DSN (Data Source Name) used to connect to Google Chat.
The DSN used to connect to Google Chat can be written as googlechat://WEBHOOK
With WEBHOOK the value of the webhook URL, without the https:// prefix.
Example: chat.googleapis.com/v1/spaces/XXXXXXX/messages?key=YYYYYYY&token=ZZZZZZZ
3Notification content
Notifications can contain simple text, or a derivative of Markdown syntax, or a complexe layout with title, subtitle, pictogram, HTML code, images and links.
4Unified calls
4.1Array-like access
// send a simple message
$gchat[''] = "Message to send";
// message with Markdown
$gchat[''] = 'Text with _simple_ *formatting*.';
$gchat[''] = [
'title' => 'A title',
'subtitle' => 'A subtitle',
'picto' => 'https://url of the picto',
// each section may have a title and: a text, an image or a list of buttons
'sections' => [
[
'title' => 'First section',
'html' => 'Some text',
],
[
'icon' => 'STAR',
'topLabel' => 'Status',
'html' => "A link.",
'bottomLabel' => 'Generated yesterday',
],
[
'image' => 'https://url_of_image',
'alt' => 'Alternate text', // optionnal
],
[
'title' => 'Another section',
'buttons' => [
'Button 1' => 'https://link_btn_1',
'Button 2' => 'https://link_btn_2',
'Button 3' => 'https://link_btn_3',
]
],
],
];
4.2Advanced method
// send a simple message
$gchat->set('', "Message to send");
// rich notification
$gchat->set('', [
'title' => 'A title',
'picto' => 'htpss://url of the picto',
]);