Class: BotSpec::AWS::LexService

Inherits:
Object
  • Object
show all
Defined in:
lib/botspec/lex/lex_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ LexService

Returns a new instance of LexService.



10
11
12
13
14
15
16
17
18
# File 'lib/botspec/lex/lex_service.rb', line 10

def initialize(config)
  if config[:stub_responses]
    @lex_client = Aws::Lex::Client.new(stub_responses: true)
    @lex_client.stub_responses(config[:stub_responses][:operation_to_stub], config[:stub_responses][:stub_data])
  end
  @config = config
  @bot_name = config[:botname]
  @user_id = "botspec-#{SecureRandom.uuid}"
end

Class Method Details

.load(config) ⇒ Object



6
7
8
# File 'lib/botspec/lex/lex_service.rb', line 6

def self.load(config)
  return LexService.new(config)
end

Instance Method Details

#interaction_to_lex_message(message) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/botspec/lex/lex_service.rb', line 24

def interaction_to_lex_message(message)
  return {
    bot_name: @bot_name,
    bot_alias: "$LATEST",
    user_id: @user_id,
    session_attributes: {
      "String" => "String",
    },
    request_attributes: {
      "String" => "String",
    },
    input_text: message,
  }
end

#lex_clientObject



20
21
22
# File 'lib/botspec/lex/lex_service.rb', line 20

def lex_client
  @lex_client ||= Aws::Lex::Client.new
end

#post_message(message, user_id = '') ⇒ Object



39
40
41
42
43
# File 'lib/botspec/lex/lex_service.rb', line 39

def post_message message, user_id=''
  resp = lex_client.post_text(interaction_to_lex_message(message))
  sleep(1);
  resp
end