Laravel 松弛通知,启动一个线程
Laravel Slack Notification, starting a thread
现在我有通知 类 每当创建新事件或事件注释时发送松弛消息。在应用程序中,Incident 和 IncidentNote 通过 I.D 关联。在我的数据库表中。
我想做的是,每当创建事件时,它都会向频道发送一条松弛消息,但是当为事件创建注释时,它会存储在事件下面的松弛线程中。我查看了 Laravel 文档,但没有找到这是否可能。
我应该如何着手尝试这个?
步骤:
- 每次在 slack 上创建新事件时,您都会获得线程 ID。
- 将该线程 ID 存储到与您的事件记录相对应的数据库中。
- 下次当您想 post 对任何特定线程的任何评论或注释时,post 消息包含来自数据库的线程 ID。
简单地说,您必须随事件一起跟踪和存储线程 ID。下次通过将线程 ID 包含到您的 json 数据中,生成一条 json 消息到 post 到特定线程。
示例:到 post note/comment 到 slack 上的特定线程:
public function postReplyThread($msg,$ts){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://slack.com/api/chat.postMessage");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"token=".$this->access_token."&channel=".$this->channel."&text=".$msg."&ts=".$ts."&thread_ts=".$ts);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
return $server_output;
}
其中 thread_ts=".$ts
是您希望post发表评论的话题。
现在我有通知 类 每当创建新事件或事件注释时发送松弛消息。在应用程序中,Incident 和 IncidentNote 通过 I.D 关联。在我的数据库表中。
我想做的是,每当创建事件时,它都会向频道发送一条松弛消息,但是当为事件创建注释时,它会存储在事件下面的松弛线程中。我查看了 Laravel 文档,但没有找到这是否可能。
我应该如何着手尝试这个?
步骤:
- 每次在 slack 上创建新事件时,您都会获得线程 ID。
- 将该线程 ID 存储到与您的事件记录相对应的数据库中。
- 下次当您想 post 对任何特定线程的任何评论或注释时,post 消息包含来自数据库的线程 ID。
简单地说,您必须随事件一起跟踪和存储线程 ID。下次通过将线程 ID 包含到您的 json 数据中,生成一条 json 消息到 post 到特定线程。
示例:到 post note/comment 到 slack 上的特定线程:
public function postReplyThread($msg,$ts){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://slack.com/api/chat.postMessage");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"token=".$this->access_token."&channel=".$this->channel."&text=".$msg."&ts=".$ts."&thread_ts=".$ts);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
return $server_output;
}
其中 thread_ts=".$ts
是您希望post发表评论的话题。