Skip to content

Simple Text Messages

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

MethodOutput DescriptionGoogle 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>

Convert GitHub and GitLab Markdown

Use markdown() to convert GitHub-Flavoured Markdown, such as a pull or merge request description, to the text formatting supported by Google Chat:

php
GoogleChatMessage::create()
    ->bold('Merge request merged')
    ->line()
    ->markdown($mergeRequest->description)
    ->link($mergeRequest->web_url, 'View merge request');

The converter supports headings, emphasis, strikethrough, links, code blocks, block quotes, lists, task lists, and tables. Images and unsupported HTML are converted to readable text. It does not create Google Chat mentions from GitHub or GitLab usernames; use mention() where a Google Chat user ID is available.

Google Chat supports a limited formatting syntax. This converter preserves supported Markdown where possible and degrades unsupported constructs to readable text. See Google Chat's formatting documentation for the complete supported syntax.

For use outside a notification builder, call GoogleChatMarkdown::convert($markdown) directly.

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.');