class RocketChat::Messages::Channel

Rocket.Chat Channel messages

Public Class Methods

settable_attributes() click to toggle source

Keys for set_attr:

  • 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)

# File lib/rocket_chat/messages/channel.rb, line 68
def self.settable_attributes
  %i[description join_code purpose read_only topic type]
end

Public Instance Methods

join(room_id: nil, name: nil) click to toggle source

channels.join REST API @param [String] room_id Rocket.Chat room id @param [String] name Rocket.Chat room name (coming soon) @return [Boolean] @raise [HTTPError, StatusError]

# 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) click to toggle source

channels.list REST API @param [Integer] offset Query offset @param [Integer] count Query count/limit @param [Hash] sort Query field sort hash. eg `{ msgs: 1, name: -1 }` @param [Hash] fields Query fields to return. eg `{ name: 1, ro: 0 }` @param [Hash] query The query. `{ active: true, type: { '$in': ['name', 'general'] } }` @return [Room @raise [HTTPError, StatusError]

# 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) click to toggle source

channels.online REST API @param [String] room_id Rocket.Chat room id @return [Users @raise [HTTPError, StatusError]

# File lib/rocket_chat/messages/channel.rb, line 52
def online(room_id: nil, name: nil)
  response = session.request_json(
    '/api/v1/channels.online',
    body: room_params(room_id, name)
  )

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