Hi.
I have a function for sending message from powershell to webex by rest api:
Function WebexStringNotify ([String]$string) {
# $enc = [System.Text.Encoding]::UTF8
# $dec = [System.Text.Encoding]::Unicode
# $string = $dec.GetString($enc.GetBytes($string))
foreach ($roomID in $WebexNotificationRoomIDs) {
$request = @{
Uri = 'https://webexapis.com/v1/messages'
SessionVariable = 'Session'
Method = 'POST'
Body = @{
roomId = $roomID
markdown = $string
}
Headers = @{
'Authorization' = "Bearer $WebexBotToken"
'Accept' = 'application/json; charset=UTF-8'
'Accept-Charset'= 'UTF-8'
}
}
$response = Invoke-WebRequest @request
if ($response.StatusCode -eq 200) {
Write-Host "Webex Notification Sended" -ForegroundColor Green
}
else {
Write-Host "Webex Notification Problem" -ForegroundColor Yellow
Write-Host $response
}
}
}
Problem is when $string argument contains UTF-8 symbol (ex: "┌") it goes to webex as "âÂÂ".
-Console has
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
-Enc/dec:
# $enc = [System.Text.Encoding]::UTF8
# $dec = [System.Text.Encoding]::Unicode
# $string = $dec.GetString($enc.GetBytes($string))
do not work.
-Content-Type header not supported by api, and i suppose it will not work.
-Webex direct input support UTF8 and this char so looks like this is not a webex issue
-Debugging in VS Code shows $string with no problem.
How to resolve this?