Module: Slatan::Mouth::Ext::Chat

Included in:
Slatan::Mouth::Ext
Defined in:
lib/slatan/mouth/ext/chat.rb

Class Method Summary collapse

Class Method Details

.mreply(users, channel, text, options = {}) ⇒ Object

build postMessage to reply specific multiple users

Parameters:

  • users (array)

    name or id of users

  • channel (string)

    channel id

  • text (string)

    message

  • options (hash) (defaults to: {})

    options

See Also:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/slatan/mouth/ext/chat.rb', line 40

def mreply(users, channel, text, options={})
  user_ids = users.map do |user|
    user = user.to_s if user.kind_of?(Symbol)
    user_id = Affiliation::Users.is_id?(user) ? user : Affiliation::Users.get_id(user)
    if user_id.nil?
      Buttocks.error("user '#{user}' is not exist. (reply_message)")
    end
    user_id
  end
  user_ids = user_ids.compact.uniq
  users_list = user_ids.reduce("") do |list, user_id|
    "<@#{user_id}>: #{list}"
  end
  reply_text = "#{users_list}#{text}"
  send('postMessage', {
    channel: channel,
    text: reply_text
  }.merge(options))
end

.reply(user, channel, text, options = {}) ⇒ Object

build postMessage to reply specific user

Parameters:

  • user (string)

    name or id of user

  • channel (string)

    channel id

  • text (string)

    message

  • options (hash) (defaults to: {})

    options

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/slatan/mouth/ext/chat.rb', line 19

def reply(user, channel, text, options={})
  user = user.to_s if user.kind_of?(Symbol)
  user_id = Affiliation::Users.is_id?(user) ? user : Affiliation::Users.get_id(user)
  if user_id.nil?
    Buttocks.error("user '#{user}' is not exist. (reply_message)")
    return
  end
  reply_text = "<@#{user_id}>: #{text}"
  send('postMessage', {
    channel: channel,
    text: reply_text
  }.merge(options))
end