diff --git a/PSDify.psd1 b/PSDify.psd1 index 7bfb1fc..f6f8e02 100644 --- a/PSDify.psd1 +++ b/PSDify.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'PSDify.psm1' - ModuleVersion = '0.3.0' + ModuleVersion = '0.3.1' CompatiblePSEditions = @('Core', 'Desktop') GUID = 'b791c4c0-ed46-4561-8713-5d4242e6bac7' Author = 'kurokobo' diff --git a/Public/Import-DifyApp.ps1 b/Public/Import-DifyApp.ps1 index 6401cb4..88f77c5 100644 --- a/Public/Import-DifyApp.ps1 +++ b/Public/Import-DifyApp.ps1 @@ -51,9 +51,9 @@ function Import-DifyApp { if ([System.Version]$SimplifiedVersion -lt [System.Version]"0.12.0") { $Endpoint = Join-Url -Segments @($env:PSDIFY_URL, "/console/api/apps/import") $Method = "POST" - $Body = $UTF8NoBOM.GetBytes((@{ - "data" = $RawContent - } | ConvertTo-Json)) + $Body = @{ + "data" = $RawContent + } | ConvertTo-Json try { $Response = Invoke-DifyRestMethod -Uri $Endpoint -Method $Method -Body $Body -Token $env:PSDIFY_CONSOLE_TOKEN } @@ -85,10 +85,10 @@ function Import-DifyApp { else { $Endpoint = Join-Url -Segments @($env:PSDIFY_URL, "/console/api/apps/imports") $Method = "POST" - $Body = $UTF8NoBOM.GetBytes((@{ - "mode" = "yaml-content" - "yaml_content" = $RawContent - } | ConvertTo-Json)) + $Body = @{ + "mode" = "yaml-content" + "yaml_content" = $RawContent + } | ConvertTo-Json try { $Response = Invoke-DifyRestMethod -Uri $Endpoint -Method $Method -Body $Body -Token $env:PSDIFY_CONSOLE_TOKEN } diff --git a/Public/Invoke-DifyRestMethod.ps1 b/Public/Invoke-DifyRestMethod.ps1 index c870052..46b872e 100644 --- a/Public/Invoke-DifyRestMethod.ps1 +++ b/Public/Invoke-DifyRestMethod.ps1 @@ -4,7 +4,7 @@ function Invoke-DifyRestMethod { [String] $Uri, [String] $Method = "GET", [String] $ContentType = "application/json", - [Object] $Body = $null, + [String] $Body = $null, [Hashtable] $Query = $null, [String] $Token = $null, [Microsoft.PowerShell.Commands.WebRequestSession] $Session = $null, @@ -37,7 +37,8 @@ function Invoke-DifyRestMethod { } if (@("POST", "PUT", "PATCH", "DELETE") -contains $Method) { if ($Body) { - $RestMethodParams.Body = $Body + $UTF8NoBOM = New-Object "System.Text.UTF8Encoding" -ArgumentList @($false) + $RestMethodParams.Body = $UTF8NoBOM.GetBytes($Body) } if ($InFile) { $RestMethodParams.InFile = $InFile diff --git a/Tests/Integration/52_Send-DifyChatMessage.Tests.ps1 b/Tests/Integration/52_Send-DifyChatMessage.Tests.ps1 index 8565821..54a70ab 100644 --- a/Tests/Integration/52_Send-DifyChatMessage.Tests.ps1 +++ b/Tests/Integration/52_Send-DifyChatMessage.Tests.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.6" } +#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.6" } BeforeDiscovery { $PesterPhase = "BeforeDiscovery" @@ -61,6 +61,12 @@ Describe "Send-DifyChatMessage" -Tag "chat" { Assert-MockCalled -ModuleName PSDify -CommandName Write-Host -ParameterFilter { $Object -like "*Pong*" } } + It "should send messages without knowledge with multibyte characters" { + $env:PSDIFY_APP_TOKEN = $TestAppWithoutKnowledgeAPIKey.Token + Send-DifyChatMessage -NewSession -Message "日本語で朝の挨拶は? ひらがなで。" + + Assert-MockCalled -ModuleName PSDify -CommandName Write-Host -ParameterFilter { $Object -like "*おはよ*" } + } It "should send messages with knowledge" { $env:PSDIFY_APP_TOKEN = $TestAppWithKnowledgeAPIKey.Token Send-DifyChatMessage -NewSession -Message "What is the vegetable that is deep ruby red in color ?"