Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

ruby - Microsoft Teams escaping underscores in text

I have following function in ruby to send aws logs to microsoft team channel through webhook. Some text contains underscore signs like connection_web but appears like connectionweb in MS teams. How to get the exact output ?

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("
")
end
question from:https://stackoverflow.com/questions/65923762/microsoft-teams-escaping-underscores-in-text

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@Jagadeesh: I used following request using postman body and send the message passwd in value in last paragraph to msteam channel now the output received perfectly. But same message cannot received using above ruby code.

{
"@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"
    }
]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...