sipgate_io 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f30b274bab11bd493409b71dfd60537942d7342a
4
- data.tar.gz: 332a7828f261fc6609bffb04d6f610d9ea7ef7af
3
+ metadata.gz: d250a89b7760c16184aafb4a732e0cee508dcf7d
4
+ data.tar.gz: f5495d6e33dfee38b7325481418cf3450dafbf39
5
5
  SHA512:
6
- metadata.gz: 629927f349be9610dee7a64fc4c481dd07bfc722d35c725437c8d154b4ebb53a1be4742486f457dd1e7b1726509ad810799fb6c264b1a772f9d1b84e86f012ec
7
- data.tar.gz: 7297f3857e245530be42e771391b342b599b3a6c7feb33e3913c65d27fd51a86a7ba2d63ef9a8af9e642ac697a021742372939d972343bfea31e6c8202efa6f5
6
+ metadata.gz: 386852cee73a88acc8adf787998d72bc8740d6e13660f36cdfcbb57dfabc48020ba093b535bed173add08ae15a1409add364d7cd8896e267da0c4fbc2fd99403
7
+ data.tar.gz: 20632df508025f91b636bb2878a50d3709fdd334fa0363da5b70f37ed73d00b2de6e99e95fe18ee187d8d655d1e5208943412598a2e294617a3743aac12ff799
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # gem "sipgate_io"
2
+ [![Gem Version](https://badge.fury.io/rb/sipgate_io.svg)](https://badge.fury.io/rb/sipgate_io)
3
+ [![Build Status](https://travis-ci.org/superbilk/sipgate_io.svg?branch=master)](https://travis-ci.org/superbilk/sipgate_io)
4
+
5
+ This project rocks and uses MIT-LICENSE.
6
+
7
+ ## Receive realtime call meta data in your Rails app
8
+
9
+ This gem is a Rails engine that provides an endpoint for sipgate.io that parses these Push-API POSTs and hands off a
10
+ built event object to a class implemented by you.
11
+
12
+ ### sipgate says:
13
+
14
+ > sipgate.io is sipgate's new Push-API. With sipgate.io booked, we send you call meta data every time someone calls. And when someone picks up. And when someone hangs up.
15
+
16
+ ### Requirement: Account with sipgate
17
+
18
+ You need an account and phonenumber with sipgate. A free sipgate basic account is sufficient.
19
+
20
+ * [x] [Create a free sipgate basic account](https://www.sipgate.de/go)
21
+ * [x] [Book the sipgate.io feature](https://www.sipgate.de/go/feature-store/sipgate.io)
22
+ * [x] [Enter an URL for incoming/outgoing calls in the dashboard](https://www.sipgate.de/go/dashboard)
23
+
24
+ ### Have a working example in 5 Minutes
25
+
26
+ There is a fully working example app included in this gem.
27
+
28
+ * Have your sipgate account ready (you can create one in a minute, see above)
29
+ * You need [ngrok](https://ngrok.com/) to receive a POST from sipgate on your locale machine
30
+ * Clone this gem `git clone https://github.com/superbilk/sipgate_io.git` and cd into it `cd sipgate_io`
31
+ * Go to app root `cd test/dummy`
32
+ * Make sure all gems are installed `bundle install`
33
+ * Start rails app `rails s`
34
+ * Start ngrok in another terminal `ngrok http 3000` you get a secure forwarding URL like `https://999b1wa06.ngrok.io`
35
+ * Add your forwarding URL to your sipgate account, don't forget to add `/sipgate_io` (`https://999b1wa06.ngrok.io/sipgate_io`). Use the same URL for incoming & outgoing calls
36
+ * Make a phonecall and you will see the call in realtime in your console (the one with the rails server running)
37
+ * Change what happens with the call here [`test/dummy/app/models/event_processor.rb`](https://github.com/superbilk/sipgate_io/blob/master/test/dummy/app/models/event_processor.rb)
38
+
39
+ You can also check out my complete Rails 5 (beta2) app with ActionCable with a sipgate.io proof of concept. IT' called [callmonitor](https://github.com/superbilk/callmonitor)
40
+
41
+ ## Installation
42
+
43
+ 1. Add `sipgate_io` gem to your application's Gemfile
44
+ and run `bundle install`.
45
+
46
+ 2. A route is needed for the endpoint which receives `POST` messages. To add the
47
+ route, in `config/routes.rb` you may either use the provided routing method
48
+ `mount_sipgate_io` or set the route explicitly. Examples:
49
+
50
+ ```ruby
51
+ # config/routes.rb
52
+
53
+ # mount using default path: /sipgate_io
54
+ mount_sipgate_io
55
+
56
+ # mount using a custom path
57
+ mount_sipgate_io('/call/push')
58
+
59
+ # the DIY approach:
60
+ post '/call_processor' => 'sipgate_io/events#create'
61
+ ```
62
+
63
+ ### Configuration Options
64
+
65
+ An initializer can be created to control some of the options in sipgate_io.
66
+ Defaults are shown below with sample overrides following. In
67
+ `config/initializers/sipgate_io.rb`:
68
+
69
+ ```ruby
70
+ SipgateIo.configure do |config|
71
+ config.processor_class = EventProcessor # CountMyCalls
72
+ config.processor_method = :process # :add_call (A method on CountMyCalls)
73
+ config.callback_url = "https://example.org/sipgate_io"
74
+ end
75
+ ```
76
+
77
+ | Option | Meaning
78
+ | ------ | -------
79
+ | `processor_class` | The class sipgate.io will use to handle your incoming events.
80
+ | `processor_method` | The method sipgate.io will call on the processor class when handling your incoming events.
81
+ | `callback_url` | Used for DTMF, on_answer and on_hangup.
82
+
83
+ By default sipgate.io will look for a class named `EventProcessor`. The class is
84
+ initialized with a event object representing the event, and has a `process` method to actually process the event.
85
+ For example, in `./lib/event_processor.rb`:
86
+
87
+ ```ruby
88
+ class EventProcessor
89
+ def initialize(event)
90
+ @event = event
91
+ end
92
+
93
+ def process
94
+ # all of your application-specific code here - creating models,
95
+ # processing reports, etc
96
+ return SipgateIo::XmlResponse.hangup
97
+ end
98
+ end
99
+ ```
100
+
101
+ Keep in mind, that Rails does NOT autoload files in `lib`. You can conveniently put tis file in `controllers` or `models` - there it is autoloaded.
102
+
103
+
104
+ ## How to use it
105
+
106
+ You find the API documentation here: https://github.com/sipgate/sipgate.io
107
+
108
+ This gem makes the usage a bit more rubiesque. (call_id instead of callId, e.g.)
109
+
110
+ ## Response helper
111
+
112
+ Your EventProcessor has to decide what to to with an event (hangup this call, forward it to voicemail, ...). You can build your own XML as shown in the sipgate documentation. To make your life easier, there are helper methods you can use.
113
+
114
+ Here are some examples:
115
+
116
+ ```ruby
117
+ # don't answer that call
118
+ SipgateIo::XmlResponse.reject
119
+ SipgateIo::XmlResponse.reject(reason: :busy)
120
+ SipgateIo::XmlResponse.reject(reason: :rejected)
121
+ SipgateIo::XmlResponse.hangup
122
+
123
+ # forward that call
124
+ SipgateIo::XmlResponse.dial(target: :voicemail)
125
+ SipgateIo::XmlResponse.dial(target: "491234567", callback: :on_hangup)
126
+ SipgateIo::XmlResponse.dial(target: "491234567", clip: :anonymous)
127
+ SipgateIo::XmlResponse.dial(target: "491234567", clip: "555")
128
+
129
+ # play an announcement
130
+ SipgateIo::XmlResponse.play(soundfile_url: "http://some.wav", callback: :on_answer)
131
+
132
+ # wait for DTMF
133
+ SipgateIo::XmlResponse.gather()
134
+ SipgateIo::XmlResponse.gather(soundfile_url: "http://some.wav", timeout: 5000, callback: :on_hangup)
135
+ ```
136
+
137
+ ## Testing In Your App
138
+
139
+ * tba
140
+
141
+ ## Credits
142
+
143
+ Most of the code is copied fom Griddler by Caleb Thompson and Joel Oliveira / thoughtbot.
144
+ You find the code [here](https://github.com/thoughtbot/griddler)
@@ -3,6 +3,7 @@ require_dependency "sipgate_io/application_controller"
3
3
  module SipgateIo
4
4
  class EventsController < ApplicationController
5
5
  skip_before_action :verify_authenticity_token, raise: false
6
+ before_action :add_response_header
6
7
 
7
8
  def create
8
9
  (head 500 and return) unless params.key?(:event)
@@ -18,6 +19,10 @@ module SipgateIo
18
19
 
19
20
  private
20
21
 
22
+ def add_response_header
23
+ response.headers["X-API-Client"] = "sipgate_io-#{SipgateIo::VERSION} (source: https://github.com/superbilk/sipgate_io)"
24
+ end
25
+
21
26
  def create_event(params)
22
27
  event_type = params[:event].clone
23
28
  event_type[0] = event_type[0].upcase
@@ -1,3 +1,3 @@
1
1
  module SipgateIo
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -112,3 +112,15 @@ Started POST "/sipgate_io" for 217.116.118.254 at 2016-02-12 22:08:57 +0100
112
112
  Processing by SipgateIo::EventsController#create as XML
113
113
  Parameters: {"event"=>"newCall", "direction"=>"out", "from"=>"4915792303200", "to"=>"498003303000", "callId"=>"1208245019208840124", "user"=>["Christian Schmidt"]}
114
114
  Completed 200 OK in 3ms (Views: 0.1ms | ActiveRecord: 0.0ms)
115
+
116
+
117
+ Started POST "/sipgate_io" for ::1 at 2016-02-17 19:22:38 +0100
118
+ Processing by SipgateIo::EventsController#create as */*
119
+ Parameters: {"from"=>"492111234567", "to"=>"4915791234567", "direction"=>"in", "event"=>"newCall", "callId"=>"123456", "user"=>["Alice", "Bob"]}
120
+ Completed 200 OK in 5ms (Views: 0.1ms | ActiveRecord: 0.0ms)
121
+
122
+
123
+ Started POST "/sipgate_io" for ::1 at 2016-02-17 19:23:00 +0100
124
+ Processing by SipgateIo::EventsController#create as */*
125
+ Parameters: {"from"=>"492111234567", "to"=>"4915791234567", "direction"=>"in", "event"=>"newCall", "callId"=>"123456", "user"=>["Alice", "Bob"]}
126
+ Completed 200 OK in 2ms (Views: 0.2ms | ActiveRecord: 0.0ms)