mock-twilio 0.8.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +32 -1
- data/lib/mock/twilio/decorators/api_2010/calls.rb +5 -3
- data/lib/mock/twilio/decorators/api_2010/messages.rb +10 -1
- data/lib/mock/twilio/version.rb +1 -1
- data/lib/mock/twilio/webhooks/call_status_updates.rb +4 -4
- data/lib/mock/twilio/webhooks/calls.rb +1 -1
- data/lib/mock/twilio/webhooks/inbound_messages.rb +65 -0
- data/lib/mock/twilio.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0288825792a2120cef9986fac4b2b0d862870f8684494d6e5cd5ff56118e2df4'
|
4
|
+
data.tar.gz: 114f34bac6342aaacaec7717e8b4dbd167534dbaa2256f295280fb689b2bcb40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b28d6052491c9fe19af3239b06472b8d2ca31e519f3ea18df82ce506f723fe4a9d4de70f59a6e963052b1c13f3bb12a08362aef4bd38340f9c3919c9543be9e
|
7
|
+
data.tar.gz: f6de2b86dd622fa70f2df6825a39a1a2bb06090e34bbf1ae6888f1deb7c4bb64ba7f8e78ce43a011eec806ca59f9b68983195777e7f94f9ab50cdaae4a49efa2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,38 @@ OR
|
|
26
26
|
- `proxy_port = 4010`
|
27
27
|
- `proxy_protocol = http`
|
28
28
|
|
29
|
+
## Features Support
|
30
|
+
|
31
|
+
| Mock::Twilio::Client | Support |
|
32
|
+
| ------------- | ------------- |
|
33
|
+
| `client.messages.create(to: "+593978613041", body: "Testing SMS", from: "+13212855389")` | :white_check_mark: |
|
34
|
+
| `client.messaging.v1.services("MG"+"F"*32).phone_numbers.create(phone_number_sid: @phone_number_sid)` | :white_check_mark: |
|
35
|
+
| `client.available_phone_numbers('US').local.list(limit: 20)` | :white_check_mark: |
|
36
|
+
| `client.incoming_phone_numbers.create(phone_number: "+1987654321", voice_url: "#{BASE_URL}/api/v1/twilio_calls/incoming", sms_url: "#{BASE_URL}/api/v1/twilio_requests/inbound")` | :white_check_mark: |
|
37
|
+
| `client.lookups.v2.phone_numbers("+14159929960").fetch(fields: :line_type_intelligence)` | :white_check_mark: |
|
38
|
+
| `client.calls.create(url: '<http://demo.twilio.com/docs/voice.xml>', to: '+14155551212', from: '+15017122661', status_callback: '<https://myapp.com/events>', status_callback_event: ['ringing'], status_callback_method: 'POST')` | :white_check_mark: |
|
39
|
+
| `client.conferences("CF"+("F")*32).participants.create(label: 'customer', early_media: true, beep: 'onEnter', status_callback: '<https://myapp.com/events>', status_callback_event: ['ringing'], record: true, from: '+15017122661', to: '+15558675310')` | :white_check_mark: |
|
40
|
+
| `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` | :white_check_mark: |
|
41
|
+
| `client.trusthub.v1.customer_profiles(customer_profile_sid).customer_profiles_entity_assignments.create(object_sid:)` | :white_check_mark: |
|
42
|
+
| `client.trusthub.v1.end_users.create(**twilio_parameters)` | :white_check_mark: |
|
43
|
+
| `client.trusthub.v1.supporting_documents.create(**twilio_parameters)` | :white_check_mark: |
|
44
|
+
| `client.addresses.create(**twilio_parameters)` | :white_check_mark: |
|
45
|
+
| `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` | :white_check_mark: |
|
46
|
+
| `client.trusthub.v1.customer_profiles(customer_profile.sid).customer_profiles_evaluations.create(policy_sid:)` | :white_check_mark: |
|
47
|
+
|
48
|
+
|
49
|
+
## Trigger resources updates
|
50
|
+
|
51
|
+
| Mock::Twilio::Webhooks | Support |
|
52
|
+
| ------------- | ------------- |
|
53
|
+
| `Webhooks::Messages` | :white_check_mark: |
|
54
|
+
| `Webhooks::InboundMessages` | :white_check_mark: |
|
55
|
+
| `Webhooks::Calls` | :white_check_mark: |
|
56
|
+
| `Webhooks::CallStatusUpdates` | :white_check_mark: |
|
57
|
+
| `Webhooks::Conferences` | :white_check_mark: |
|
58
|
+
| `Webhooks::CustomerProfiles` | :white_check_mark: |
|
59
|
+
| `Webhooks::Brands` | :white_check_mark: |
|
60
|
+
|
29
61
|
## How to use
|
30
62
|
Initializer sample
|
31
63
|
```ruby
|
@@ -35,7 +67,6 @@ Mock::Twilio.configure do |config|
|
|
35
67
|
config.port = "3000"
|
36
68
|
config.proto = "http"
|
37
69
|
end
|
38
|
-
|
39
70
|
```
|
40
71
|
|
41
72
|
Example
|
@@ -30,15 +30,17 @@ module Mock
|
|
30
30
|
scheduler.in '2s' do
|
31
31
|
conference_uuid = request.data["Url"].split("conference_uuid=").last
|
32
32
|
begin
|
33
|
-
response = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid)
|
33
|
+
response = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, 'unknown')
|
34
34
|
|
35
|
-
conference_response = if response.
|
35
|
+
conference_response = if response.success?
|
36
36
|
twiMl_xml = Nokogiri::XML response.body
|
37
37
|
friendly_name = twiMl_xml.at_xpath('//Dial').at_xpath('//Conference').children.text
|
38
38
|
Mock::Twilio::Webhooks::Conferences.trigger(friendly_name)
|
39
39
|
end
|
40
40
|
|
41
|
-
Mock::Twilio::Webhooks::Calls.trigger(sid) if conference_response.
|
41
|
+
participant_response = Mock::Twilio::Webhooks::Calls.trigger(sid) if conference_response.success?
|
42
|
+
|
43
|
+
Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, 'machine_start') if participant_response.success?
|
42
44
|
rescue => e
|
43
45
|
puts e
|
44
46
|
end
|
@@ -14,8 +14,12 @@ module Mock
|
|
14
14
|
body["end_time"] = Time.current.rfc2822 if body["end_time"]
|
15
15
|
|
16
16
|
message_sid(body, request) if body["sid"]
|
17
|
+
body["messaging_service_sid"] = request.data["MessagingServiceSid"] if request.data["MessagingServiceSid"]
|
17
18
|
pagination(body) if body["available_phone_numbers"]
|
18
19
|
|
20
|
+
body["to"] = request.data["To"] if request.data["To"]
|
21
|
+
body["from"] = request.data["From"] if request.data["From"]
|
22
|
+
|
19
23
|
body
|
20
24
|
end
|
21
25
|
|
@@ -33,7 +37,12 @@ module Mock
|
|
33
37
|
scheduler = Rufus::Scheduler.new
|
34
38
|
scheduler.in '2s' do
|
35
39
|
begin
|
36
|
-
Mock::Twilio::Webhooks::Messages.trigger(sid)
|
40
|
+
response = Mock::Twilio::Webhooks::Messages.trigger(sid)
|
41
|
+
|
42
|
+
if response.success? && request.data["Body"].downcase.include?("inbound")
|
43
|
+
inbound_sid = prefix + SecureRandom.hex(16)
|
44
|
+
Mock::Twilio::Webhooks::InboundMessages.trigger(inbound_sid, request.data)
|
45
|
+
end
|
37
46
|
rescue => e
|
38
47
|
puts e
|
39
48
|
end
|
data/lib/mock/twilio/version.rb
CHANGED
@@ -6,13 +6,13 @@ module Mock
|
|
6
6
|
class CallStatusUpdates < Base
|
7
7
|
URL = "/api/v1/twilio_calls/voice_responses"
|
8
8
|
|
9
|
-
def self.trigger(sid, conference_uuid)
|
9
|
+
def self.trigger(sid, conference_uuid, answered_by)
|
10
10
|
# Wait simulation from twilio
|
11
11
|
sleep DELAY.sample
|
12
12
|
|
13
13
|
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
14
14
|
|
15
|
-
data = call_status_updates_data(sid, conference_uuid)
|
15
|
+
data = call_status_updates_data(sid, conference_uuid, answered_by)
|
16
16
|
|
17
17
|
signature = build_signature_for_request(request_url, data)
|
18
18
|
|
@@ -33,7 +33,7 @@ module Mock
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.call_status_updates_data(sid, conference_uuid)
|
36
|
+
def self.call_status_updates_data(sid, conference_uuid, answered_by)
|
37
37
|
{
|
38
38
|
:AccountSid=> twilio_client.account_sid,
|
39
39
|
:ApiVersion=> "2010-04-01",
|
@@ -68,7 +68,7 @@ module Mock
|
|
68
68
|
:ToZip=> "33605",
|
69
69
|
:StirStatus=> "B",
|
70
70
|
:StirVerstat=> "TN-Validation-Passed-B",
|
71
|
-
:AnsweredBy=>
|
71
|
+
:AnsweredBy=> answered_by,
|
72
72
|
:conference_uuid=> conference_uuid
|
73
73
|
}
|
74
74
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Webhooks
|
6
|
+
class InboundMessages < Base
|
7
|
+
URL = "/api/v1/twilio_requests/inbound"
|
8
|
+
|
9
|
+
def self.trigger(sid, params)
|
10
|
+
raise Webhooks::RestError, "Invalid Inbound message data" if params['To'].empty? || params['From'].empty?
|
11
|
+
# Wait simulation from twilio
|
12
|
+
sleep DELAY.sample
|
13
|
+
|
14
|
+
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
15
|
+
|
16
|
+
data = inbound_data(sid, params)
|
17
|
+
|
18
|
+
signature = build_signature_for_request(request_url, data)
|
19
|
+
|
20
|
+
response = webhook_client.request(Mock::Twilio.host,
|
21
|
+
Mock::Twilio.port,
|
22
|
+
'POST',
|
23
|
+
URL,
|
24
|
+
nil,
|
25
|
+
data,
|
26
|
+
headers.merge!({ 'X-Twilio-Signature': signature }),
|
27
|
+
auth_twilio,
|
28
|
+
nil)
|
29
|
+
case response.status
|
30
|
+
when 200..204
|
31
|
+
response
|
32
|
+
when 400..600
|
33
|
+
raise Webhooks::RestError, Mock::Twilio::ErrorHandler.new(response).raise
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.inbound_data(sid, params)
|
38
|
+
{
|
39
|
+
"ToCountry": "US",
|
40
|
+
"ToState": "MS",
|
41
|
+
"SmsMessageSid": sid,
|
42
|
+
"NumMedia": "0",
|
43
|
+
"ToCity": "SARDIS",
|
44
|
+
"FromZip": "98315",
|
45
|
+
"SmsSid": sid,
|
46
|
+
"FromState": "WA",
|
47
|
+
"SmsStatus": "received",
|
48
|
+
"FromCity": "SILVERDALE",
|
49
|
+
"Body": "Inbound::Message mock reply",
|
50
|
+
"FromCountry": "US",
|
51
|
+
"To": params["To"],
|
52
|
+
"MessagingServiceSid": params['MessagingServiceSid'],
|
53
|
+
"ToZip": "38666",
|
54
|
+
"AddOns": "{\"status\":\"successful\",\"message\":null,\"code\":null,\"results\":{}}",
|
55
|
+
"NumSegments": "1",
|
56
|
+
"MessageSid": sid,
|
57
|
+
"AccountSid": ::Twilio.account_sid,
|
58
|
+
"From": params["From"],
|
59
|
+
"ApiVersion": "2010-04-01"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/mock/twilio.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative "twilio/webhooks/call_status_updates"
|
|
13
13
|
require_relative "twilio/webhooks/conferences"
|
14
14
|
require_relative "twilio/webhooks/customer_profiles"
|
15
15
|
require_relative "twilio/webhooks/brands"
|
16
|
+
require_relative "twilio/webhooks/inbound_messages"
|
16
17
|
require_relative "twilio/util/configuration"
|
17
18
|
require_relative "twilio/util/error_handler"
|
18
19
|
require_relative "twilio/util/generator"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock-twilio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SchoolStatus Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/mock/twilio/webhooks/calls.rb
|
118
118
|
- lib/mock/twilio/webhooks/conferences.rb
|
119
119
|
- lib/mock/twilio/webhooks/customer_profiles.rb
|
120
|
+
- lib/mock/twilio/webhooks/inbound_messages.rb
|
120
121
|
- lib/mock/twilio/webhooks/messages.rb
|
121
122
|
- lib/twilio/rest/messaging/v1/service/phone_number_decorator.rb
|
122
123
|
- sig/mock/twilio.rbs
|