protected function Slack::processMessage in Slack 8
Replaces links with slack friendly tags. Strips all other html.
Parameters
string $message: The message sent to the channel.
Return value
string Replaces links with slack friendly tags. Strips all other html.
1 call to Slack::processMessage()
- Slack::sendRequest in src/
Slack.php - Send message to the Slack with more options.
File
- src/
Slack.php, line 198
Class
- Slack
- Send messages to Slack.
Namespace
Drupal\slackCode
protected function processMessage($message) {
$regexp = "<a\\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\\/a>";
if (preg_match_all("/{$regexp}/siU", $message, $matches, PREG_SET_ORDER)) {
$i = 1;
$links = [];
foreach ($matches as $match) {
$new_link = "<{$match[2]} | {$match[3]}>";
$links['link-' . $i] = $new_link;
$message = str_replace($match[0], 'link-' . $i, $message);
$i++;
}
$message = strip_tags($message);
foreach ($links as $id => $link) {
$message = str_replace($id, $link, $message);
}
}
return $message;
}