ruboty-call 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad76eb632070b3eb2184732e92e81a227c2c6fd2
4
+ data.tar.gz: a9ac5a7cb11c04818bbe3e2939a3e0f41465dad9
5
+ SHA512:
6
+ metadata.gz: 85508d2443942477ae6298e7a1ba73a13ac361287ff174c05324740f10a168b7bdd64e91c2217ef327f40037e4a1dc927dd4bb35ba5cdb0959dc846f5e725439
7
+ data.tar.gz: 55b7b7701d897356219415300e1426c44c54c1791a566ee7a4d390aac17485224007ed4302488b31e864cf9509873c40a6098bb927f96b8b2f1d83624d4c6270
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-call.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 block_given?
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Ruboty::Call
2
+
3
+ ruboty plugin for make a call to you.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-call'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-call
20
+
21
+ ## Usage
22
+
23
+ You need to get [Twilio](https://jp.twilio.com/) account and set these environment variables
24
+
25
+ | env | description |
26
+ | ------------------- | ------------------- |
27
+ | TWILIO_ACCOUNT_SID | twilio account sid |
28
+ | TWILIO_AUTH_TOKEN | twilio auth token |
29
+ | RUBOTY_PHONE_NUMBER | twilio phone number |
30
+
31
+ then:
32
+
33
+ @ruboty call +81xxyyyyzzzz オーケー、ルボティー
34
+
35
+ 呼び出し中です。
36
+ 相手が応答し、通話中です。
37
+ 相手が応答し、通話中です。
38
+ 相手が応答し、通話中です。
39
+ 相手が応答し、通話が正常に終了しました。
40
+ recordings:
41
+ https://api.twilio.com/****-**-**/Accounts/****/Recordings/****.mp3
42
+ https://api.twilio.com/****-**-**/Accounts/****/Recordings/****.mp3
43
+
44
+ You can set language which ruboty speaks by environment variable. the default language is ja-JP.
45
+
46
+ RUBOTY_LANG=en-US bundle exec ruboty
47
+
48
+ see more available languages from:
49
+
50
+ https://jp.twilio.com/docs/api/twiml/say#attributes-language
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( https://github.com/blockgiven/ruboty-call/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,9 @@
1
+ require "ruboty/call/version"
2
+ require "ruboty/call/actions/call"
3
+ require "ruboty/handlers/call"
4
+
5
+ module Ruboty
6
+ module Call
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,106 @@
1
+ require 'twilio-ruby'
2
+ require 'uri'
3
+
4
+ module Ruboty
5
+ module Call
6
+ module Actions
7
+ class Call < Ruboty::Actions::Base
8
+ STATUS_REFRESH_INTERVAL = 5
9
+ MAX_RECORDING_TIME = 20
10
+
11
+ def call
12
+ phone_call
13
+ end
14
+
15
+ private
16
+
17
+ def from
18
+ ENV['RUBOTY_PHONE_NUMBER']
19
+ end
20
+
21
+ def language
22
+ ENV['RUBOTY_LANG'] || 'ja-JP'
23
+ end
24
+
25
+ def max_recording_time
26
+ MAX_RECORDING_TIME
27
+ end
28
+
29
+ def phone_call
30
+ c = twilio_client.account.calls.create({
31
+ :to => to,
32
+ :from => from,
33
+ :url => twiml_url,
34
+ :method => 'GET',
35
+ :fallback_method => 'GET',
36
+ :status_callback_method => 'GET',
37
+ :record => 'true'
38
+ })
39
+
40
+ loop do
41
+ sleep STATUS_REFRESH_INTERVAL
42
+
43
+ c.refresh
44
+
45
+ if %w(queued ringing in-progress).include?(c.status)
46
+ next message.reply(status_text[c.status])
47
+ end
48
+
49
+ message.reply(status_text[c.status])
50
+ recs = c.recordings.list
51
+ if recs.size.nonzero?
52
+ urls = recs.map {|r| "https://api.twilio.com#{r.uri.gsub(/.json$/, '.mp3')}" }
53
+ message.reply("おへんじ:#{$/}#{urls.join($/)}")
54
+ end
55
+ break
56
+ end
57
+ rescue
58
+ message.reply("なにかに失敗したよ.")
59
+ end
60
+
61
+ def text
62
+ message[:text]
63
+ end
64
+
65
+ def to
66
+ message[:to]
67
+ end
68
+
69
+ def status_text
70
+ {
71
+ 'queued' => '通話は発信待ち状態です。',
72
+ 'ringing' => '呼び出し中です。',
73
+ 'in-progress' => '相手が応答し、通話中です。',
74
+ 'canceled' => 'queued または ringing 中に、通話がキャンセルされました。',
75
+ 'completed' => '相手が応答し、通話が正常に終了しました。',
76
+ 'busy' => '相手からビジー信号を受信しました。',
77
+ 'failed' => '通話を接続できませんでした。通常は、ダイヤルした電話番号が存在しません。',
78
+ 'no-answer' => '相手が応答せず、通話が終了しました。'
79
+ }
80
+ end
81
+
82
+ def twilio_client
83
+ # put your own credentials here
84
+ account_sid = ENV['TWILIO_ACCOUNT_SID']
85
+ auth_token = ENV['TWILIO_AUTH_TOKEN']
86
+
87
+ Twilio::REST::Client.new account_sid, auth_token
88
+ end
89
+
90
+ def twiml
91
+ <<TWIML
92
+ <?xml version="1.0" encoding="UTF-8"?>
93
+ <Response>
94
+ <Say voice="alice" language="#{language}">#{text}</Say>
95
+ <Record maxLength="#{max_recording_time}" />
96
+ </Response>
97
+ TWIML
98
+ end
99
+
100
+ def twiml_url
101
+ "http://twimlets.com/echo?Twiml=#{URI.escape(twiml)}"
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Call
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Call < Base
4
+ env :TWILIO_ACCOUNT_SID, 'twilio account sid'
5
+ env :TWILIO_AUTH_TOKEN, 'twilio auth token'
6
+ env :RUBOTY_PHONE_NUMBER, 'twilio phone number'
7
+ env :RUBOTY_LANG, 'which language ruboty speaks. details: https://jp.twilio.com/docs/api/twiml/say#attributes-language', optional: true
8
+
9
+ on /call \+(?<to>\d+) (?<text>.*)/, name: 'phone_call', description: "make a call, and record #{Ruboty::Call::Actions::Call::MAX_RECORDING_TIME}sec"
10
+
11
+ # call is already used in ruboty
12
+ def phone_call(message)
13
+ Ruboty::Call::Actions::Call.new(message).call
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/call/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-call"
8
+ spec.version = Ruboty::Call::VERSION
9
+ spec.authors = ["block_given?"]
10
+ spec.email = ["block_given@outlook.com"]
11
+ spec.summary = %q{ruboty plugin for make a call to you.}
12
+ spec.homepage = "https://github.com/blockgiven/ruboty-call"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "ruboty"
21
+ spec.add_runtime_dependency "twilio-ruby"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-call
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - block_given?
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: twilio-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - block_given@outlook.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/call.rb
82
+ - lib/ruboty/call/actions/call.rb
83
+ - lib/ruboty/call/version.rb
84
+ - lib/ruboty/handlers/call.rb
85
+ - ruboty-call.gemspec
86
+ homepage: https://github.com/blockgiven/ruboty-call
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: ruboty plugin for make a call to you.
110
+ test_files: []