tropo-webapi-sdk-ruby 15.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/LICENSE +21 -0
- data/README.md +249 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/sinatra_server.rb +194 -0
- data/lib/tropo-webapi-ruby/object_patch.rb +13 -0
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb +253 -0
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby.rb +903 -0
- data/lib/tropo-webapi-ruby.rb +5 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/tropo-webapi-ruby_spec.rb +637 -0
- data/tropo-webapi-ruby.gemspec +58 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d318399f0e321377af8bb4f0572664f19c884afe
|
4
|
+
data.tar.gz: d5ca6fac58e74ddc15dd92d3fcf137b8707373c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4189478223535ee3a44a6dbf0b87a33e70771ca96dea1a1388d93170fd727d20a77cdaa0c7ee49c72dac83275eecbfdc44643126becba2d0ae7943631d091700
|
7
|
+
data.tar.gz: 20f5aabfe66c851d451ea80a3df26c535443b0eb5513b5c0b5253e78242c063a7fb6387c84987c9aba76b865c35c9cc7243c3f71ed19d02f6938db2e8fda1359
|
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Voxeo, Corporation
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
# Tropo Web API Ruby Library
|
2
|
+
[](https://drone.io/github.com/tropo/tropo-webapi-ruby/latest)
|
3
|
+
|
4
|
+
A Ruby library for interaction with the Tropo Web API (http://tropo.com) using JSON.
|
5
|
+
|
6
|
+
## Tropo Web API Overview
|
7
|
+
|
8
|
+
The Tropo Remote API provides a RESTful JSON API for controlling realtime communications applications from
|
9
|
+
your own web servers.
|
10
|
+
|
11
|
+
## Requirements
|
12
|
+
|
13
|
+
* Unit tests passed on: Ruby MRI v1.8.6/1.8.7/1.9.3/2.1.0 and JRuby v1.5.0/v1.7.9
|
14
|
+
* RubyGems
|
15
|
+
|
16
|
+
Note: If using with ActiveSupport, v2.3.5 or better of ActiveSupport is required.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
$ sudo gem install tropo-webapi-ruby
|
21
|
+
|
22
|
+
Optional, if you would like to use with Sinatra:
|
23
|
+
|
24
|
+
$ sudo gem install sinatra
|
25
|
+
|
26
|
+
## Generate Documentation
|
27
|
+
|
28
|
+
### Developer
|
29
|
+
|
30
|
+
$ gemserver
|
31
|
+
|
32
|
+
### Project Developer
|
33
|
+
|
34
|
+
$ sudo gem install yard
|
35
|
+
|
36
|
+
From within the project:
|
37
|
+
|
38
|
+
$ yardoc
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
```ruby
|
42
|
+
require 'rubygems'
|
43
|
+
require 'tropo-webapi-ruby'
|
44
|
+
|
45
|
+
# Will return the properly formatted JSON to pass to Tropo
|
46
|
+
response = Tropo::Generator.ask({ :say => 'Hello world!' })
|
47
|
+
|
48
|
+
# Will return a Ruby Hash, with some transformations, from the JSON string received from Tropo
|
49
|
+
response = Tropo::Generator.parse(json_string)
|
50
|
+
|
51
|
+
# Will provide instance variables that will allow you to easily reference session type
|
52
|
+
tropo = Tropo::Generator.new
|
53
|
+
response = tropo.parse(json_string)
|
54
|
+
p 'Hey, this is a voice session!' if tropo.voice_session
|
55
|
+
p 'Hey, this is a text messaging session!' if tropo.text_session
|
56
|
+
```
|
57
|
+
## Examples
|
58
|
+
|
59
|
+
### Sinatra
|
60
|
+
|
61
|
+
Using the great RESTful Web Services framework Sinatra for Ruby.
|
62
|
+
|
63
|
+
#### Hello World
|
64
|
+
```ruby
|
65
|
+
require 'rubygems'
|
66
|
+
require 'sinatra'
|
67
|
+
require 'tropo-webapi-ruby'
|
68
|
+
|
69
|
+
post '/helloworld.json' do
|
70
|
+
Tropo::Generator.say 'Hello World!'
|
71
|
+
end
|
72
|
+
|
73
|
+
post '/helloworld_block.json' do
|
74
|
+
tropo = Tropo::Generator.new do
|
75
|
+
say 'Hello World!'
|
76
|
+
end
|
77
|
+
tropo.response
|
78
|
+
end
|
79
|
+
|
80
|
+
post '/helloworld_twice.json' do
|
81
|
+
tropo = Tropo::Generator.new
|
82
|
+
tropo.say 'Hello World!'
|
83
|
+
tropo.say 'Hello again.'
|
84
|
+
tropo.response
|
85
|
+
end
|
86
|
+
```
|
87
|
+
#### Getting Session Information
|
88
|
+
```ruby
|
89
|
+
# Produces a Ruby hash:
|
90
|
+
#
|
91
|
+
# { :session =>
|
92
|
+
# { :timestamp => Tue Jan 19 18:27:46 -0500 2010,
|
93
|
+
# :user_type =>"HUMAN",
|
94
|
+
# :initial_text => nil,
|
95
|
+
# :account_id =>"0",
|
96
|
+
# :headers => [{ "value" => "70", "key"=>"Max-Forwards" },
|
97
|
+
# { "value" => "385", "key"=>"Content-Length" },
|
98
|
+
# { "value" => "<sip:127.0.0.1:49152>", "key"=>"Contact" },
|
99
|
+
# { "value" => "replaces", "key"=>"Supported" },
|
100
|
+
# { "value" => "<sip:sample.json@localhost:5555>", "key"=>"To" },
|
101
|
+
# { "value" => "1 INVITE", "key"=>"CSeq" },
|
102
|
+
# { "value" => "SJphone-M/1.65.382f (SJ Labs)", "key"=>"User-Agent" },
|
103
|
+
# { "value" => "SIP/2.0/UDP 127.0.0.1:49152;branch=z9000000a9;rport=49152", "key"=>"Via" },
|
104
|
+
# { "value" => "3FA7C70A1DD211B286B7A583D7B46DDD0xac106207", "key"=>"Call-ID" },
|
105
|
+
# { "value" => "application/sdp", "key"=>"Content-Type" },
|
106
|
+
# { "value" => "unknown <sip:127.0.0.1:49152>;tag=750b1b1648e9c876", "key"=>"From" }],
|
107
|
+
# :id => "3FA7C70A1DD211B286B7A583D7B46DDD0xac106207",
|
108
|
+
# :to => { :network => "PSTN",
|
109
|
+
# :channel => "VOICE",
|
110
|
+
# :name => "unknown",
|
111
|
+
# :id => "sample.json"},
|
112
|
+
# :from => { :network => "PSTN",
|
113
|
+
# :channel => "VOICE",
|
114
|
+
# :name => "unknown",
|
115
|
+
# :id => "unknown"}}}
|
116
|
+
#
|
117
|
+
post '/start_session.json' do
|
118
|
+
tropo_session = Tropo::Generator.parse request.env["rack.input"].read
|
119
|
+
p tropo_session
|
120
|
+
end
|
121
|
+
```
|
122
|
+
#### Asking for input and receiving the response, or catching a hangup
|
123
|
+
```ruby
|
124
|
+
post '/ask.json' do
|
125
|
+
tropo = Tropo::Generator.new do
|
126
|
+
on :event => 'hangup', :next => '/hangup.json'
|
127
|
+
on :event => 'continue', :next => '/answer.json'
|
128
|
+
ask({ :name => 'account_number',
|
129
|
+
:bargein => true,
|
130
|
+
:timeout => 30,
|
131
|
+
:require => 'true' }) do
|
132
|
+
say :value => 'Please say your account number'
|
133
|
+
choices :value => '[5 DIGITS]'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
tropo.response
|
137
|
+
end
|
138
|
+
|
139
|
+
# Produces a Ruby hash, if the user gives a response before hanging up:
|
140
|
+
#
|
141
|
+
# { :result =>
|
142
|
+
# { :actions => { :attempts => 1,
|
143
|
+
# :disposition => "SUCCESS",
|
144
|
+
# :interpretation => "12345",
|
145
|
+
# :confidence => 100,
|
146
|
+
# :name => "account_number",
|
147
|
+
# :utterance => "1 2 3 4 5" },
|
148
|
+
# :session_duration => 3,
|
149
|
+
# :error => nil,
|
150
|
+
# :sequence => 1,
|
151
|
+
# :session_id => "5325C262-1DD2-11B2-8F5B-C16F64C1D62E@127.0.0.1",
|
152
|
+
# :state => "ANSWERED",
|
153
|
+
# :complete => true } }
|
154
|
+
#
|
155
|
+
post '/answer.json' do
|
156
|
+
tropo_event = Tropo::Generator.parse request.env["rack.input"].read
|
157
|
+
p tropo_event
|
158
|
+
end
|
159
|
+
|
160
|
+
# Produces a Ruby hash, if the user hangs up before giving a reponse
|
161
|
+
# { :result =>
|
162
|
+
# { :actions => {},
|
163
|
+
# :session_duration => 1,
|
164
|
+
# :error => nil,
|
165
|
+
# :sequence => 1,
|
166
|
+
# :session_id => "812BEF50-1DD2-11B2-8F5B-C16F64C1D62E@127.0.0.1",
|
167
|
+
# :state => "DISCONNECTED",
|
168
|
+
# :complete => true } }
|
169
|
+
#
|
170
|
+
post '/hangup.json' do
|
171
|
+
tropo_event = Tropo::Generator.parse request.env["rack.input"].read
|
172
|
+
p tropo_event
|
173
|
+
end
|
174
|
+
```
|
175
|
+
#### Redirect a call before answering
|
176
|
+
```ruby
|
177
|
+
# A redirect method
|
178
|
+
post '/redirect.json' do
|
179
|
+
Tropo::Generator.redirect({ :to => 'sip:1234', :from => '4155551212' })
|
180
|
+
end
|
181
|
+
```
|
182
|
+
#### Reject a call before answering
|
183
|
+
```ruby
|
184
|
+
# A reject method
|
185
|
+
post '/reject.json' do
|
186
|
+
Tropo::Generator.reject
|
187
|
+
end
|
188
|
+
```
|
189
|
+
#### Setting a default voice for speech synthesis (text-to-speech/TTS)
|
190
|
+
```ruby
|
191
|
+
post '/speak.json' do
|
192
|
+
t = Tropo::Generator.new(:voice => 'kate')
|
193
|
+
t.say 'Hello!' # Will speak as kate now
|
194
|
+
|
195
|
+
# or
|
196
|
+
|
197
|
+
t = Tropo::Generator.new
|
198
|
+
t.voice = 'kate'
|
199
|
+
t.say 'Hello!' # Will speak as kate now
|
200
|
+
end
|
201
|
+
```
|
202
|
+
#### Setting a default recognizer for speech recognition (ASR)
|
203
|
+
```ruby
|
204
|
+
post '/ask.json' do
|
205
|
+
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
206
|
+
t.ask({ :name => 'account_number', # Will now use the French speech recognition engine
|
207
|
+
:bargein => true,
|
208
|
+
:timeout => 30,
|
209
|
+
:require => 'true' }) do
|
210
|
+
say :value => "S'il vous plaît dire votre numéro de compte", :voice => 'florence'
|
211
|
+
choices :value => '[5 DIGITS]'
|
212
|
+
end
|
213
|
+
|
214
|
+
# or
|
215
|
+
|
216
|
+
t = Tropo::Generator.new
|
217
|
+
t.recognizer = 'fr-fr'
|
218
|
+
t.ask({ :name => 'account_number', # Will now use the French speech recognition engine
|
219
|
+
:bargein => true,
|
220
|
+
:timeout => 30,
|
221
|
+
:require => 'true' }) do
|
222
|
+
say :value => "S'il vous plaît dire votre numéro de compte", :voice => 'florence'
|
223
|
+
choices :value => '[5 DIGITS]'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
```
|
227
|
+
### Additional Examples
|
228
|
+
|
229
|
+
May be found by checking out the project from Github, and then looking in $PROJECT_HOME/examples and $PROJECT_HOME/spec/tropo-webapi-ruby_spec.rb.
|
230
|
+
|
231
|
+
### Documentation
|
232
|
+
|
233
|
+
* API Documentation:
|
234
|
+
|
235
|
+
http://voxeo.github.com/tropo-webapi-ruby
|
236
|
+
|
237
|
+
* Tropo Web API Documentation
|
238
|
+
|
239
|
+
http://docs.tropo.com/webapi/2.0/home.htm
|
240
|
+
|
241
|
+
## Notes
|
242
|
+
|
243
|
+
In order to maintain compatibility between Ruby MRI and JRuby the gem requires 'json_pure'. If you are using the Ruby MRI and would prefer to use the C version of 'json', simply install the 'json' gem as follows:
|
244
|
+
|
245
|
+
sudo gem install json
|
246
|
+
|
247
|
+
## Copyright
|
248
|
+
|
249
|
+
Copyright (c) 2014 Tropo, Inc. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "tropo-webapi-ruby"
|
9
|
+
gem.summary = "Tropo Web API Ruby Gem"
|
10
|
+
gem.description = "Ruby library for interacting with the Tropo Web API via REST & JSON"
|
11
|
+
gem.email = "jsgoecke@voxeo.com"
|
12
|
+
gem.homepage = "http://tropo.com"
|
13
|
+
gem.authors = ["Jason Goecke"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.files.include %w(lib/tropo-webapi-ruby.rb lib/tropo-webapi-ruby/tropo-webapi-ruby.rb lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb LICENSE VERSION README.markdown)
|
16
|
+
#gem.add_dependency('json', '>= 1.2.0')
|
17
|
+
gem.add_dependency('json_pure', '>= 1.2.0')
|
18
|
+
gem.add_dependency('hashie', '>= 3.2.0')
|
19
|
+
gem.required_ruby_version = '>= 1.8.6'
|
20
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rspec/core/rake_task'
|
28
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
33
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
+
spec.rcov = true
|
35
|
+
end
|
36
|
+
|
37
|
+
task :spec => :check_dependencies
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "tropo #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
50
|
+
|
51
|
+
YARD::Rake::YardocTask.new do |t|
|
52
|
+
t.files = ['lib/tropo-webapi-ruby/*.rb', 'lib/*.rb', 'README']
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
15.12.0
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'sinatra'
|
4
|
+
require '../lib/tropo-webapi-ruby'
|
5
|
+
|
6
|
+
enable :sessions
|
7
|
+
|
8
|
+
post '/index.json' do
|
9
|
+
tropo = Tropo::Generator.new do
|
10
|
+
on :event => 'continue', :next => '/the_answer.json'
|
11
|
+
ask({ :name => 'account_number',
|
12
|
+
:bargein => 'true',
|
13
|
+
:timeout => 30,
|
14
|
+
:require => 'true' }) do
|
15
|
+
say :value => 'Please enter your account number'
|
16
|
+
choices :value => '[5 DIGITS]'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
tropo.response
|
20
|
+
end
|
21
|
+
|
22
|
+
post '/the_answer.json' do
|
23
|
+
Tropo::Generator.hangup
|
24
|
+
end
|
25
|
+
|
26
|
+
post '/helloworld.json' do
|
27
|
+
json_session = request.env["rack.input"].read
|
28
|
+
p json_session
|
29
|
+
tropo_session = Tropo::Generator.parse json_session
|
30
|
+
Tropo::Generator.say :value => 'Hello World!'
|
31
|
+
end
|
32
|
+
|
33
|
+
# ===
|
34
|
+
# Ask answer example
|
35
|
+
post '/ask.json' do
|
36
|
+
tropo = Tropo::Generator.new do
|
37
|
+
on :event => 'hangup', :next => '/hangup.json'
|
38
|
+
on :event => 'continue', :next => '/answer.json'
|
39
|
+
ask({ :name => 'account_number',
|
40
|
+
:bargein => 'true',
|
41
|
+
:timeout => 30,
|
42
|
+
:require => 'true' }) do
|
43
|
+
say :value => 'Please say your account number'
|
44
|
+
choices :value => '[5 DIGITS]'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
tropo.response
|
48
|
+
end
|
49
|
+
|
50
|
+
post '/answer.json' do
|
51
|
+
tropo_event = Tropo::Generator.parse request.env["rack.input"].read
|
52
|
+
p tropo_event
|
53
|
+
end
|
54
|
+
|
55
|
+
post '/hangup.json' do
|
56
|
+
tropo_event = Tropo::Generator.parse request.env["rack.input"].read
|
57
|
+
p tropo_event
|
58
|
+
end
|
59
|
+
# ===
|
60
|
+
post '/say_goodbye.json' do
|
61
|
+
Tropo::Generator.say :value => 'Thank you. Goodbye.'
|
62
|
+
end
|
63
|
+
|
64
|
+
post '/start.json' do
|
65
|
+
tropo_session = Tropo::Generator.parse request.env["rack.input"].read
|
66
|
+
session[:callid] = tropo_session[:session][:id]
|
67
|
+
tropo = Tropo::Generator.new do
|
68
|
+
say :value => 'Hello World!'
|
69
|
+
on :event => 'hangup', :next => '/hangup.json'
|
70
|
+
end
|
71
|
+
tropo.response
|
72
|
+
end
|
73
|
+
|
74
|
+
post '/disconnect.json' do
|
75
|
+
tropo = Tropo::Generator.hangup
|
76
|
+
p tropo
|
77
|
+
tropo
|
78
|
+
end
|
79
|
+
|
80
|
+
post '/hangup.json' do
|
81
|
+
p 'Received a hangup response!'
|
82
|
+
json_string = request.env["rack.input"].read
|
83
|
+
tropo_session = Tropo::Generator.parse json_string
|
84
|
+
p tropo_session
|
85
|
+
end
|
86
|
+
|
87
|
+
post '/conference.json' do
|
88
|
+
tropo = Tropo::Generator.conference({ :name => 'foo',
|
89
|
+
:id => '1234',
|
90
|
+
:mute => false,
|
91
|
+
:send_tones => false,
|
92
|
+
:exit_tone => '#' }) do
|
93
|
+
on(:event => 'join') { say :value => 'Welcome to the conference' }
|
94
|
+
on(:event => 'leave') { say :value => 'Someone has left the conference' }
|
95
|
+
end
|
96
|
+
tropo
|
97
|
+
end
|
98
|
+
|
99
|
+
post '/result.json' do
|
100
|
+
tropo_result = Tropo::Generator.parse request.env["rack.input"].read
|
101
|
+
p tropo_result
|
102
|
+
end
|
103
|
+
|
104
|
+
post '/nomatch.json' do
|
105
|
+
Tropo::Generator.say :value => 'Something went terribly wrong!'
|
106
|
+
end
|
107
|
+
|
108
|
+
post '/redirect.json' do
|
109
|
+
response = Tropo::Generator.redirect(:to => 'sip:9991427589@sip.tropo.com')
|
110
|
+
p response
|
111
|
+
response
|
112
|
+
end
|
113
|
+
|
114
|
+
post '/reject.json' do
|
115
|
+
response = Tropo::Generator.reject
|
116
|
+
p response
|
117
|
+
response
|
118
|
+
end
|
119
|
+
|
120
|
+
post '/total_recording.json' do
|
121
|
+
tropo = Tropo::Generator.new do
|
122
|
+
start_recording :name => 'ladeda', :url => 'http://postthis/mofo'
|
123
|
+
say :value => 'I am now recording!'
|
124
|
+
stop_recording
|
125
|
+
end
|
126
|
+
p tropo.response
|
127
|
+
tropo.response
|
128
|
+
end
|
129
|
+
|
130
|
+
post '/record.json' do
|
131
|
+
response = Tropo::Generator.record({ :name => 'foo',
|
132
|
+
:url => 'http://sendme.com/tropo',
|
133
|
+
:beep => true,
|
134
|
+
:send_tones => false,
|
135
|
+
:exit_tone => '#' }) do
|
136
|
+
say :value => 'Please say your account number'
|
137
|
+
choices :value => '[5 DIGITS]'
|
138
|
+
end
|
139
|
+
p response
|
140
|
+
response
|
141
|
+
end
|
142
|
+
|
143
|
+
post '/session_scope.json' do
|
144
|
+
session = Hash.new
|
145
|
+
session[:foo] = 'bar'
|
146
|
+
tropo = Tropo::Generator.new(session) do
|
147
|
+
p session
|
148
|
+
say 'Do we now see the session?'
|
149
|
+
end
|
150
|
+
tropo.response
|
151
|
+
end
|
152
|
+
|
153
|
+
post '/transfer_request.json' do
|
154
|
+
tropo = Tropo::Generator.new do
|
155
|
+
say 'Hello, about to transfer you'
|
156
|
+
transfer :to => 'sip:9991427589@sip.tropo.com'
|
157
|
+
say 'I like rocks!'*10
|
158
|
+
end
|
159
|
+
p tropo.response
|
160
|
+
tropo.response
|
161
|
+
end
|
162
|
+
|
163
|
+
post '/ons.json' do
|
164
|
+
tropo = Tropo::Generator.new
|
165
|
+
p tropo.on :event => 'hangup', :next => '/hangup.json'
|
166
|
+
p tropo.on :event => 'continue', :next => '/next_resource.json'
|
167
|
+
tropo.say 'That was a boat load of ons...'
|
168
|
+
tropo.response
|
169
|
+
end
|
170
|
+
|
171
|
+
post '/on_with_block.json' do
|
172
|
+
tropo = Tropo::Generator.new
|
173
|
+
p tropo.on :event => 'hangup', :next => '/hangup.json'
|
174
|
+
p tropo.on :event => 'continue', :next => '/next_resource.json' do
|
175
|
+
say 'About to send you to the next menu.'
|
176
|
+
end
|
177
|
+
tropo.say 'That was a boat load of ons...'
|
178
|
+
tropo.response
|
179
|
+
end
|
180
|
+
|
181
|
+
post '/test_json.json' do
|
182
|
+
t = Tropo::Generator.new
|
183
|
+
t.on :event => 'error', :next => '/error.json' # For fatal programming errors. Log some details so we can fix it
|
184
|
+
t.on :event => 'hangup', :next => '/hangup.json' # When a user hangs or call is done. We will want to log some details.
|
185
|
+
t.on :event => 'continue', :next => '/next.json'
|
186
|
+
t.say "Hello"
|
187
|
+
t.start_recording(:name => 'recording', :url => "http://heroku-voip.marksilver.net/post_audio_to_s3?filename=foo.wav&unique_id=bar")
|
188
|
+
# [From this point, until stop_recording(), we will record what the caller *and* the IVR say]
|
189
|
+
t.say "You are now on the record."
|
190
|
+
# Prompt the user to incriminate themselve on-the-record
|
191
|
+
t.say "Go ahead, sing-along."
|
192
|
+
t.say "http://denalidomain.com/music/keepers/HappyHappyBirthdaytoYou-Disney.mp3"
|
193
|
+
t.response
|
194
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Borrowed from here: http://eigenclass.org/hiki.rb?instance_exec
|
2
|
+
class Object
|
3
|
+
def instance_exec(*args, &block)
|
4
|
+
mname = "__instance_exec_#{Thread.current.object_id.abs}"
|
5
|
+
class << self; self end.class_eval{ define_method(mname, &block) }
|
6
|
+
begin
|
7
|
+
ret = send(mname, *args)
|
8
|
+
ensure
|
9
|
+
class << self; self end.class_eval{ undef_method(mname) } rescue nil
|
10
|
+
end
|
11
|
+
ret
|
12
|
+
end
|
13
|
+
end
|