猿问

您如何使用 laravel slack 通知 api 在 (@) 某人处于 slack 状态?

我有一个功能正常的通知系统,可以发布到我们公司 Slack 的频道。但是,遇到的一切都只是文本。linkNames假设在您的内容中查找/链接用户名。我看到它被设置为“1”,但当它出现在频道中时没有影响。


 namespace App\Notifications;


use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Notifications\Notification;

use Illuminate\Notifications\Messages\SlackMessage;

class Dd extends Notification

{

use Queueable;


/**

 * Create a new notification instance.

 *

 * @return void

 */

public function __construct()

{

    //

}


/**

 * Get the notification's delivery channels.

 *

 * @param  mixed  $notifiable

 * @return array

 */

public function via($notifiable)

{

    return ['slack'];

}



/**

 * Get the array representation of the notification.

 *

 * @param  mixed  $notifiable

 * @return array

 */

public function toArray($notifiable)

{

    return [

        //

    ];

}


/**

 * Get the Slack representation of the notification.

 *

 * @param  mixed  $notifiable

 * @return SlackMessage

 */

public function toSlack($slackComment)

{   

    $slackMessage = new SlackMessage();

    $slackMessage->linkNames();

    $slackMessage->from('Christopher');

    $slackMessage->to($slackComment->channel);

    $slackMessage->content("Harded coded for example @christopher <- this doesn't get linked to the user in slack but should");

     $slackMessage->info();

    //dd($slackMessage); // this shows that the linkedNames attribute has been set to "1"

    return $slackMessage;             

}

}

这是一个已知问题,版本不匹配,还是我遗漏了什么?



茅侃侃
浏览 116回答 1
1回答

料青山看我应如是

https://api.slack.com/reference/surfaces/formatting#mentioning-users要在应用发布的文本中提及用户,您需要按以下语法提供他们的用户 ID:Hey&nbsp;<@U024BE7LH>,&nbsp;thanks&nbsp;for&nbsp;submitting&nbsp;your&nbsp;report.
随时随地看视频慕课网APP
我要回答