RamblingCookieMonster / PSSlack

PowerShell module for simple Slack integration
http://ramblingcookiemonster.github.io/PSSlack/
MIT License
274 stars 74 forks source link

Send-SlackFIle - macOS/linux support #59

Closed devblackops closed 6 years ago

devblackops commented 6 years ago

More cross-platform fun 😄

Send-SlackFile is throwing this error on macOS.

> Send-SlackFile -Token $token -Path $f.FullName -Channel general
Invoke-RestMethod : The format of value 'multipart/form-data; boundary="4ade9b52-9513-44c0-a787-3843b95eba20"' is invalid.
At /Users/brandon/.local/share/powershell/Modules/PSSlack/0.0.31/Public/Send-SlackFile.ps1:135 char:29
+ ... $response = Invoke-RestMethod -Uri $uri -Method Post -ContentType "mu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], FormatException
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Something must be wrong with the value of $bodyLines on macOS/linux.

@markekraus has a nice article on multipart/form-data support. I did some quick tests and this is working on macOS. I also like using .net methods over a bunch of string concatenation as well.

If you agree, I'll submit a PR to fix.

Cheers

markekraus commented 6 years ago

I would suggest holding off until 6.1 and then requiring the 6.1 version. 6.1 adds a much easier to swallow multi-part/formdata feature:

$From = @{
    file = Get-Item -Path $FileName
    token = $Token
    filename = Split-Path -Path $Path -Leaf 
    channels = $Channel -join ", "
    title = $Title
    'initial_comment' = $Comment
} 
Invoke-RestMethod  -Uri $Uri -Method Post -Form $Form

PowerShell/PowerShell#5972

I wanted that feature in 6.0.0, but we couldn't get the design nailed down before RC.

RamblingCookieMonster commented 6 years ago

Good catch!

Up to you all. I'm good with waiting until that PR is in (6.1?) if it makes sense to you.

@devblackops - that work for you? If you need this for the summit, would working in a branch that has code that works in 6.0.0 work for you? It would be more work, but feel free to submit a temporary workaround (as long as it continues to work in windows powershell) that we can adjust in 6.1

Cheers!

devblackops commented 6 years ago

My only issue with waiting for 6.1 is now PSSlack would have a hard dependency on 6.1 in your manifest. It requires 3+ right now and there isn't a way to specify different required versions between Windows PS and core PS. Most people on Windows are not using 6+ yet. If you require 6.1, then everyone else depending on PSSlack requires 6.1.

@RamblingCookieMonster I don't strictly need it for the summit. I'd like to demo PoshBot on macOS but can use Windows if needed. This issue and #57 are the only things I've found so far and #57 really just creates a warning for me.

markekraus commented 6 years ago

Yea, if you need backwards compat, I can only seriously recommend the raw .NET APIs (HttpClient in particular). The new multipart/form-data in 6.0 is not backwards compat with 5.x-3.0 either.

RamblingCookieMonster commented 6 years ago

Ahh good call! Yeah - if you can do the same code and cover both core and full, even better

Thanks!