class RocketChat::Messages::Chat

Rocket.Chat Chat messages

Attributes

session[R]

Public Class Methods

new(session) click to toggle source

@param [Session] session Session

# File lib/rocket_chat/messages/chat.rb, line 14
def initialize(session)
  @session = session
end

Public Instance Methods

delete(room_id: nil, name: nil, msg_id: nil, as_user: nil) click to toggle source

chat.delete REST API @param [String] room_id Rocket.Chat room id @param [String] name Rocket.Chat room name (coming soon) @param [String] msg_id The message id to delete @param [Boolean] as_user Message deleted as user who sent (optional - default: false) @return [Boolean] @raise [HTTPError, StatusError]

# File lib/rocket_chat/messages/chat.rb, line 27
def delete(room_id: nil, name: nil, msg_id: nil, as_user: nil)
  session.request_json(
    '/api/v1/chat.delete',
    method: :post,
    body:
      room_params(room_id, name).tap do |h|
        h[:msgId] = msg_id
        h[:asUser] = as_user unless as_user.nil?
      end
  )['success']
end
get_message(msg_id: nil) click to toggle source

chat.getMessage REST API @param [String] msg_id The message id to return @return [RocketChat::Message] @raise [HTTPError, StatusError]

# File lib/rocket_chat/messages/chat.rb, line 45
def get_message(msg_id: nil)
  response = session.request_json(
    '/api/v1/chat.getMessage',
    body: { msgId: msg_id }
  )
  RocketChat::Message.new response['message'] if response['success']
end
post_message(room_id: nil, name: nil, channel: nil, **params) click to toggle source

chat.postMessage REST API @param [String] room_id Rocket.Chat room id @param [String] name Rocket.Chat room name (coming soon) @param [String] channel Rocket.Chat channel name @param [Hash] params Optional params (text, alias, emoji, avatar & attachments) @return [RocketChat::Message] @raise [HTTPError, StatusError]

# File lib/rocket_chat/messages/chat.rb, line 62
def post_message(room_id: nil, name: nil, channel: nil, **params)
  response = session.request_json(
    '/api/v1/chat.postMessage',
    method: :post,
    body: room_params(room_id, name)
      .merge(channel: channel)
      .merge(Util.slice_hash(params, :text, :alias, :emoji, :avatar, :attachments))
  )
  RocketChat::Message.new response['message'] if response['success']
end
update(room_id: nil, name: nil, msg_id: nil, text: nil) click to toggle source

chat.update REST API @param [String] room_id Rocket.Chat room id @param [String] name Rocket.Chat room name (coming soon) @param [String] msg_id The message id to update @param [String] text Updated text for the message @return [RocketChat::Message] @raise [HTTPError, StatusError]

# File lib/rocket_chat/messages/chat.rb, line 82
def update(room_id: nil, name: nil, msg_id: nil, text: nil)
  response = session.request_json(
    '/api/v1/chat.update',
    method: :post,
    body: room_params(room_id, name).merge(msgId: msg_id, text: text)
  )
  RocketChat::Message.new response['message'] if response['success']
end