【问题标题】:how to use slack rich formatting in linux bash script如何在 linux bash 脚本中使用 slack 丰富的格式
【发布时间】:2017-06-29 19:50:45
【问题描述】:

我正在尝试使用传入的 webhook 向松弛通道发送通知,下面是我的 bash 脚本

# !/bin/sh
curl -X POST --data-urlencode 'payload={"channel": "#aws_webhooks", "username": "webhookbot",
"attachments":[
      {
         "fallback":"blahb",
         "pretext":"blahblahblahblahbla",
         "color":"warning",
         "fields":[
            {
               "title":"Alarms Updates",
               "value":" blahblahblahblahblahblah",
               "short":false
            }
         ]
      }
   ]
}'
https://hooks.slack.com/services/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

运行此脚本后我遇到此错误,有人可以帮助我解决我在编写脚本时做错了什么

sh new.sh
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

【问题讨论】:

  • 您需要在有效载荷的末尾和https 之前使用反斜杠。另外,删除第一行中# 之后的空格(尽管这不是您的问题的原因)。
  • 还是不行

标签: linux slack


【解决方案1】:

如果 url 在单独的行上,您应该添加一个“\”:

# !/bin/sh
curl -X POST --data-urlencode 'payload={"channel": "#aws_webhooks", "username": "webhookbot",
"attachments":[
      {
         "fallback":"blahb",
         "pretext":"blahblahblahblahbla",
         "color":"warning",
         "fields":[
            {
               "title":"Alarms Updates",
               "value":" blahblahblahblahblahblah",
               "short":false
            }
         ]
      }
   ]
}' \ <-------backslash
https://hooks.slack.com/services/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

【讨论】:

    【解决方案2】:

    不确定你的代码是怎么回事,但你可以看看我在这里写的 bash 客户端:https://github.com/openbridge/ob_hacky_slack

    这是为帖子创建的代码 sn-p:

        # Send the payload to the Slack API
      echo "OK: All tests passed, sending message to Slack API..."
      POST=$(curl -s -S -X POST --data-urlencode "${PAYLOAD}" "${WEBHOOK}${TOKEN}");
    
      # Check if the message posted to the Slack API. A successful POST should return "ok". Anything other than "ok" indicates an issue
      if test "${POST}" != ok; then echo "ERROR: The POST to the Slack API failed (${POST})" && return 1; else echo "OK: Message successfully sent to the channel ${CHANNEL} via the Slack API"; fi
    

    它可能会为您的问题提供一些线索。

    【讨论】:

      猜你喜欢
      • 2011-08-29
      • 2017-10-09
      • 2011-12-20
      • 1970-01-01
      • 2011-05-14
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多