【问题标题】:Microsoft Teams escaping underscores in textMicrosoft Teams 在文本中转义下划线
【发布时间】:2021-01-27 16:55:19
【问题描述】:

我在 ruby​​ 中具有以下功能,可通过 webhook 将 aws 日志发送到 Microsoft 团队频道。某些文本包含下划线符号,如 connection_web,但在 MS 团队中显示为 connectionweb。如何得到准确的输出?

require 'json'
require 'net/https'
require 'uri'
require 'base64'
require 'zlib'
require 'stringio'
def lambda_handler(event:, context:)
  log_event = JSON.parse(decode_and_decompress(event["awslogs"]["data"]))
  response = speak(messages_from_blob(log_event))
  puts response.body
end
def speak(message)
  http = Net::HTTP.new("MS-Teamwebhook.com", 443)
  http.use_ssl = true
  request = Net::HTTP::Post.new(ENV["HOOK_URL"])
  request.body = JSON.generate({
    text: message
  })
  http.request(request)
end
def decode_and_decompress(input)
  binary_compressed = Base64.decode64(input)
  gz = Zlib::GzipReader.new(StringIO.new(binary_compressed))    
  gz.read
end
def messages_from_blob(event_data)
  event_data["logEvents"]
    .map{ |e| e["message"] }
    .join("\n")
end

【问题讨论】:

  • 默认情况下它似乎打开了markdown标志,我在代码markdown: false中关闭了但仍然有问题。
  • 有人帮我解决这个问题吗?
  • 嗨@blaCkninJa,我无法使用邮递员重现该问题,请尝试Sending messages to connectors and webhooks
  • 嗨@blaCkninJa,你还面临这个问题吗?如果是,请您按照this 文件尝试使用邮递员。它有示例
  • @Jagadeesh-MSFT 我已经在下面提到了详细信息。使用 ruby​​ 代码无法解决问题。

标签: ruby microsoft-teams amazon-cloudwatchlogs


【解决方案1】:

@Jagadeesh:我使用邮递员正文使用以下请求,并将最后一段中value 中的消息密码发送到 msteam 频道,现在输出完美接收。但是使用上面的 ruby​​ 代码无法接收到相同的消息。

{
"@type": "MessageCard",
"@context": "https://schema.org/extensions",
"summary": "Office 365 Notification",
"title": "Office 365 Service Degradations",
"sections": [
    {
        "markdown": false,
        "facts": [
            {
                "name": "Service Incident:",
                "value": "ID"
            },
            {
                "name": "Start time:",
                "value": "check_disk_critical"
            },
            {
                "name": "Service:",
                "value": "SERVICENAME"
            },
            {
                "name": "Description:",
                "value": "# Time: 210211  6:12:12
    # User@Host: live_test_demo_web[live_test_demo_web] @  [10.7.13.209]  Id: 468920921
    # Query_time: 2.070946  Lock_time: 0.000041 Rows_sent: 0  Rows_examined: 762480
    use web;
    SET timestamp=1613023932;
    UPDATE `testing_web`.`abc_customer_data` SET `test_processing`=0 WHERE `id` > 0;"
            }
        ],
        "title": "Office 365 Service Problem"
    }
]
}

【讨论】:

  • 嗨@blaCkninJa,您提供的有效负载/卡 JSON 在我们端工作正常。 Teams 不会在消息卡的任何文本字段中转义下划线。看起来问题出在您的代码上。请跟踪和调试应用程序以找出下划线转义发生的位置。此外,为请求进行网络捕获也会有所帮助,因为我们可以检查发送到 Webhook 端点的有效负载。
  • @Jagadeesh-MSFT 我已经通过使用带有 python 脚本的消息卡解决了这个问题。
【解决方案2】:

我们为此提出了一个错误,相关团队正在努力解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2020-10-28
    相关资源
    最近更新 更多