Skip to content

Instantly share code, notes, and snippets.

@ykon
Created September 28, 2019 05:51
Show Gist options
  • Save ykon/91df9932bd7f99ffa4168cabb7af9334 to your computer and use it in GitHub Desktop.
Save ykon/91df9932bd7f99ffa4168cabb7af9334 to your computer and use it in GitHub Desktop.
#!/usr/bin/env julia
using HTTP
function print_usage()
println("Usage: send_chatwork token room_id body")
end
function make_chatwork_url(room_id::String)::String
"https://api.chatwork.com/v2/rooms/$room_id/messages"
end
function make_chatwork_headers(token::String)::Dict{String, String}
Dict(
"Content-Type" => "application/x-www-form-urlencoded",
"X-ChatWorkToken" => token
)
end
function make_chatwork_body(body::String)::String
"body=" * HTTP.escapeuri(body)
end
function post_chatwork(token::String, room_id::String, body::String)::HTTP.Response
c_url = make_chatwork_url(room_id)
c_headers = make_chatwork_headers(token)
c_body = make_chatwork_body(body)
HTTP.post(c_url, c_headers, c_body)
end
function main()
if length(ARGS) != 3
print_usage()
exit(1)
end
token = ARGS[1]
room_id = ARGS[2]
body = ARGS[3]
resp = post_chatwork(token, room_id, body)
if resp.status != 200
println(resp)
exit(1)
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment