Class: ApiAiWrapper::Trainers::IntentTrainer

Inherits:
Components::TrainerComponent show all
Defined in:
lib/api_ai_wrapper/trainers/intent_trainer.rb

Overview

Instance Attribute Summary

Attributes inherited from Components::Component

#engine

Instance Method Summary collapse

Methods inherited from Components::TrainerComponent

#raise_if_unauthorized, #set_headers

Instance Method Details

#delete_intent(iid) ⇒ Object



50
51
52
53
54
# File 'lib/api_ai_wrapper/trainers/intent_trainer.rb', line 50

def delete_intent(iid)
  endpoint_url = URI.join(self.engine.base_url, "intents/#{iid}?v=#{self.engine.version}")

  self.delete(endpoint_url, {})
end

#get_intent(iid) ⇒ Object



17
18
19
20
21
# File 'lib/api_ai_wrapper/trainers/intent_trainer.rb', line 17

def get_intent(iid)
  endpoint_url = URI.join(self.engine.base_url, "intents/#{iid}?v=#{self.engine.version}")

  self.get(endpoint_url, {})
end

#get_intentsObject

api.ai/docs/reference/agent/intents#get_intents Fetches all intents for a given token



9
10
11
12
13
# File 'lib/api_ai_wrapper/trainers/intent_trainer.rb', line 9

def get_intents
  endpoint_url = URI.join(self.engine.base_url, "intents?v=#{self.engine.version}")

  self.get(endpoint_url, {})
end

#post_intent(name, user_says_data, options = {}) ⇒ Object

api.ai/docs/reference/agent/intents#post_intents Creates an intent options can contain (in accordance with API reference) :

  • contexts

  • templates

  • responses



29
30
31
32
33
34
35
36
37
38
# File 'lib/api_ai_wrapper/trainers/intent_trainer.rb', line 29

def post_intent(name, user_says_data, options = {})
  body = options.merge({
    name: name,
    auto: true, # ML activated
    userSays: user_says_data
  })
  endpoint_url = URI.join(self.engine.base_url, "intents?v=#{self.engine.version}")

  self.post(endpoint_url, body.to_json)
end

#put_intent(iid, options = {}) ⇒ Object



42
43
44
45
46
# File 'lib/api_ai_wrapper/trainers/intent_trainer.rb', line 42

def put_intent(iid, options = {})
  endpoint_url = URI.join(self.engine.base_url, "intents/#{iid}?v=#{self.engine.version}")

  self.put(endpoint_url, options.to_json)
end