Method: MatrixSdk::Protocols::CS#send_content

Defined in:
lib/matrix_sdk/protocols/cs.rb

#send_content(room_id, url, name, msg_type, **params) ⇒ Response

Send a content message to a room

Examples:

Sending an image to a room

send_content('!abcd123:localhost',
             'mxc://localhost/1234567',
             'An image of a cat',
             'm.image',
             extra_information: {
               h: 128,
               w: 128,
               mimetype: 'image/png',
               size: 1024
             })

Sending a file to a room

send_content('!example:localhost',
             'mxc://localhost/fileurl',
             'Contract.pdf',
             'm.file',
             extra_content: {
               filename: 'contract.pdf'
             },
             extra_information: {
               mimetype: 'application/pdf',
               size: 96674
             })

Parameters:

  • room_id (MXID, String)

    The room ID to send the content to

  • url (URI, String)

    The URL to the content

  • name (String)

    The name of the content

  • msg_type (String)

    The message type of the content

  • params (Hash)

    Options for the request

Options Hash (**params):

  • :extra_information (Hash) — default: {}

    Extra information for the content

  • :extra_content (Hash)

    Extra data to insert into the content hash

Returns:

  • (Response)

    A response hash with the parameter :event_id

See Also:



578
579
580
581
582
583
584
585
586
587
588
# File 'lib/matrix_sdk/protocols/cs.rb', line 578

def send_content(room_id, url, name, msg_type, **params)
  content = {
    url: url,
    msgtype: msg_type,
    body: name,
    info: params.delete(:extra_information) { {} }
  }
  content.merge!(params.fetch(:extra_content)) if params.key? :extra_content

  send_message_event(room_id, 'm.room.message', content, params)
end