Skip to content

Commit

Permalink
TROPO-12173
Browse files Browse the repository at this point in the history
Add answer to TROPO JSON helper library with support for RPID parameters
- WebAPI Ruby
  • Loading branch information
frankyuCisco committed Aug 25, 2017
1 parent a052df8 commit 5529274
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/answer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'lib/tropo-webapi-ruby'

require 'sinatra'

set :bind => "192.168.26.1"
set :port => "12457"


post '/index.json' do

t = Tropo::Generator.new

t.answer :headers => {:keey1 => "gffdddddddddddddd",
:keey2 => "value 2 here"}

t.say :value => "i am answer method say content",
:name => "justaname"

headers \
"WebAPI-Lang-Ver" => "ruby-frank20170824",
"rubyversion" => "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]"

"This is t.response, where is t.response"
t.response # def response line 464

end


post '/continue.json' do

v = Tropo::Generator.parse request.env["rack.input"].read
t = Tropo::Generator.new
#pppppppquts v
userType = v[:result][:user_type]
#pppppppquts userType
t.say(:value => "You are a #{userType}")

t.response

end
27 changes: 27 additions & 0 deletions lib/tropo-webapi-ruby/tropo-webapi-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ def ask(params={}, &block)
end
alias :prompt :ask

##
# Prompts initiates a new answer.
#
# @overload answer(params)
# @param [Hash] params the options to create a answer action request with.
# @option params [optional, Hash] :headers A set of key/values
# @overload answer(params, &block)
# @param [Hash] params the options to create an answer action request with.
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
# @option params [optional, Hash] :headers A set of key/values
# @return [String, nil] the JSON string to be passed back to Tropo or nil
# if the method has been called from inside a block
def answer(params={}, &block)
if block_given?
create_nested_hash('answer', params)
instance_exec(&block)
@response[:tropo] << @nested_hash
@nested_hash = nil
@nested_name = nil
else
hash = build_action('answer', params)
@response[:tropo] << hash
end
render_response if @building.nil?
end


##
# Prompts initiates a new call. May only be used when no call is active.
#
Expand Down

0 comments on commit 5529274

Please sign in to comment.