Simple Text Messages
Pre-release Version
These documentation pages are for the pre-release v2 of this package.
Simple text messages allow you to format notification body text with bolding, italics, code blocks, hyperlinks, and mentions using Google Chat markdown syntax.
Fluent Text Formatting
GoogleChatMessage provides fluent helper methods to construct rich text messages:
php
use NotificationChannels\GoogleChat\GoogleChatMessage;
public function toGoogleChat(object $notifiable): GoogleChatMessage
{
return GoogleChatMessage::create()
->bold('System Backup Completed')
->line('The daily database snapshot finished successfully:')
->monospaceBlock("Database: production_db\nSize: 4.2 GB\nTime: 124s")
->italic('Status: ')
->bold('HEALTHY')
->line()
->link('https://backup.example.com/logs/1048', 'View Complete Backup Logs');
}Available Text Formatting Helpers
| Method | Output Description | Google Chat Output |
|---|---|---|
text(string $text) | Appends plain text without trailing newline. | Text |
line(?string $text = null) | Appends text followed by a new line. | Text\n |
bold(string $text) | Appends bold text. | *Text* |
italic(string $text) | Appends italic text. | _Text_ |
strikethrough(string $text) / strike(string $text) | Appends strikethrough text. | ~Text~ |
monospace(string $text) / mono(string $text) | Appends inline monospace text. | `Text` |
monospaceBlock(string $text) | Appends a multiline code block. | \nText\n |
link(string $url, ?string $label = null) | Appends a hyperlink. | <https://example.com|Label> |
mention(string $userId) | Mentions a specific Google Chat user ID. | <users/USER_ID> |
mentionAll(?string $prepend = null, ?string $append = null) | Mentions @all room members. | <users/all> |
User Mentions & Room Alerts
Mentioning @all
To trigger a room-wide alert notification targeting all members of a space:
php
GoogleChatMessage::create()
->mentionAll('CRITICAL ALERT: ', ' Server unreachability detected!')
->line('Immediate investigation required.');Mentioning Specific Users
To mention a specific Google Workspace user by their Google Chat User ID:
php
GoogleChatMessage::create()
->text('Task assigned to ')
->mention('104829304857102938475')
->line('. Please review the attached PR.');