Class: RasaCore::Client

Inherits:
Object
  • Object
show all
Includes:
ResponseFormatter, TyphoeusClient
Defined in:
lib/rasa_core/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResponseFormatter

#format_response_body

Methods included from TyphoeusClient

#run_request

Constructor Details

#initialize(args = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/rasa_core/client.rb', line 7

def initialize(args={})
  @server = args[:server]
  @port = args[:port]
end

Instance Attribute Details

#response_formatObject

Returns the value of attribute response_format.



5
6
7
# File 'lib/rasa_core/client.rb', line 5

def response_format
  @response_format
end

Instance Method Details

#append_action(args = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/rasa_core/client.rb', line 54

def append_action(args={})
  body = {
    event: 'action',
    timestamp: args[:timestamp],
    name: args[:name],
    policy: args[:policy],
    confidence: args[:confidence]}
  append_event_to_tracker(args, body)
end

#append_slot(args = {}) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/rasa_core/client.rb', line 40

def append_slot(args={})
  body = {
    event: 'slot',
    timestamp: args[:timestamp],
    name: args[:name],
    value: args[:value]}
  append_event_to_tracker(args, body)
end

#check_healthObject



12
13
14
# File 'lib/rasa_core/client.rb', line 12

def check_health
  build_response(run_request(url: build_url), :no_format)
end

#conversation_tracker(args = {}) ⇒ Object



33
34
35
36
37
38
# File 'lib/rasa_core/client.rb', line 33

def conversation_tracker(args={})
  path = ['conversations', args[:sender_id] || "default", 'tracker'].join('/')
  query = {include_events: args[:include_events] || "AFTER_RESTART"}
  url = build_url(path: path, query: query)
  build_response(run_request(url: url))
end

#reset_slots(args = {}) ⇒ Object



49
50
51
52
# File 'lib/rasa_core/client.rb', line 49

def reset_slots(args={})
  body = {event: 'reset_slots', timestamp: args[:timestamp]}
  append_event_to_tracker(args, body)
end

#send_message(args = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/rasa_core/client.rb', line 26

def send_message(args={})
  path = "webhooks/rest/webhook"
  body = {sender: args[:sender_id] || 'default', message: args[:message]}
  response = run_request(url: build_url(path: path), body: body, method: 'post')
  build_response(response)
end

#statusObject



21
22
23
24
# File 'lib/rasa_core/client.rb', line 21

def status
  response = run_request(url: build_url(path: 'status'))
  build_response(response)
end

#versionObject



16
17
18
19
# File 'lib/rasa_core/client.rb', line 16

def version
  response = run_request(url: build_url(path: 'version'))
  build_response(response)
end