Skip to content

Latest commit

 

History

History
198 lines (118 loc) · 4.78 KB

channels.md

File metadata and controls

198 lines (118 loc) · 4.78 KB

Channels API

Channels are RocketChat's public rooms.

channels.create

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channel = session.channels.create('new_channelname', members: ['username1', 'username2'])

Optional parameters for create are:

:members, :read_only, :custom_fields, :extra_data

channels.info

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channel = session.channels.info(name: 'some_channelname')

Either room_id (RocketChat's ID) or name can be used.

channels.delete

To delete a channel, the same options as an info request can be used (room_id or name).

channels.addAll

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
success = session.channels.add_all(room_id: 'ByehQjC44FwMeiLbX')

Optional parameter for add_all is active_users_only (default false)

N.B. the addAll API endpoint requires the calling user to have the admin role

channels.addOwner

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
success = session.channels.add_owner(name: 'some_channelname', username: 'some_username')

Either room_id (RocketChat's ID) or name can be used. The same applies to user_id and username.

channels.removeOwner

To remove an owner from a channel, the same options as an add_owner request can be used.

channels.addModerator

To add a moderator to a channel, the same options as an add_owner request can be used.

channels.removeModerator

To remove a moderator from a channel, the same options as an add_owner request can be used.

channels.invite

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channel = session.channels.invite(name: 'some_channel_name', username: 'some_username')

Either room_id (RocketChat's ID) or name can be used. The same applies to user_id and username.

channels.join

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channel = session.channels.join(name: 'some_channel_name')

Either room_id (RocketChat's ID) or name can be used.

channels.leave

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channel = session.channels.leave(name: 'some_channel_name')

Either room_id (RocketChat's ID) or name can be used.

channels.list

N.B. list is also used for searching/querying

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channels = session.channels.list(query: { usernames: 'friend-username' })

channels.rename

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
channel = session.channels.info(name: 'some_channel_name')
session.channels.rename(channel.id, 'new_channel_name')

channels.set*

This method executes all setSomethingOrOther calls.

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
session.channels.set_attr(name: 'some_channel_name', topic: 'Chatting about stuff')

channels.online

This method returns all online users in a channel.

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
session.channels.online(name: 'some_channel_name')

channels.members

This method returns all members in a channel.

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
session.channels.members(name: 'some_channel_name')

channels.upload_file

Upload file to the room

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
session.channels.upload_file(room_id: 'GENERAL', file: File, filename: "Optional. The name of the file to use.", content_type: "Optional. The content type of the uploaded file", msg: "Optional Message", description: "Optional Description", tmid: "Optional thread message id")