mock-twilio 1.0.0 → 1.2.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 +16 -15
- data/lib/mock/twilio/decorators/api_2010/calls.rb +8 -3
- data/lib/mock/twilio/version.rb +1 -1
- data/lib/mock/twilio/webhooks/call_status_updates.rb +5 -5
- data/lib/mock/twilio/webhooks/calls.rb +4 -4
- data/lib/mock/twilio/webhooks/conferences.rb +1 -1
- data/lib/mock/twilio/webhooks/voicemail.rb +55 -0
- data/lib/mock/twilio.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 310cc33586ef04e160217a0dfd84d974ac767e6f81d9af3f09d051f9fd802114
|
4
|
+
data.tar.gz: e8e3391a767e0e5ba9270e4615df0dba90174b9715c8260c25c390155176829b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcd5088423808878c3ba15bc7c2e36be36600ab2d4dc735d3f5d89ea9c37e29d0dc8a485b186ab01261bdcd3fb2d9f688f0f27ac9e9245930017883647cb41c2
|
7
|
+
data.tar.gz: 428a6a44af8c26c0f3e06dd53863be5a68fd4efe94bc616f7bb3f712d8661853932a26171c15a69abff45174bee648800e25ce3d255f13e4d06cff8b3b0f978f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,22 +28,22 @@ OR
|
|
28
28
|
|
29
29
|
## Features Support
|
30
30
|
|
31
|
-
| Mock::Twilio::Client
|
31
|
+
| Support | Mock::Twilio::Client |
|
32
32
|
| ------------- | ------------- |
|
33
|
-
| `client.messages.create(to: "+593978613041", body: "Testing SMS", from: "+13212855389")` |
|
34
|
-
| `client.messaging.v1.services("MG"+"F"*32).phone_numbers.create(phone_number_sid: @phone_number_sid)` |
|
35
|
-
| `client.available_phone_numbers('US').local.list(limit: 20)` |
|
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")` |
|
37
|
-
| `client.lookups.v2.phone_numbers("+14159929960").fetch(fields: :line_type_intelligence)` |
|
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')` |
|
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')` |
|
40
|
-
| `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` |
|
41
|
-
| `client.trusthub.v1.customer_profiles(customer_profile_sid).customer_profiles_entity_assignments.create(object_sid:)` |
|
42
|
-
| `client.trusthub.v1.end_users.create(**twilio_parameters)`
|
43
|
-
| `client.trusthub.v1.supporting_documents.create(**twilio_parameters)` |
|
44
|
-
| `client.addresses.create(**twilio_parameters)` |
|
45
|
-
| `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` |
|
46
|
-
| `client.trusthub.v1.customer_profiles(customer_profile.sid).customer_profiles_evaluations.create(policy_sid:)` |
|
33
|
+
| :white_check_mark: | `client.messages.create(to: "+593978613041", body: "Testing SMS", from: "+13212855389")` |
|
34
|
+
| :white_check_mark: | `client.messaging.v1.services("MG"+"F"*32).phone_numbers.create(phone_number_sid: @phone_number_sid)` |
|
35
|
+
| :white_check_mark: | `client.available_phone_numbers('US').local.list(limit: 20)` |
|
36
|
+
| :white_check_mark: | `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")` |
|
37
|
+
| :white_check_mark: | `client.lookups.v2.phone_numbers("+14159929960").fetch(fields: :line_type_intelligence)` |
|
38
|
+
| :white_check_mark: | `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')` |
|
39
|
+
| :white_check_mark: | `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')` |
|
40
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` |
|
41
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles(customer_profile_sid).customer_profiles_entity_assignments.create(object_sid:)` |
|
42
|
+
| :white_check_mark: | `client.trusthub.v1.end_users.create(**twilio_parameters)`
|
43
|
+
| :white_check_mark: | `client.trusthub.v1.supporting_documents.create(**twilio_parameters)` |
|
44
|
+
| :white_check_mark: | `client.addresses.create(**twilio_parameters)` |
|
45
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles.create(**twilio_attributes)` |
|
46
|
+
| :white_check_mark: | `client.trusthub.v1.customer_profiles(customer_profile.sid).customer_profiles_evaluations.create(policy_sid:)` |
|
47
47
|
|
48
48
|
|
49
49
|
## Trigger resources updates
|
@@ -54,6 +54,7 @@ OR
|
|
54
54
|
| `Webhooks::InboundMessages` | :white_check_mark: |
|
55
55
|
| `Webhooks::Calls` | :white_check_mark: |
|
56
56
|
| `Webhooks::CallStatusUpdates` | :white_check_mark: |
|
57
|
+
| `Webhooks::Voicemail` | :white_check_mark: |
|
57
58
|
| `Webhooks::Conferences` | :white_check_mark: |
|
58
59
|
| `Webhooks::CustomerProfiles` | :white_check_mark: |
|
59
60
|
| `Webhooks::Brands` | :white_check_mark: |
|
@@ -30,15 +30,20 @@ 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', 'ringing')
|
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
|
-
|
41
|
+
# Participant
|
42
|
+
participant_ringing = Mock::Twilio::Webhooks::Calls.trigger(sid, 'ringing') if conference_response.success?
|
43
|
+
participant_completed = Mock::Twilio::Webhooks::Calls.trigger(sid, 'completed') if participant_ringing.success?
|
44
|
+
|
45
|
+
call_completed = Mock::Twilio::Webhooks::CallStatusUpdates.trigger(sid, conference_uuid, 'human', 'completed') if participant_completed.success?
|
46
|
+
Mock::Twilio::Webhooks::Voicemail.trigger(sid) if call_completed.success? && [true,false].sample
|
42
47
|
rescue => e
|
43
48
|
puts e
|
44
49
|
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, call_status)
|
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, call_status)
|
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, call_status)
|
37
37
|
{
|
38
38
|
:AccountSid=> twilio_client.account_sid,
|
39
39
|
:ApiVersion=> "2010-04-01",
|
@@ -50,7 +50,7 @@ module Mock
|
|
50
50
|
:CallerState=> "CA",
|
51
51
|
:CallerZip=> "no value",
|
52
52
|
:CallSid=> sid,
|
53
|
-
:CallStatus=>
|
53
|
+
:CallStatus=> call_status,
|
54
54
|
:Direction=> "outbound-api",
|
55
55
|
:Duration=> "0",
|
56
56
|
:From=> "+18111111111",
|
@@ -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
|
@@ -6,13 +6,13 @@ module Mock
|
|
6
6
|
class Calls < Base
|
7
7
|
URL = "/api/v1/twilio_calls/participant_status_changes"
|
8
8
|
|
9
|
-
def self.trigger(sid)
|
9
|
+
def self.trigger(sid, participant_status)
|
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_data(sid)
|
15
|
+
data = call_data(sid, participant_status)
|
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_data(sid)
|
36
|
+
def self.call_data(sid, participant_status)
|
37
37
|
{
|
38
38
|
:AccountSid=> twilio_client.account_sid,
|
39
39
|
:ApiVersion=> "2010-04-01",
|
@@ -50,7 +50,7 @@ module Mock
|
|
50
50
|
:CallerState=> "CA",
|
51
51
|
:CallerZip=> "no value",
|
52
52
|
:CallSid=> sid,
|
53
|
-
:CallStatus=>
|
53
|
+
:CallStatus=> participant_status,
|
54
54
|
:Direction=> "outbound-api",
|
55
55
|
:Duration=> "0",
|
56
56
|
:From=> "+18111111111",
|
@@ -41,7 +41,7 @@ module Mock
|
|
41
41
|
:FriendlyName=> friendly_name,
|
42
42
|
:SequenceNumber=> "6",
|
43
43
|
:ConferenceSid=> sid,
|
44
|
-
:StatusCallbackEvent=> "conference-
|
44
|
+
:StatusCallbackEvent=> "conference-end",
|
45
45
|
:Timestamp=> "2024-06-17 16:49:31 UTC",
|
46
46
|
:AccountSid=> twilio_client.account_sid,
|
47
47
|
:Reason=> "Participant from mock twilio"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Twilio
|
5
|
+
module Webhooks
|
6
|
+
class Voicemail < Base
|
7
|
+
URL = "/api/v1/twilio_calls/create_voicemail"
|
8
|
+
|
9
|
+
def self.trigger(call_sid)
|
10
|
+
# Wait simulation from twilio
|
11
|
+
sleep DELAY.sample
|
12
|
+
|
13
|
+
request_url = Mock::Twilio.proto + "://" + Mock::Twilio.forwarded_host + URL
|
14
|
+
|
15
|
+
data = voicemail_data(call_sid)
|
16
|
+
|
17
|
+
signature = build_signature_for_request(request_url, data)
|
18
|
+
|
19
|
+
response = webhook_client.request(Mock::Twilio.host,
|
20
|
+
Mock::Twilio.port,
|
21
|
+
'POST',
|
22
|
+
URL,
|
23
|
+
nil,
|
24
|
+
data,
|
25
|
+
headers.merge!({ 'X-Twilio-Signature': signature }),
|
26
|
+
auth_twilio,
|
27
|
+
nil)
|
28
|
+
case response.status
|
29
|
+
when 200..204
|
30
|
+
response
|
31
|
+
when 400..600
|
32
|
+
raise Webhooks::RestError, Mock::Twilio::ErrorHandler.new(response).raise
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.voicemail_data(call_sid)
|
37
|
+
prefix = "RE"
|
38
|
+
recording_sid = prefix + SecureRandom.hex(16)
|
39
|
+
{
|
40
|
+
:RecordingSource=> "RecordVerb",
|
41
|
+
:RecordingSid=> recording_sid,
|
42
|
+
:RecordingUrl=> "https://cdn.pixabay.com/download/audio/2022/03/24/audio_4ff823c44c.mp3?filename=ding-101492.mp3",
|
43
|
+
:RecordingStatus=> "completed",
|
44
|
+
:RecordingChannels=> "1",
|
45
|
+
:ErrorCode=> "0",
|
46
|
+
:CallSid=> call_sid,
|
47
|
+
:RecordingStartTime=> Time.current.rfc2822,
|
48
|
+
:AccountSid=> twilio_client.account_sid,
|
49
|
+
:RecordingDuration=> "4"
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/mock/twilio.rb
CHANGED
@@ -14,6 +14,7 @@ require_relative "twilio/webhooks/conferences"
|
|
14
14
|
require_relative "twilio/webhooks/customer_profiles"
|
15
15
|
require_relative "twilio/webhooks/brands"
|
16
16
|
require_relative "twilio/webhooks/inbound_messages"
|
17
|
+
require_relative "twilio/webhooks/voicemail"
|
17
18
|
require_relative "twilio/util/configuration"
|
18
19
|
require_relative "twilio/util/error_handler"
|
19
20
|
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: 1.
|
4
|
+
version: 1.2.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-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/mock/twilio/webhooks/customer_profiles.rb
|
120
120
|
- lib/mock/twilio/webhooks/inbound_messages.rb
|
121
121
|
- lib/mock/twilio/webhooks/messages.rb
|
122
|
+
- lib/mock/twilio/webhooks/voicemail.rb
|
122
123
|
- lib/twilio/rest/messaging/v1/service/phone_number_decorator.rb
|
123
124
|
- sig/mock/twilio.rbs
|
124
125
|
homepage: https://github.com/schoolstatus/mock-twilio
|
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
- !ruby/object:Gem::Version
|
144
145
|
version: '0'
|
145
146
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.4.19
|
147
148
|
signing_key:
|
148
149
|
specification_version: 4
|
149
150
|
summary: This repository contains Mock::Twilio::Client and Webhooks for Twilio's API.
|