Class: BotBaseModulePhrases

Inherits:
Object
  • Object
show all
Defined in:
lib/botbase-module-phrases.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: nil, reg: nil, keywords: '', px_url: nil, voiceassistant: 'emma', callback: nil) ⇒ BotBaseModulePhrases

Returns a new instance of BotBaseModulePhrases.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/botbase-module-phrases.rb', line 16

def initialize(host: nil, reg: nil, keywords: '', 
            px_url: nil, voiceassistant: 'emma', callback: nil)

  @rsc = RSC.new host
  
  # px may be use in future for advanced rules which use conditionals
  #px = Polyrex.new px_url
  
  @keywords, @voiceassistant, @bot = keywords, voiceassistant, callback
  botlog = @bot.log ? @bot.log : nil

  @ste = SPSTriggerExecute.new keywords, reg=nil, px=nil, log: botlog

end

Instance Method Details

#query(sender = 'user01', said, mode: :voicechat, echo_node: 'node1') ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/botbase-module-phrases.rb', line 31

def query(sender='user01', said, mode: :voicechat, echo_node: 'node1')    
      
  #puts 'inside phrases::query()' + said.inspect
  
  a = @ste.mae message: said

  if a.length > 0 then
    
    h = {
    
      rse: ->(x, rsc){
      
        job = x.shift[/\/\/job:(.*)/,1]                  
        package_path = x.shift 
        package = package_path[/([^\/]+)\.rsf$/,1]
        
        rsc.run_job package, job, {}, args=x, package_path: package_path
      }, 
      rse_uri: ->(x, rsc){
      
        Rse.call x          
        
      },         
      sps: ->(x, rsc){
                      
        topic, msg = x.split(':',2)
                      
        fqm = (topic == 'reply' and mode == :voicechat) ? 
                     echo_node + "/echo/#{@voiceassistant}: " + msg : x

        @bot.notice fqm
     },
      ste: ->(x, rsc){ @ste.run x }
    }

  end
          
  
  r = nil
          
  a2 = a.map do |type, x| 
    
      
    if @bot.log then
      
      instruction = x.length > 60 ? x[0..57] + '...' : x
      @bot.log.info "BotBaseModulePhrases/query: matched type: %," + 
          " instruction: %s in response to %s" % [type, instruction, said]
      
    end
    
    begin
      r = h[type].call x, @rsc
    rescue

      if @bot.log then
        @bot.log.debug 'BotBaseModulePhrases/query/error: ' + ($!).inspect
      end

    end
    
    
    if type == :sps and x[/^reply/] and mode != :voicechat then

      r = x[/:\s*(.*)/,1].to_s
      
    else
      
      r

    end
    
  end # /each           
  
  return a2.join(' ')      
  
end