Class: FSR::Cmd::Chat

Inherits:
Command show all
Defined in:
lib/fsr/cmd/chat.rb

Constant Summary

Constants inherited from Command

FSR::Cmd::Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_socket = nil, args = {}) ⇒ Chat

Returns a new instance of Chat.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fsr/cmd/chat.rb', line 8

def initialize(fs_socket = nil, args = {})
  
  raise(ArgumentError, "args (Passed: <<<#{args}>>>) must be a hash") unless args.kind_of?(Hash)

  @fs_socket = fs_socket # FSR::CommandSocket obj
  @protocol = args[:protocol] ? args[:protocol] : 'sip'
  raise(ArgumentError, "Cannot send chat with invalid protocol") unless @protocol.to_s.size > 0
  @from = args[:from] # i.e. [email protected]
  raise(ArgumentError, "Cannot send chat without :from set") unless @from.to_s.size > 0
  @to   = args[:to]   # i.e. [email protected]
  raise(ArgumentError, "Cannot send chat without :to set") unless @to.to_s.size > 0
  @message = args[:message]
  raise(ArgumentError, "Cannot send chat without :message set") unless @message.to_s.size > 0
  @message.gsub!('|', '\|')
end

Instance Attribute Details

#fs_socketObject (readonly)

Returns the value of attribute fs_socket.



6
7
8
# File 'lib/fsr/cmd/chat.rb', line 6

def fs_socket
  @fs_socket
end

Instance Method Details

#rawObject

This method builds the API command to send to the freeswitch event socket



32
33
34
# File 'lib/fsr/cmd/chat.rb', line 32

def raw
  %Q(chat #{@protocol}|#{@from}|#{@to}|#{@message})
end

#run(api_method = :api) ⇒ Object

Send the command to the event socket, using api by default.



25
26
27
28
29
# File 'lib/fsr/cmd/chat.rb', line 25

def run(api_method = :api)
  orig_command = "%s %s" % [api_method, raw]
  Log.debug "saying #{orig_command}"
  @fs_socket.say(orig_command)
end