Class: Layer::Message

Inherits:
Resource show all
Extended by:
Operations::Find::ClassMethods
Includes:
Operations::Find
Defined in:
lib/layer/message.rb

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::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:


19
20
21
# File 'lib/layer/message.rb', line 19

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


39
40
41
# File 'lib/layer/message.rb', line 39

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


33
34
35
# File 'lib/layer/message.rb', line 33

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:


47
48
49
# File 'lib/layer/message.rb', line 47

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


26
27
28
# File 'lib/layer/message.rb', line 26

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