rooms: send: allow html formatted messages

send: new keyword argument html (html String or nothing)
master
Nicolò Balzarotti 2020-01-04 20:22:41 +01:00
parent 4adcee3eea
commit 48493a7f51
No known key found for this signature in database
GPG Key ID: E5900B8AC02DE455
1 changed files with 10 additions and 4 deletions

View File

@ -11,13 +11,19 @@ function invite(u::MatrixUser, room::String, user::String)
post(u, string("rooms/",room,"/invite"), Dict("user_id" => user))
end
function send(u::MatrixUser, room_id::String, text::String)
res = post(u, string("rooms/", room_id, "/send/m.room.message"),
Dict("msgtype" => "m.text", "body" => text))
"""Send message TEXT from user U to room ROOM_ID.
If HTML is not nothing, send also an html formatted text."""
function send(u::MatrixUser, room_id::String, text::String;
html::Union{Nothing,String} = nothing)
msg = Dict("msgtype" => "m.text", "body" => text)
if !isnothing(html)
msg["format"] = "org.matrix.custom.html"
msg["formatted_body"] = html
end
res = post(u, string("rooms/", room_id, "/send/m.room.message"), msg)
JSON.parse(String(res.body))
end
function getroomevent(u::MatrixUser, room_id::String, event::String)
get(u, string("rooms/", HTTP.escapeuri(room_id), "/state",
event == "" ? "" : string("/", event)))