Class: ChatWork::Message

Inherits:
Entity
  • Object
show all
Defined in:
lib/chatwork/message.rb

Constant Summary

Constants included from Operations

Operations::ACCEPT_PARAMS_ID

Instance Attribute Summary

Attributes inherited from Entity

#attributes

Attributes included from Operations

#assign_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

convert, hash_compact, #initialize

Methods included from Operations

#define_create, #define_get, #install_class_operations

Constructor Details

This class inherits a constructor from ChatWork::Entity

Class Method Details

.create(room_id:, body:) ⇒ Hash

Add new message to the chat

Examples:

response format

{
  "message_id": "1234"
}

Parameters:

  • room_id (Integer)
  • body (String)

    message body

Returns:

  • (Hash)

See Also:


56
57
58
# File 'lib/chatwork/message.rb', line 56

def self.create(room_id:, body:)
  _create(room_id: room_id, body: body)
end

.get(room_id:, force: nil) ⇒ Array<Hash>

Get all messages associated with the specified chat (returns up to 100 entries).

If the parameter is not set, it returns the next 100 entries from previous call.

Examples:

response format

[
  {
    "message_id": "5",
    "account": {
      "account_id": 123,
      "name": "Bob",
      "avatar_image_url": "https://example.com/ico_avatar.png"
    },
    "body": "Hello Chatwork!",
    "send_time": 1384242850,
    "update_time": 0
  }
]

Parameters:

  • room_id (Integer)
  • force (Boolean, Integer) (defaults to: nil)

    Flag which forces to get 100 newest entries regardless of previous calls.

Returns:

  • (Array<Hash>)

See Also:


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chatwork/message.rb', line 30

def self.get(room_id:, force: nil)
  params = { room_id: room_id }

  case force
  when 1, true
    params[:force] = 1
  when 0, false
    params[:force] = 0
  end

  _get(params)
end

.pathObject


60
61
62
# File 'lib/chatwork/message.rb', line 60

def self.path
  "/rooms/%d/messages"
end

Instance Method Details

#pathObject


64
65
66
# File 'lib/chatwork/message.rb', line 64

def path
  "/rooms/%d/messages"
end