phonomenal_client 0.10.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +71 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +532 -0
- data/Rakefile +12 -0
- data/lib/phonomenal/account_context.rb +33 -0
- data/lib/phonomenal/api_handler.rb +90 -0
- data/lib/phonomenal/audio_response.rb +32 -0
- data/lib/phonomenal/calls.rb +10 -0
- data/lib/phonomenal/campaign_context.rb +147 -0
- data/lib/phonomenal/leads.rb +62 -0
- data/lib/phonomenal/response.rb +23 -0
- data/lib/phonomenal/version.rb +5 -0
- data/lib/phonomenal.rb +98 -0
- data/sig/phonomenal_client.rbs +4 -0
- metadata +78 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phonomenal
|
|
4
|
+
Calls = Struct.new(:client) do
|
|
5
|
+
def create(body, session_id: nil)
|
|
6
|
+
url = session_id.nil? ? client.url_for("/calls") : client.url_for("/sessions/#{session_id}/calls")
|
|
7
|
+
Phonomenal::Response.new(client.post(url, body: body.to_json))
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phonomenal
|
|
4
|
+
# :nodoc:
|
|
5
|
+
module CampaignContext
|
|
6
|
+
def campaign
|
|
7
|
+
@campaign ||= Phonomenal::ApiHandler.new(
|
|
8
|
+
client: self,
|
|
9
|
+
path: "campaign",
|
|
10
|
+
allowed_methods: %i[show update],
|
|
11
|
+
singular: true
|
|
12
|
+
).tap do |handler|
|
|
13
|
+
handler.add_method!(method_name: :clear_webhooks, method: :delete, url_path: "webhooks")
|
|
14
|
+
handler.extend(CampaignVoiceMessageAudio)
|
|
15
|
+
handler.extend(CampaignIvr)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def sessions # rubocop:disable Metrics/MethodLength
|
|
20
|
+
unless @sessions
|
|
21
|
+
@sessions = Phonomenal::ApiHandler.new(
|
|
22
|
+
client: self,
|
|
23
|
+
path: "sessions",
|
|
24
|
+
allowed_methods: %i[index create update destroy],
|
|
25
|
+
singular: false
|
|
26
|
+
)
|
|
27
|
+
@sessions.add_method!(method_name: :start_break, method: :post)
|
|
28
|
+
@sessions.add_method!(method_name: :end_break, method: :post)
|
|
29
|
+
@sessions.add_method!(method_name: :dispose_call, method: :post)
|
|
30
|
+
@sessions.add_method!(method_name: :switch_to_manual, method: :post)
|
|
31
|
+
@sessions.add_method!(method_name: :switch_to_auto, method: :post)
|
|
32
|
+
end
|
|
33
|
+
@sessions
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def sip_configs
|
|
37
|
+
unless @sip_configs
|
|
38
|
+
@sip_configs = Phonomenal::ApiHandler.new(
|
|
39
|
+
client: self,
|
|
40
|
+
path: "sip_configs",
|
|
41
|
+
allowed_methods: %i[index create update destroy activate deactivate show],
|
|
42
|
+
singular: false
|
|
43
|
+
)
|
|
44
|
+
@sip_configs.add_method!(method_name: "borrow", method: :post)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@sip_configs
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def members
|
|
51
|
+
@members ||= Phonomenal::ApiHandler.new(
|
|
52
|
+
client: self,
|
|
53
|
+
path: "members",
|
|
54
|
+
allowed_methods: %i[index create update activate deactivate show],
|
|
55
|
+
singular: false
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def global_dids
|
|
60
|
+
@global_dids ||= Phonomenal::ApiHandler.new(
|
|
61
|
+
client: self,
|
|
62
|
+
path: "global_dids",
|
|
63
|
+
allowed_methods: %i[index],
|
|
64
|
+
singular: false
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
%w[member_groups member_tags black_list_phones holidays inbound_schedule_entries voice_messages].each do |method|
|
|
69
|
+
define_method method do # rubocop:disable Metrics/MethodLength
|
|
70
|
+
handler = instance_variable_get(:"@#{method}")
|
|
71
|
+
unless handler
|
|
72
|
+
handler = Phonomenal::ApiHandler.new(
|
|
73
|
+
client: self,
|
|
74
|
+
path: method,
|
|
75
|
+
allowed_methods: %i[index create update show destroy],
|
|
76
|
+
singular: false
|
|
77
|
+
)
|
|
78
|
+
handler.extend(VoiceMessageAudio) if method == "voice_messages"
|
|
79
|
+
instance_variable_set(:"@#{method}", handler)
|
|
80
|
+
end
|
|
81
|
+
handler
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# The audio of a campaign's voice messages
|
|
86
|
+
module VoiceMessageAudio
|
|
87
|
+
# The generated audio: the message, or a sample read with its default
|
|
88
|
+
# values when it's personalized. Fails (404) until it's generated.
|
|
89
|
+
def audio(id)
|
|
90
|
+
Phonomenal::AudioResponse.new(client.get(url_for("#{path}/#{id}/audio"), format: :plain))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# The message read for one lead: lead is a hash of full_name, email,
|
|
94
|
+
# phone, language and custom_data ({ "EMI" => "Rs. 500" }). Missing
|
|
95
|
+
# values fall back to the message's defaults.
|
|
96
|
+
def preview(id, lead: {})
|
|
97
|
+
Phonomenal::AudioResponse.new(client.post(url_for("#{path}/#{id}/preview"), body: { lead: lead }.to_json,
|
|
98
|
+
format: :plain))
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# The audio of the campaign's own voice message: what automated calls fall
|
|
103
|
+
# back to without a matching or default voice message
|
|
104
|
+
module CampaignVoiceMessageAudio
|
|
105
|
+
# Its generated audio (a sample with default values when personalized).
|
|
106
|
+
# Fails (404) until it's generated.
|
|
107
|
+
def voice_message_audio
|
|
108
|
+
Phonomenal::AudioResponse.new(client.get(url_for("#{path}/voice_message_audio"), format: :plain))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# The message read for one lead, as voice_messages.preview
|
|
112
|
+
def voice_message_preview(lead: {})
|
|
113
|
+
url = url_for("#{path}/voice_message_preview")
|
|
114
|
+
Phonomenal::AudioResponse.new(client.post(url, body: { lead: lead }.to_json, format: :plain))
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# The campaign's IVR menu tree: whether it plays, its welcome message, the
|
|
119
|
+
# main menu's options and sub menus, down to sub sub menus. In a sub menu
|
|
120
|
+
# callers press * for the previous menu and 0 for the main menu.
|
|
121
|
+
module CampaignIvr
|
|
122
|
+
# The tree, under "ivr": play_ivr_menu, welcome_message, custom_audio,
|
|
123
|
+
# taken_digits (the main menu's member group and tag digits), options
|
|
124
|
+
# and menus
|
|
125
|
+
def ivr
|
|
126
|
+
Phonomenal::Response.new(client.get(url_for("#{path}/ivr")))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Replaces the whole tree. options: [{ digit:, member_tag_id: } or
|
|
130
|
+
# { digit:, member_group_id: }]; menus: [{ digit:, label:, message:,
|
|
131
|
+
# options: [...], menus: [...] }]. play_ivr_menu and welcome_message
|
|
132
|
+
# are optional. Nothing changes if any of it is invalid (422, with
|
|
133
|
+
# "errors" naming the menu).
|
|
134
|
+
def update_ivr(ivr)
|
|
135
|
+
Phonomenal::Response.new(client.put(url_for("#{path}/ivr"), body: { ivr: ivr }.to_json))
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def calls
|
|
140
|
+
@calls ||= Phonomenal::Calls.new(self)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def leads
|
|
144
|
+
@leads ||= Phonomenal::Leads.new(self)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phonomenal
|
|
4
|
+
Leads = Struct.new(:client) do
|
|
5
|
+
def list(filter: nil)
|
|
6
|
+
Response.new(client.get(client.url_for("/leads"), query: { filter: filter }))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def make_response(method, path, **kwargs)
|
|
10
|
+
Response.new(client.send(method, client.url_for(path), **kwargs))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create(object)
|
|
14
|
+
make_response :post, "/leads", body: { lead: object }.to_json
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update(lead_id, object)
|
|
18
|
+
make_response :put, "/leads/#{lead_id}", body: { lead: object }.to_json
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# State changes that carry no payload. Every name here matches a `post` member
|
|
22
|
+
# route on the server, so adding to this list means adding a route to match.
|
|
23
|
+
%w[block restore unbump unset_follow_up].each do |method_name|
|
|
24
|
+
define_method method_name do |lead_id|
|
|
25
|
+
make_response :post, "/leads/#{lead_id}/#{method_name}", body: {}.to_json
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Kept for callers written against the old name, which never had a route.
|
|
30
|
+
alias_method :unblock, :restore
|
|
31
|
+
|
|
32
|
+
# Move a lead to the front of the dialling queue.
|
|
33
|
+
#
|
|
34
|
+
# `bump_at` is when the lead becomes due for priority, not when the bump was
|
|
35
|
+
# made - pass a future time to schedule one. The server bumps from now when it
|
|
36
|
+
# is omitted.
|
|
37
|
+
def bump(lead_id, bump_at: nil)
|
|
38
|
+
body = bump_at.nil? ? {} : { bump_at: bump_at }
|
|
39
|
+
|
|
40
|
+
make_response :post, "/leads/#{lead_id}/bump", body: body.to_json
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def set_follow_up(lead_id, follow_up_at)
|
|
44
|
+
make_response :post, "/leads/#{lead_id}/follow_up", body: { follow_up_at: follow_up_at }.to_json
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def assign(lead_id, member_email)
|
|
48
|
+
make_response :post, "/leads/#{lead_id}/assign", body: { member_email: member_email }.to_json
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def unassign(lead_id)
|
|
52
|
+
make_response :post, "/leads/#{lead_id}/unassign", body: {}.to_json
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Clear every lead currently held by one agent, identified by email as the
|
|
56
|
+
# single-lead `assign` is. Responds with `unassigned_count` rather than a
|
|
57
|
+
# lead, and 404s if the campaign has no member with that email.
|
|
58
|
+
def unassign_all(member_email)
|
|
59
|
+
make_response :post, "/leads/unassign_all", body: { member_email: member_email }.to_json
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phonomenal
|
|
4
|
+
Response = Struct.new(:http_response) do
|
|
5
|
+
def json
|
|
6
|
+
http_response.parsed_response
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def success?
|
|
10
|
+
http_response.code == 200 && http_response.parsed_response["success"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def method_missing(method, *args, **kwargs, &block)
|
|
14
|
+
return http_response.send(method, *args, **kwargs, &block) if http_response.respond_to?(method)
|
|
15
|
+
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def respond_to_missing?(method, include_private = false)
|
|
20
|
+
http_response.respond_to?(method, include_private) || super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/phonomenal.rb
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "httparty"
|
|
4
|
+
require_relative "phonomenal/version"
|
|
5
|
+
require_relative "phonomenal/api_handler"
|
|
6
|
+
require_relative "phonomenal/calls"
|
|
7
|
+
require_relative "phonomenal/leads"
|
|
8
|
+
require_relative "phonomenal/campaign_context"
|
|
9
|
+
require_relative "phonomenal/account_context"
|
|
10
|
+
|
|
11
|
+
module Phonomenal
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
class Client
|
|
15
|
+
DEFAULT_BASE_URL = "https://phonomenal.voizworks.com"
|
|
16
|
+
|
|
17
|
+
def self.for_campaign(campaign_key, base_url: nil)
|
|
18
|
+
new(campaign_key: campaign_key, base_url: base_url)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.for_account(account_key, base_url: nil)
|
|
22
|
+
new(account_key: account_key, base_url: base_url)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.with_campaign(*args, **kwargs)
|
|
26
|
+
yield for_campaign(*args, **kwargs)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.with_account(*args, **kwargs)
|
|
30
|
+
yield for_account(*args, **kwargs)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
attr_reader :base_url, :campaign_key, :account_key
|
|
34
|
+
|
|
35
|
+
def initialize(campaign_key: nil, account_key: nil, base_url: nil)
|
|
36
|
+
raise ArgumentError, "Provide either campaign_key or account_key, not both" if campaign_key && account_key
|
|
37
|
+
raise ArgumentError, "Either campaign_key or account_key is required" unless campaign_key || account_key
|
|
38
|
+
|
|
39
|
+
@base_url = base_url || DEFAULT_BASE_URL
|
|
40
|
+
@campaign_key = campaign_key
|
|
41
|
+
@account_key = account_key
|
|
42
|
+
extend(campaign_context? ? Phonomenal::CampaignContext : Phonomenal::AccountContext)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def campaign_context?
|
|
46
|
+
!@campaign_key.nil?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def account_context?
|
|
50
|
+
!@account_key.nil?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def headers
|
|
54
|
+
key_header =
|
|
55
|
+
if campaign_context?
|
|
56
|
+
{ "X-Phonomenal-Campaign-Key" => campaign_key }
|
|
57
|
+
else
|
|
58
|
+
{ "X-Phonomenal-Account-Key" => account_key }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
key_header.merge("Content-Type" => "application/json")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def url_for(partial_path)
|
|
65
|
+
"#{base_url}/api/v1/#{partial_path}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Add helper methods for HTTP requests that use instance-level config
|
|
69
|
+
def get(url, options = {})
|
|
70
|
+
HTTParty.get(url, default_options.merge(options))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def post(url, options = {})
|
|
74
|
+
HTTParty.post(url, default_options.merge(options))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def put(url, options = {})
|
|
78
|
+
HTTParty.put(url, default_options.merge(options))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def patch(url, options = {})
|
|
82
|
+
HTTParty.patch(url, default_options.merge(options))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def delete(url, options = {})
|
|
86
|
+
HTTParty.delete(url, default_options.merge(options))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
def default_options
|
|
92
|
+
{
|
|
93
|
+
headers: headers,
|
|
94
|
+
format: :json
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: phonomenal_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.10.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Venkatakrishnan Ganesh
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
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
|
+
description: "\n "
|
|
28
|
+
email:
|
|
29
|
+
- venkatk@voizworks.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".rspec"
|
|
35
|
+
- ".rubocop.yml"
|
|
36
|
+
- CHANGELOG.md
|
|
37
|
+
- CODE_OF_CONDUCT.md
|
|
38
|
+
- LICENSE.txt
|
|
39
|
+
- README.md
|
|
40
|
+
- Rakefile
|
|
41
|
+
- lib/phonomenal.rb
|
|
42
|
+
- lib/phonomenal/account_context.rb
|
|
43
|
+
- lib/phonomenal/api_handler.rb
|
|
44
|
+
- lib/phonomenal/audio_response.rb
|
|
45
|
+
- lib/phonomenal/calls.rb
|
|
46
|
+
- lib/phonomenal/campaign_context.rb
|
|
47
|
+
- lib/phonomenal/leads.rb
|
|
48
|
+
- lib/phonomenal/response.rb
|
|
49
|
+
- lib/phonomenal/version.rb
|
|
50
|
+
- sig/phonomenal_client.rbs
|
|
51
|
+
homepage: https://github.com/gvenkat/phonomenal_client
|
|
52
|
+
licenses:
|
|
53
|
+
- MIT
|
|
54
|
+
metadata:
|
|
55
|
+
allowed_push_host: https://rubygems.org
|
|
56
|
+
homepage_uri: https://github.com/gvenkat/phonomenal_client
|
|
57
|
+
source_code_uri: https://github.com/gvenkat/phonomenal_client
|
|
58
|
+
changelog_uri: https://github.com/gvenkat/phonomenal_client/blob/master/CHANGELOG.md
|
|
59
|
+
post_install_message:
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 3.0.0
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubygems_version: 3.5.15
|
|
75
|
+
signing_key:
|
|
76
|
+
specification_version: 4
|
|
77
|
+
summary: A simple ruby interface to manage campaign and calls with Phonomenal service
|
|
78
|
+
test_files: []
|