Laravel 8 格式化 Slack 通知

2021-07-19 10:56 更新

如果通知支持通過(guò) Slack 消息發(fā)送,則需要在通知類(lèi)上定義一個(gè) toSlack 方法,該方法接收一個(gè) $notifiable 實(shí)體并返回 Illuminate\Notifications\Messages\SlackMessage 實(shí)例,Slack 消息可以包含文本內(nèi)容以及格式化附加文本或數(shù)組字段的 “附件”。讓我們來(lái)看一個(gè)基本的 toSlack 使用示例:

/**
 * Get the Slack representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return SlackMessage
 */
public function toSlack($notifiable)
{
    return (new SlackMessage)
                ->content('One of your invoices has been paid!');
}

在此示例中,我們僅向 Slack 發(fā)送一行文本,這將創(chuàng)建一條如下所示的消息:

basic-slack-notification.png
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)