Module: ChatWork::Message

Extended by:
EntityMethods
Defined in:
lib/chatwork/message.rb

Class Method Summary collapse

Class Method Details

.create(room_id:, body:) ⇒ Hashie::Mash

Add new message to the chat

Examples:

response format

{
  "message_id": "1234"
}

Parameters:

  • room_id (Integer)
  • body (String)

    message body

Returns:

  • (Hashie::Mash)

See Also:



49
50
51
# File 'lib/chatwork/message.rb', line 49

def self.create(room_id:, body:)
  _post("/rooms/#{room_id}/messages", body: body)
end

.destroy(room_id:, message_id:) ⇒ Hashie::Mash

Destroy the specified message

Examples:

response format

{
  "message_id": "1234"
}

Parameters:

  • room_id (Integer)
  • message_id (String)

Returns:

  • (Hashie::Mash)

See Also:



150
151
152
# File 'lib/chatwork/message.rb', line 150

def self.destroy(room_id:, message_id:)
  _delete("/rooms/#{room_id}/messages/#{message_id}")
end

.find(room_id:, message_id:) ⇒ Hashie::Mash

Get information about the specified message

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)
  • message_id (String)

Returns:

  • (Hashie::Mash)

See Also:



113
114
115
# File 'lib/chatwork/message.rb', line 113

def self.find(room_id:, message_id:)
  _get("/rooms/#{room_id}/messages/#{message_id}")
end

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

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<Hashie::Mash>)

See Also:



31
32
33
# File 'lib/chatwork/message.rb', line 31

def self.get(room_id:, force: nil)
  _get("/rooms/#{room_id}/messages", force: boolean_to_integer(force))
end

.read(room_id:, message_id: nil) ⇒ Hashie::Mash

Mark messages as read

Examples:

response format

{
  "unread_num": 461,
  "mention_num": 0
}

Parameters:

  • room_id (Integer)
  • message_id (String) (defaults to: nil)

Returns:

  • (Hashie::Mash)

See Also:



68
69
70
# File 'lib/chatwork/message.rb', line 68

def self.read(room_id:, message_id: nil)
  _put("/rooms/#{room_id}/messages/read", message_id: message_id)
end

.unread(room_id:, message_id:) ⇒ Hashie::Mash

Mark messages as unread

Examples:

response format

{
  "unread_num": 3,
  "mention_num": 0
}

Parameters:

  • room_id (Integer)
  • message_id (String)

Returns:

  • (Hashie::Mash)

See Also:



87
88
89
# File 'lib/chatwork/message.rb', line 87

def self.unread(room_id:, message_id:)
  _put("/rooms/#{room_id}/messages/unread", message_id: message_id)
end

.update(room_id:, message_id:, body:) ⇒ Hashie::Mash

Update the specified message

Examples:

response format

{
  "message_id": "1234"
}

Parameters:

  • room_id (Integer)
  • message_id (String)
  • body (String)

    message body

Returns:

  • (Hashie::Mash)

See Also:



132
133
134
# File 'lib/chatwork/message.rb', line 132

def self.update(room_id:, message_id:, body:)
  _put("/rooms/#{room_id}/messages/#{message_id}", body: body)
end