Polyjuice Client v0.4.2 Polyjuice.Client.Attachment View Source
Attachment related functions.
Use the new
function to create an attachment. The attachment type can be
set by using the as_*
functions. For example:
Polyjuice.Client.Room.send_message(
client,
"!roomid",
Polyjuice.Client.Attachment.new(
client,
{:file, "file.png"},
mimetype: "image/png"
)
# mark it as image, and set the size
|> Polyjuice.Client.Attachment.as_image(width: 250, height: 250)
|> Polyjuice.Client.Attachment.add_thumbnail(
client,
{:file, "thumbnail.png"},
"image/png",
width: 10,
height: 10
)
)
Link to this section Summary
Types
Represents an attachment message.
Functions
Add a thumbnail to an attachment object.
Transform a attachment object object into an attachment audio object.
Transform a attachment object object into an attachment file object.
Transform a attachment object object into an attachment image object
Transform a attachment object object into an attachment video object.
Download the file from an attachment object.
Download the thumbnail from an attachment object.
Create an attachment object.
Link to this section Types
Represents an attachment message.
The map will have the following keys: "msgtype"
(a string), "body"
(a
string), and "info"
(a map).
Link to this section Functions
add_thumbnail(msg, client_api, data, mimetype, opts \\ [])
View Sourceadd_thumbnail( msg :: attachment(), client_api :: Polyjuice.Client.API.t() | nil, data :: {:data, binary(), String.t()} | {:file, String.t()} | {:url, String.t() | URI.t()}, mimetype :: String.t(), opts :: Keyword.t() ) :: attachment()
Add a thumbnail to an attachment object.
Supported options are:
height:
the thumbnail heightwidth:
the thumbnail widthsize:
the size in bytes of the thumbnail
as_audio(msg, duration \\ nil)
View Sourceas_audio(msg :: attachment(), duration :: integer() | nil) :: attachment()
Transform a attachment object object into an attachment audio object.
The duration
is given in milliseconds.
as_file(msg, filename)
View Sourceas_file(msg :: attachment(), filename :: String.t()) :: attachment()
Transform a attachment object object into an attachment file object.
as_image(msg, opts \\ [])
View Sourceas_image(msg :: attachment(), opts :: Keyword.t()) :: attachment()
Transform a attachment object object into an attachment image object
Supported options are:
width:
the intended display width of the imageheight:
the intended display height of the image
as_video(msg, opts \\ [])
View Sourceas_video(msg :: attachment(), opts :: Keyword.t()) :: attachment()
Transform a attachment object object into an attachment video object.
Supported options:
width:
the display width of the videoheight:
the display height of the videoduration:
the duration of the video in milliseconds
download(client, msg)
View Sourcedownload(client_api :: Polyjuice.Client.API.t(), msg :: attachment()) :: {:ok, String.t(), String.t(), Enumerable.t()} | any()
Download the file from an attachment object.
Returns the same format as Polyjuice.Client.Media.download
: if successful,
returns a tuple of the form {:ok, filename, content_type, body}
, where
body
is a Stream
such that Enum.join(body)
is the file contents.
download_thumbnail(client, msg)
View Sourcedownload_thumbnail(client_api :: Polyjuice.Client.API.t(), msg :: attachment()) :: {:ok, String.t(), String.t(), Enumerable.t()} | any()
Download the thumbnail from an attachment object.
Returns the same format as Polyjuice.Client.Media.download
: if successful,
returns a tuple of the form {:ok, filename, content_type, body}
, where
body
is a Stream
such that Enum.join(body)
is the file contents.
new(client_api, data, opts \\ [])
View Sourcenew( client_api :: Polyjuice.Client.API.t(), data :: {:data, binary(), String.t()} | {:file, String.t()} | {:url, String.t() | URI.t()}, opts :: Keyword.t() ) :: attachment()
Create an attachment object.
The attachment data can be provided as:
- a tuple of the form
{:data, file_contents, filename}
, which will usefile_contents
as the file; - a tuple of the form
{:file, filename}
, which will upload a local file; or - a tuple of the form
{:url, mxc_url}
, which uses an already-uploaded file.
Supported options are:
body:
the message body. Defaults to the filename, if provided, or "Attachment" if the data is of the form{:url, mxc_url}
.mimetype:
the mimetype for the attachment. Defaults toapplication/octet-stream
.size:
the size in bytes of the file. If not specified, it will attempt to determine the size automatically.info:
metadata about the image, in the format specified by theinfo
property of them.file
(or similar) msgtypemsgtype:
themsgtype
to use for the message. Defaults tom.file
. This can also be set by using one of theas_*
functions (e.g.as_image
will change the message to anm.image
msgtype) rather than setting themsgtype
here.