Skip to content

Commit cf5b344

Browse files
Merge pull request #12 from hyrodium/feature/sendfile
Add `sendfiletoslack` function
2 parents a77262b + 42493eb commit cf5b344

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Slack.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ end
2828
include("send.jl")
2929
export
3030
sendtoslack,
31-
sendattachmenttoslack
31+
sendattachmenttoslack,
32+
sendfiletoslack
3233

3334
include("channel.jl")
3435
export

src/send.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,27 @@ function sendattachmenttoslack(data, user_endpoint::String)
4343

4444
return (String(r.body))
4545
end
46+
47+
"""
48+
sendfiletoslack(filepath, message, channel, token)
49+
50+
Sends a file with a message to the specified channel.
51+
https://api.slack.com/methods/files.upload
52+
"""
53+
function sendfiletoslack(filepath, message, channel, token)
54+
HTTP.setuseragent!("HTTP.jl")
55+
56+
57+
url = "https://slack.com/api/files.upload"
58+
headers = Dict("Authorization"=>"Bearer $token")
59+
data = Dict(
60+
"file" => open(filepath),
61+
"initial_comment" => message,
62+
"channels" => channel
63+
)
64+
body = HTTP.Form(data)
65+
66+
r = HTTP.post(url, headers, body)
67+
68+
return (String(r.body))
69+
end

0 commit comments

Comments
 (0)