From 48493a7f513bba3152204282b25df5f4a5db69c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Sat, 4 Jan 2020 20:22:41 +0100 Subject: [PATCH] rooms: send: allow html formatted messages send: new keyword argument html (html String or nothing) --- src/rooms.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rooms.jl b/src/rooms.jl index 1c0f14a..4d1b129 100644 --- a/src/rooms.jl +++ b/src/rooms.jl @@ -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)))