Shi*_*pra 7 logging ansi-colors hubot slack
我正在使用 Slack 和 Hubot 在我们的服务器上运行一些命令,这些命令的 stdout 和 stderr 作为片段上传到通道。
其中一些命令返回颜色输出,并在代码片段中显示为 ANSI 颜色代码(例如:[32mHello World![0m)。
有没有办法在 Slack 代码片段中显示这些颜色?
小智 0
def enviarNotificacionSlack(mensaje, estado) {
// Convert ANSI color codes to Slack message formatting
def formattedMensaje = mensaje.replaceAll('\u001B\\[39m', '*')
.replaceAll('\u001B\\[90m', '`')
.replaceAll('\u001B\\[32m', '*')
.replaceAll('\u001B\\[31m', '`')
// Construct the Slack message payload
def slackMessage = [
channel: '#channel',
attachments: [
[
fallback: mensaje,
color: estado == 'success' ? 'good' : 'danger',
text: formattedMensaje
]
]
]
// Send the Slack notification
slackSend(slackMessage)
}Run Code Online (Sandbox Code Playgroud)