Class: Layer::Message

Overview

Note:

This is available in both the REST and the Platform API. Please refer to the respective documentation to see which methods are available.

Examples:

Sending messages

conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')
conversation.messages.create({ sender: { name: 'Server' }, parts: [{ body: 'Hello!', mime_type: 'text/plain' }]})

See Also:

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #client

Instance Method Summary collapse

Methods included from Operations::Find::ClassMethods

find

Methods included from Operations::Delete::ClassMethods

delete

Methods included from Operations::Destroy::ClassMethods

destroy

Methods included from Operations::Destroy

#destroy

Methods included from Operations::Delete

#delete

Methods included from Operations::Find

#reload

Methods inherited from Resource

class_name, from_response, #id, #initialize, #respond_to_missing?, url, #url

Constructor Details

This class inherits a constructor from Layer::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Layer::Resource

Instance Method Details

#conversationLayer::Conversation

Returns the conversation this message belongs to

Returns:



23
24
25
# File 'lib/layer/message.rb', line 23

def conversation
  Conversation.from_response(attributes['conversation'], client)
end

#delivered!Object

Note:

This is only available via the REST API.

Marks the message as delivered to the current user



43
44
45
# File 'lib/layer/message.rb', line 43

def delivered!
  client.post(receipts_url, { type: 'delivery' })
end

#read!Object

Note:

This is only available via the REST API.

Marks the message as read by the current user



37
38
39
# File 'lib/layer/message.rb', line 37

def read!
  client.post(receipts_url, { type: 'read' })
end

#receipts_urlString

Note:

This is only available via the REST API.

The endpoint to send read and delivered receipts to

Returns:

  • (String)

    the url of the endpoint

See Also:



51
52
53
# File 'lib/layer/message.rb', line 51

def receipts_url
  attributes['receipts_url'] || "#{url}/receipts"
end

#sent_atTime

Returns the time the message was sent at

Returns:

  • (Time)

    the time the message was sent at



30
31
32
# File 'lib/layer/message.rb', line 30

def sent_at
  Time.parse(attributes['sent_at'])
end