Class: RocketChat::Messages::Channel

Inherits:
Room
  • Object
show all
Includes:
ListSupport, UserSupport
Defined in:
lib/rocket_chat/messages/channel.rb

Overview

Rocket.Chat Channel messages

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserSupport

#user_params

Methods inherited from Room

#add_all, #add_moderator, #add_owner, api_path, #archive, #create, #delete, #info, inherited, #initialize, #invite, #kick, #leave, #members, #remove_moderator, #remove_owner, #rename, #set_attr, #unarchive

Methods included from RoomSupport

#room_params, #room_query_params

Constructor Details

This class inherits a constructor from RocketChat::Messages::Room

Class Method Details

.settable_attributesObject

Keys for set_attr:

  • String

    announcement Announcement for the channel

  • Hash

    custom_fields Custom fields for the channel

  • Boolean

    default Sets whether the channel is a default channel or not

  • String

    description A room’s description

  • String

    join_code Code to join a channel

  • String

    purpose Alias for description

  • Boolean

    read_only Read-only status

  • String

    topic A room’s topic

  • Strong

    type c (channel) or p (private group)



73
74
75
# File 'lib/rocket_chat/messages/channel.rb', line 73

def self.settable_attributes
  %i[announcement custom_fields default description join_code purpose read_only topic type]
end

Instance Method Details

#join(room_id: nil, name: nil) ⇒ Boolean

channels.join REST API

Parameters:

  • room_id (String) (defaults to: nil)

    Rocket.Chat room id

  • name (String) (defaults to: nil)

    Rocket.Chat room name (coming soon)

Returns:

  • (Boolean)

Raises:



19
20
21
22
23
24
25
# File 'lib/rocket_chat/messages/channel.rb', line 19

def join(room_id: nil, name: nil)
  session.request_json(
    '/api/v1/channels.join',
    method: :post,
    body: room_params(room_id, name)
  )['success']
end

#list(offset: nil, count: nil, sort: nil, fields: nil, query: nil) ⇒ Room[]

channels.list REST API

Parameters:

  • offset (Integer) (defaults to: nil)

    Query offset

  • count (Integer) (defaults to: nil)

    Query count/limit

  • sort (Hash) (defaults to: nil)

    Query field sort hash. eg ‘{ msgs: 1, name: -1 }`

  • fields (Hash) (defaults to: nil)

    Query fields to return. eg ‘{ name: 1, ro: 0 }`

  • query (Hash) (defaults to: nil)

    The query. ‘{ active: true, type: { ’$in’: [‘name’, ‘general’] } }‘

Returns:

Raises:



37
38
39
40
41
42
43
44
# File 'lib/rocket_chat/messages/channel.rb', line 37

def list(offset: nil, count: nil, sort: nil, fields: nil, query: nil)
  response = session.request_json(
    '/api/v1/channels.list',
    body: build_list_body(offset, count, sort, fields, query)
  )

  response['channels'].map { |hash| RocketChat::Room.new hash } if response['success']
end

#online(room_id: nil, name: nil) ⇒ Users[]

Note:

Must provide either ‘room_id` or `name` parameter. `room_id` will take precedence if providing both

channels.online REST API

Parameters:

  • room_id (String) (defaults to: nil)

    Rocket.Chat room id

  • name (String) (defaults to: nil)

    Rocket.Chat room name

Returns:

  • (Users[])

Raises:



54
55
56
57
58
59
60
61
# File 'lib/rocket_chat/messages/channel.rb', line 54

def online(room_id: nil, name: nil)
  response = session.request_json(
    '/api/v1/channels.online',
    body: { query: room_query_params(room_id, name) }
  )

  response['online'].map { |hash| RocketChat::User.new hash } if response['success']
end