Polyjuice Client v0.4.2 Polyjuice.Client.Message View Source
Functions for creating messages.
These functions return a full event content, and do not fit in the
Polyjuice.Client.MsgBuilder
interface. However, they make take a
Polyjuice.Client.MsgBuilder
where appropriate.
Link to this section Summary
Link to this section Functions
edit(msg, msgtype \\ "m.text", fallback \\ nil, map)
View Sourceedit( msg :: Polyjuice.Util.event_content() | Polyjuice.Client.MsgBuilder.MsgData.t(), msgtype :: String.t(), fallback :: Polyjuice.Util.event_content() | Polyjuice.Client.MsgBuilder.MsgData.t() | (Polyjuice.Util.event_content() -> Polyjuice.Util.event_content()) | (Polyjuice.Util.event_content(), Polyjuice.Util.event_content() -> Polyjuice.Util.event_content()) | nil, ref_event :: Polyjuice.Util.event() ) :: Polyjuice.Util.event_content()
Create an event that edits a previous message.
The new event contents is given in msg
, and fallback
is a fallback
representation for clients that do not support edits. fallback
can be a
function of one or two arguments, returning the fallback representation. If
it takes one argument, the argument will be the new event contents; if it
takes two arguments, the first argument will be the new event contents and
the second argument will be the old event contents. If fallback
is not
given, then the function will generate a naive fallback.
Note that this function assumes that the formatted body in msg
is properly
formatted.
ref_event
is the original event that is being edited.
Example:
iex> Polyjuice.Client.Message.edit(
...> "Hello",
...> %{
...> "event_id" => "$event_id",
...> "content" => %{"body" => "Helloo", "msgtype" => "m.text"}
...> }
...> )
%{
"body" => "* Hello",
"msgtype" => "m.text",
"m.new_content" => %{
"body" => "Hello",
"msgtype" => "m.text",
},
"m.relates_to" => %{
"rel_type" => "m.annotation",
"event_id" => "$event_id"
}
}
react(reaction, ref_event)
View Sourcereact(reaction :: String.t(), ref_event :: Polyjuice.Util.event() | String.t()) :: Polyjuice.Util.event_content()
Create a reaction event.
The event should be sent with type m.reaction
.
Example:
iex> Polyjuice.Client.Message.react("👍", "$event_id")
%{
"m.relates_to" => %{
"rel_type" => "m.annotation",
"event_id" => "$event_id",
"key" => "👍"
}
}
reply(msg, msgtype \\ "m.text", map, strip_reply_fn)
View Sourcereply( msg :: Polyjuice.Util.event_content() | Polyjuice.Client.MsgBuilder.MsgData.t(), msgtype :: String.t(), ref_event :: Polyjuice.Util.event(), strip_reply_fn :: (String.t() -> String.t()) ) :: Polyjuice.Util.event_content()
Create a reply.
strip_reply_fn
should be a function that takes an HTML-formatted message
(as a string) and removes any <mx-reply>
elements from it. The input is
untrusted, so the function should be able to handle malformed HTML.
Example:
iex> Polyjuice.Client.Message.reply(
...> "Hello",
...> %{
...> "content" => %{"body" => "Hello World!", "msgtype" => "m.text"},
...> "sender" => "@alice:example.org",
...> "event_id" => "$event_id",
...> "room_id" => "!room_id",
...> "type" => "m.room.message"
...> },
...> # Note: We can only use the following as `strip_reply_fn` because
...> # we know that the original message does not have <mx-reply> tags.
...> # In real usage, this should be replaced with something better.
...> fn msg -> msg end
...> )
%{
"body" => "> <@alice:example.org> Hello World!\nHello",
"format" => "org.matrix.custom.html",
"formatted_body" => "<mx-reply><blockquote>\n<a href=\"https://matrix.to/#/%21room_id/%24event_id\">In reply to</a> <a href=\"https://matrix.to/#/%40alice%3Aexample.org\">@alice:example.org</a><br />\nHello World!\n</blockquote></mx-reply>\nHello\n",
"msgtype" => "m.text",
"m.relates_to" => %{
"m.in_reply_to" => %{
"event_id" => "$event_id"
}
}
}