Polyjuice Client v0.2.1 Polyjuice.Client.MsgBuilder View Source
Build a message out of composable parts.
Link to this section Summary
Functions
Escape special HTML characters.
Create an image.
Create a link.
Mention a user.
Generate a Matrix message contents from message data.
Link to this section Functions
Escape special HTML characters.
Returns an iodata.
Examples:
iex> Polyjuice.Client.MsgBuilder.html_escape("a<>&\"", false)
...> |> IO.iodata_to_binary()
"a<>&\""
iex> Polyjuice.Client.MsgBuilder.html_escape("a<>&b\"", true)
...> |> IO.iodata_to_binary()
"a<>&b""
Link to this function
image(src, attrs \\ [])
View Sourceimage(src :: String.t(), attrs :: list()) :: Polyjuice.Client.MsgBuilder.MsgData.t()
Create an image.
Examples:
iex> Polyjuice.Client.MsgBuilder.to_message(
...> Polyjuice.Client.MsgBuilder.image("mxc://example.com/foo")
...> )
%{
"msgtype" => "m.text",
"body" => "[mxc://example.com/foo]",
"format" => "org.matrix.custom.html",
"formatted_body" => "<img src=\"mxc://example.com/foo\" />"
}
iex> Polyjuice.Client.MsgBuilder.to_message(
...> Polyjuice.Client.MsgBuilder.image("mxc://example.com/foo", alt: "some image")
...> )
%{
"msgtype" => "m.text",
"body" => "some image",
"format" => "org.matrix.custom.html",
"formatted_body" => "<img src=\"mxc://example.com/foo\" alt=\"some image\" />"
}
iex> Polyjuice.Client.MsgBuilder.to_message(
...> Polyjuice.Client.MsgBuilder.image(
...> "mxc://example.com/foo", alt: "some image", width: 100
...> )
...> )
%{
"msgtype" => "m.text",
"body" => "some image",
"format" => "org.matrix.custom.html",
"formatted_body" => "<img src=\"mxc://example.com/foo\" alt=\"some image\" width=\"100\" />"
}
Link to this function
link(contents, href)
View Sourcelink(contents :: Polyjuice.Client.MsgBuilder.MsgData.t(), href :: String.t()) :: Polyjuice.Client.MsgBuilder.MsgData.t()
Create a link.
Examples:
iex> Polyjuice.Client.MsgBuilder.to_message(
...> Polyjuice.Client.MsgBuilder.link(
...> Polyjuice.Client.MsgBuilder.image(
...> "mxc://example.com/foo", alt: "some image", width: 100
...> ),
...> "https://matrix.org/"
...> )
...> )
%{
"msgtype" => "m.text",
"body" => "[some image](https://matrix.org/)",
"format" => "org.matrix.custom.html",
"formatted_body" => "<a href=\"https://matrix.org/\"><img src=\"mxc://example.com/foo\" alt=\"some image\" width=\"100\" /></a>"
}
Link to this function
mention(user_id, display_name \\ nil)
View Sourcemention(user_id :: String.t(), display_name :: String.t() | nil) :: Polyjuice.Client.MsgBuilder.MsgData.t()
Mention a user.
Examples:
iex> Polyjuice.Client.MsgBuilder.to_message(
...> Polyjuice.Client.MsgBuilder.mention("@alice:example.com", "Alice")
...> )
%{
"msgtype" => "m.text",
"body" => "Alice",
"format" => "org.matrix.custom.html",
"formatted_body" => "<a href=\"https://matrix.to/#/@alice:example.com\">Alice</a>"
}
iex> Polyjuice.Client.MsgBuilder.to_message(
...> Polyjuice.Client.MsgBuilder.mention("@alice:example.com")
...> )
%{
"msgtype" => "m.text",
"body" => "@alice:example.com",
"format" => "org.matrix.custom.html",
"formatted_body" => "<a href=\"https://matrix.to/#/@alice:example.com\">@alice:example.com</a>"
}
Generate a Matrix message contents from message data.
Examples:
iex> Polyjuice.Client.MsgBuilder.to_message("foo")
%{"msgtype" => "m.text", "body" => "foo"}
iex> Polyjuice.Client.MsgBuilder.to_message(["foo", "bar"])
%{"msgtype" => "m.text", "body" => "foobar"}