lita-twilio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ea54e16ff61284f26512a7abdf827ec4f36301b
4
+ data.tar.gz: 2975d3c78eca632904e2aff90792e937ded3d2f2
5
+ SHA512:
6
+ metadata.gz: 9f6852c357516807af1736b1e3fbbe8c59fedaab9d94bd11b0b8ab6419871243ba3e5da3fa297f00cfb4ad14ef13d95f45496396bd39cd1b5147c1615660357e
7
+ data.tar.gz: da28a3a876ec1610cc44fe7c36a2541e20bf7cbca5e271d4245aa15a4ae84c934cd89fb3aa255bcd8bd30b99a3570baacc991b0b2052562a7df411bbdfa0ae7e
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ secrets.txt
20
+ fixtures/vcr_cassettes/*
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+ gem 'lita'
3
+ gem 'rack-test'
4
+ gem 'twilio-ruby'
5
+ gem 'vcr'
6
+ gem 'rspec-core'
7
+ gem 'simplecov'
8
+ gem 'coveralls'
9
+ gem 'rspec'
10
+ gem 'webmock'
11
+ gem 'rake'
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ [![Build Status](https://travis-ci.org/chriswoodrich/lita-twilio.svg?branch=master)](https://travis-ci.org/chriswoodrich/lita-twilio) [![Coverage Status](https://coveralls.io/repos/chriswoodrich/lita-twilio/badge.svg)](https://coveralls.io/r/chriswoodrich/lita-twilio)
2
+
3
+ # lita-twilio
4
+
5
+ Lita-Twilio integrates your Twilio account into Lita. Send and receive text messages from your company chat room.
6
+
7
+ ## Installation
8
+
9
+ Add lita-twilio to your Lita instance's Gemfile:
10
+
11
+ ``` gem "lita-twilio" ```
12
+
13
+ ## Configuration
14
+
15
+ There's a bit of Yak-shaving to do here, sorry.
16
+
17
+ ### Required attributes
18
+ * **default_room** (`String`) - The room or person Lita will message on receipt of incoming SMS.
19
+ * **account_sid** (`String`) Your Twilio account's sid.
20
+ * **auth_token** (`String`) Your Twilio account's auth_token.
21
+ * **phone_number** (`String`) Your Twilio account's phone_number.
22
+ * **server_token** (`String`) A keyphrase you will use to authenticate requests to the :post route. You'll need this token to properly setup Twilio callbacks to power the receive route.
23
+
24
+ ### Twilio Account Setup
25
+ * If you have the free account, you'll need to manually add and verify numbers to which you want to send.
26
+ * Go to ```https://www.twilio.com/user/account/phone-numbers/incoming``` and change the ```Request URL``` under messages to ```http://yourdomain.com/twilio?token=VALUE-OF-YOUR-CONFIG-SERVER_TOKEN```.
27
+
28
+ ## Usage
29
+
30
+ *```Litabot: sms 415-867-5309 Hello Jenny``` will send an SMS to (415) 867-5309 with the message "Hello Jenny"
31
+ * Phone numbers must be strictly in the XXX-XXX-XXXX format, and sms or SMS (case insensitive) must be used as a command to Litabot.
32
+ * Any incoming messages to your Twilio account will be displayed with the message and sender.
33
+
34
+ ## License
35
+
36
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,49 @@
1
+ module Lita
2
+ module Handlers
3
+ class Twilio < Handler
4
+
5
+ require 'twilio-ruby'
6
+
7
+ config :default_room, type: String, required: true
8
+ config :account_sid, type: String, required: true
9
+ config :auth_token, type: String, required: true
10
+ config :phone_number, type: String, required: true
11
+ config :server_token, type: String, required: true
12
+
13
+ http.post '/twilio', :receive_sms
14
+
15
+ route %r{^sms ([0-9]{3}-[0-9]{3}-[0-9]{4}) (.*)}i, :send_sms, help: {
16
+ "litabot: sms 415-867-5309 message content" => "Sends the SMS message to the number inputted"
17
+ }
18
+
19
+ def target
20
+ @target ||= config.default_room
21
+ end
22
+
23
+ def receive_sms(request, response)
24
+ return unless request.params.delete('token') == config.server_token
25
+ if request && request.params && !request.params.empty?
26
+ decoded = MultiJson.load(request.params.keys.first)
27
+ robot.send_message(target, "Message from #{decoded['From']}: #{decoded['Body']}")
28
+ end
29
+ end
30
+
31
+ def send_sms(response)
32
+ begin
33
+ client = ::Twilio::REST::Client.new(config.account_sid, config.auth_token)
34
+
35
+ if client.account.messages.create(:from => config.phone_number,
36
+ :to => response.matches[0][0],
37
+ :body => response.matches[0][1])
38
+ robot.send_message(target, "Sent message to #{response.matches[0][0]}")
39
+ end
40
+ rescue Exception => e
41
+ robot.send_message(@target, "Failed to send message: #{e.message}")
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ Lita.register_handler(Twilio)
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/twilio"
8
+
9
+ Lita::Handlers::Twilio.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-twilio"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Chris Woodrich"]
5
+ spec.email = ["cwoodrich@gmail.com"]
6
+ spec.description = "Twilio integration for Lita"
7
+ spec.summary = "Send and receive SMS with from your Lita-configured chat room"
8
+ spec.homepage = "https://github.org/chriswoodrich/lita-twilio"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.2"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rack-test"
22
+ spec.add_development_dependency "rspec", ">= 3.0.0"
23
+ spec.add_development_dependency "simplecov"
24
+ spec.add_development_dependency "coveralls"
25
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ twilio:
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+ require 'vcr'
3
+
4
+ describe Lita::Handlers::Twilio, lita_handler: true do
5
+ it { is_expected.to route_http(:post, "/twilio?token=#{ENV['SERVER_TOKEN']}").to(:receive_sms) }
6
+ it { is_expected.to route_command("sms 415-867-5309 JENNNNNNY").to(:send_sms) }
7
+
8
+
9
+ before do
10
+ registry.config.handlers.twilio.default_room = ENV["DEFAULT_ROOM"]
11
+ registry.config.handlers.twilio.account_sid = ENV["ACCOUNT_SID"]
12
+ registry.config.handlers.twilio.auth_token = ENV["AUTH_TOKEN"]
13
+ registry.config.handlers.twilio.phone_number = ENV["PHONE_NUMBER"]
14
+ registry.config.handlers.twilio.server_token = ENV["SERVER_TOKEN"]
15
+ registry.config.http.host = '127.0.0.1'
16
+ registry.config.http.port = '8080'
17
+ end
18
+
19
+ describe '#receive' do
20
+ let(:request) do
21
+ request = double('Rack::Request')
22
+ allow(request).to receive(:params).and_return(params)
23
+ request
24
+ end
25
+ let(:params) { {'Body' => 'Hi Lita!', 'From' => 'Jimmy'} }
26
+ let(:response) { Rack::Response.new }
27
+ it 'sends alerts user to the received message' do
28
+ http.post("/twilio?token=#{ENV['SERVER_TOKEN']}", params.to_json)
29
+ expect(replies.last).to include('Hi Lita!')
30
+ end
31
+ end
32
+
33
+ describe '#send_sms' do
34
+ it "Outputs a message that a message was sent, given proper params" do
35
+ VCR.use_cassette('sms') do
36
+ t = ENV["TEST_RECIPIENT_PHONE_NUMBER"]
37
+ send_command("sms #{t} this is a test message")
38
+ expect(replies.last).to eq "Sent message to #{t}"
39
+ end
40
+ end
41
+ it "Fails gracefully if Twilio generates an exception" do
42
+ send_command("sms 000-000-0000 OK computer")
43
+ expect(replies.last).to include('Failed to send message:')
44
+ end
45
+ end
46
+
47
+ describe "Twilio is pointing the Lita's webserver address and triggers received message callback" do
48
+ it 'should point to Lita\'s post route and trigger a robot message' do
49
+ full = "http://#{Lita.config.http.host}:#{Lita.config.http.port}/twilio?token=#{ENV['SERVER_TOKEN']}"
50
+ response = http.post(full, {'Body' => 'Hi Jimmy!', 'From' => 'Lita'}.to_json )
51
+ expect(response.status).to eq 200
52
+ expect(replies.last).to include('Hi Jimmy!')
53
+ end
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,24 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+ require 'vcr'
9
+ require "lita-twilio"
10
+ require "lita/rspec"
11
+ require 'webmock/rspec'
12
+
13
+
14
+ VCR.configure do |c|
15
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
16
+ c.hook_into :webmock # or :fakeweb
17
+ c.allow_http_connections_when_no_cassette = false
18
+ end
19
+
20
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
21
+ # was generated with Lita 4, the compatibility mode should be left disabled.
22
+ Lita.version_3_compatibility_mode = false
23
+
24
+
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-twilio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Woodrich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Twilio integration for Lita
112
+ email:
113
+ - cwoodrich@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-twilio.rb
124
+ - lib/lita/handlers/twilio.rb
125
+ - lita-twilio.gemspec
126
+ - locales/en.yml
127
+ - spec/lita/handlers/twilio_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.org/chriswoodrich/lita-twilio
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ lita_plugin_type: handler
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.3
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Send and receive SMS with from your Lita-configured chat room
154
+ test_files:
155
+ - spec/lita/handlers/twilio_spec.rb
156
+ - spec/spec_helper.rb