kapso-client-ruby 1.0.1 ā 1.0.2
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 +4 -4
- data/.rubocop.yml +81 -81
- data/CHANGELOG.md +262 -91
- data/Gemfile +20 -20
- data/RAILS_INTEGRATION.md +477 -477
- data/README.md +1053 -752
- data/Rakefile +40 -40
- data/TEMPLATE_TOOLS_GUIDE.md +120 -120
- data/WHATSAPP_24_HOUR_GUIDE.md +133 -133
- data/examples/advanced_features.rb +352 -349
- data/examples/advanced_messaging.rb +241 -0
- data/examples/basic_messaging.rb +139 -136
- data/examples/enhanced_interactive.rb +400 -0
- data/examples/flows_usage.rb +307 -0
- data/examples/interactive_messages.rb +343 -0
- data/examples/media_management.rb +256 -253
- data/examples/rails/jobs.rb +387 -387
- data/examples/rails/models.rb +239 -239
- data/examples/rails/notifications_controller.rb +226 -226
- data/examples/template_management.rb +393 -390
- data/kapso-ruby-logo.jpg +0 -0
- data/lib/kapso_client_ruby/client.rb +321 -316
- data/lib/kapso_client_ruby/errors.rb +348 -329
- data/lib/kapso_client_ruby/rails/generators/install_generator.rb +75 -75
- data/lib/kapso_client_ruby/rails/generators/templates/env.erb +20 -20
- data/lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb +32 -32
- data/lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb +137 -137
- data/lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb +61 -61
- data/lib/kapso_client_ruby/rails/railtie.rb +54 -54
- data/lib/kapso_client_ruby/rails/service.rb +188 -188
- data/lib/kapso_client_ruby/rails/tasks.rake +166 -166
- data/lib/kapso_client_ruby/resources/calls.rb +172 -172
- data/lib/kapso_client_ruby/resources/contacts.rb +190 -190
- data/lib/kapso_client_ruby/resources/conversations.rb +103 -103
- data/lib/kapso_client_ruby/resources/flows.rb +382 -0
- data/lib/kapso_client_ruby/resources/media.rb +205 -205
- data/lib/kapso_client_ruby/resources/messages.rb +760 -380
- data/lib/kapso_client_ruby/resources/phone_numbers.rb +85 -85
- data/lib/kapso_client_ruby/resources/templates.rb +283 -283
- data/lib/kapso_client_ruby/types.rb +348 -262
- data/lib/kapso_client_ruby/version.rb +5 -5
- data/lib/kapso_client_ruby.rb +75 -74
- data/scripts/.env.example +17 -17
- data/scripts/kapso_template_finder.rb +91 -91
- data/scripts/sdk_setup.rb +404 -404
- data/scripts/test.rb +60 -60
- metadata +12 -3
data/lib/kapso_client_ruby.rb
CHANGED
|
@@ -1,75 +1,76 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'kapso_client_ruby/version'
|
|
4
|
-
require_relative 'kapso_client_ruby/client'
|
|
5
|
-
require_relative 'kapso_client_ruby/errors'
|
|
6
|
-
require_relative 'kapso_client_ruby/types'
|
|
7
|
-
require_relative 'kapso_client_ruby/resources/messages'
|
|
8
|
-
require_relative 'kapso_client_ruby/resources/media'
|
|
9
|
-
require_relative 'kapso_client_ruby/resources/templates'
|
|
10
|
-
require_relative 'kapso_client_ruby/resources/phone_numbers'
|
|
11
|
-
require_relative 'kapso_client_ruby/resources/calls'
|
|
12
|
-
require_relative 'kapso_client_ruby/resources/conversations'
|
|
13
|
-
require_relative 'kapso_client_ruby/resources/contacts'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if
|
|
17
|
-
|
|
18
|
-
require_relative 'kapso_client_ruby/rails/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
log.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
@
|
|
58
|
-
@
|
|
59
|
-
@
|
|
60
|
-
@
|
|
61
|
-
@
|
|
62
|
-
@
|
|
63
|
-
@
|
|
64
|
-
@
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'kapso_client_ruby/version'
|
|
4
|
+
require_relative 'kapso_client_ruby/client'
|
|
5
|
+
require_relative 'kapso_client_ruby/errors'
|
|
6
|
+
require_relative 'kapso_client_ruby/types'
|
|
7
|
+
require_relative 'kapso_client_ruby/resources/messages'
|
|
8
|
+
require_relative 'kapso_client_ruby/resources/media'
|
|
9
|
+
require_relative 'kapso_client_ruby/resources/templates'
|
|
10
|
+
require_relative 'kapso_client_ruby/resources/phone_numbers'
|
|
11
|
+
require_relative 'kapso_client_ruby/resources/calls'
|
|
12
|
+
require_relative 'kapso_client_ruby/resources/conversations'
|
|
13
|
+
require_relative 'kapso_client_ruby/resources/contacts'
|
|
14
|
+
require_relative 'kapso_client_ruby/resources/flows'
|
|
15
|
+
|
|
16
|
+
# Load Rails integration if Rails is available
|
|
17
|
+
if defined?(Rails)
|
|
18
|
+
require_relative 'kapso_client_ruby/rails/railtie'
|
|
19
|
+
require_relative 'kapso_client_ruby/rails/service'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module KapsoClientRuby
|
|
23
|
+
class << self
|
|
24
|
+
# Configure default logging
|
|
25
|
+
def logger
|
|
26
|
+
@logger ||= Logger.new($stdout).tap do |log|
|
|
27
|
+
log.level = Logger::INFO
|
|
28
|
+
log.formatter = proc do |severity, datetime, progname, msg|
|
|
29
|
+
"[#{datetime}] #{severity} #{progname}: #{msg}\n"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def logger=(logger)
|
|
35
|
+
@logger = logger
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Global configuration
|
|
39
|
+
def configure
|
|
40
|
+
yield(configuration)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def configuration
|
|
44
|
+
@configuration ||= Configuration.new
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def reset_configuration!
|
|
48
|
+
@configuration = Configuration.new
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class Configuration
|
|
53
|
+
attr_accessor :debug, :timeout, :open_timeout, :max_retries, :retry_delay,
|
|
54
|
+
:access_token, :kapso_api_key, :base_url, :api_version
|
|
55
|
+
|
|
56
|
+
def initialize
|
|
57
|
+
@debug = false
|
|
58
|
+
@timeout = 60
|
|
59
|
+
@open_timeout = 10
|
|
60
|
+
@max_retries = 3
|
|
61
|
+
@retry_delay = 1.0
|
|
62
|
+
@base_url = 'https://graph.facebook.com'
|
|
63
|
+
@api_version = 'v23.0'
|
|
64
|
+
@access_token = nil
|
|
65
|
+
@kapso_api_key = nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def kapso_proxy?
|
|
69
|
+
!@kapso_api_key.nil? && @base_url&.include?('kapso')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def valid?
|
|
73
|
+
!@access_token.nil? || !@kapso_api_key.nil?
|
|
74
|
+
end
|
|
75
|
+
end
|
|
75
76
|
end
|
data/scripts/.env.example
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
# Kapso Proxy API
|
|
2
|
-
KAPSO_API_KEY=your_kapso_api_key_here
|
|
3
|
-
PHONE_NUMBER_ID=your_phone_number_id_here
|
|
4
|
-
WHATSAPP_BASE_URL=https://app.kapso.ai/api/meta
|
|
5
|
-
|
|
6
|
-
# Business Account ID (required for template management)
|
|
7
|
-
# Find this in your Kapso dashboard under WhatsApp Business section
|
|
8
|
-
BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
|
9
|
-
|
|
10
|
-
# Optional: Set API version
|
|
11
|
-
# WHATSAPP_API_VERSION=v24.0
|
|
12
|
-
|
|
13
|
-
# Optional: Enable debug mode
|
|
14
|
-
# WHATSAPP_DEBUG=true
|
|
15
|
-
|
|
16
|
-
# Optional: Set timeouts (in seconds)
|
|
17
|
-
# WHATSAPP_TIMEOUT=30
|
|
1
|
+
# Kapso Proxy API
|
|
2
|
+
KAPSO_API_KEY=your_kapso_api_key_here
|
|
3
|
+
PHONE_NUMBER_ID=your_phone_number_id_here
|
|
4
|
+
WHATSAPP_BASE_URL=https://app.kapso.ai/api/meta
|
|
5
|
+
|
|
6
|
+
# Business Account ID (required for template management)
|
|
7
|
+
# Find this in your Kapso dashboard under WhatsApp Business section
|
|
8
|
+
BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
|
9
|
+
|
|
10
|
+
# Optional: Set API version
|
|
11
|
+
# WHATSAPP_API_VERSION=v24.0
|
|
12
|
+
|
|
13
|
+
# Optional: Enable debug mode
|
|
14
|
+
# WHATSAPP_DEBUG=true
|
|
15
|
+
|
|
16
|
+
# Optional: Set timeouts (in seconds)
|
|
17
|
+
# WHATSAPP_TIMEOUT=30
|
|
18
18
|
# WHATSAPP_OPEN_TIMEOUT=10
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'dotenv/load' rescue nil
|
|
5
|
-
require_relative '../lib/kapso_client_ruby'
|
|
6
|
-
|
|
7
|
-
puts "š Kapso Template Finder"
|
|
8
|
-
puts "=" * 30
|
|
9
|
-
|
|
10
|
-
kapso_api_key = ENV['KAPSO_API_KEY']
|
|
11
|
-
phone_number_id = ENV['PHONE_NUMBER_ID']
|
|
12
|
-
business_account_id = ENV['BUSINESS_ACCOUNT_ID']
|
|
13
|
-
|
|
14
|
-
unless kapso_api_key && phone_number_id
|
|
15
|
-
puts "ā Missing credentials. Run: ruby sdk_test.rb"
|
|
16
|
-
exit 1
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
client = KapsoClientRuby::Client.new(
|
|
20
|
-
kapso_api_key: kapso_api_key,
|
|
21
|
-
base_url: ENV['WHATSAPP_BASE_URL'] || 'https://app.kapso.ai/api/meta'
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
puts "Phone: #{phone_number_id}"
|
|
25
|
-
puts "Business Account: #{business_account_id || 'Not set'}"
|
|
26
|
-
|
|
27
|
-
print "Destination (+56912345678): "
|
|
28
|
-
to_number = gets.chomp
|
|
29
|
-
to_number = "+56912345678" if to_number.empty?
|
|
30
|
-
|
|
31
|
-
puts "\nš Finding Templates..."
|
|
32
|
-
found_templates = []
|
|
33
|
-
|
|
34
|
-
# Try Business Account if available
|
|
35
|
-
if business_account_id
|
|
36
|
-
puts "Checking Business Account..."
|
|
37
|
-
begin
|
|
38
|
-
response = client.templates.list(business_account_id: business_account_id)
|
|
39
|
-
if response.data && response.data.any?
|
|
40
|
-
response.data.each do |template|
|
|
41
|
-
found_templates << {
|
|
42
|
-
name: template.name,
|
|
43
|
-
language: template.language,
|
|
44
|
-
status: template.status
|
|
45
|
-
}
|
|
46
|
-
puts "ā
#{template.name} (#{template.language}) - #{template.status}"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
rescue => e
|
|
50
|
-
puts "ā Error: #{e.message}"
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Test common names if none found
|
|
55
|
-
if found_templates.empty?
|
|
56
|
-
puts "Testing common template names..."
|
|
57
|
-
["hello_world", "welcome_message"].each do |name|
|
|
58
|
-
print "Testing #{name}... "
|
|
59
|
-
begin
|
|
60
|
-
client.messages.send_template(
|
|
61
|
-
phone_number_id: phone_number_id,
|
|
62
|
-
to: to_number,
|
|
63
|
-
name: name,
|
|
64
|
-
language: "en_US"
|
|
65
|
-
)
|
|
66
|
-
puts "ā
WORKS"
|
|
67
|
-
found_templates << { name: name, language: "en_US", status: "APPROVED" }
|
|
68
|
-
rescue => e
|
|
69
|
-
puts "ā Not found" if e.message.include?("does not exist")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
puts "\n=" * 30
|
|
75
|
-
puts "š RESULTS"
|
|
76
|
-
|
|
77
|
-
if found_templates.any?
|
|
78
|
-
puts "Found #{found_templates.length} template(s):"
|
|
79
|
-
found_templates.each do |t|
|
|
80
|
-
puts "\n⢠#{t[:name]} (#{t[:language]})"
|
|
81
|
-
puts " Status: #{t[:status]}"
|
|
82
|
-
end
|
|
83
|
-
puts "\nšÆ Templates work 24/7 - no time limits!"
|
|
84
|
-
else
|
|
85
|
-
puts "No templates found"
|
|
86
|
-
puts "\nNext steps:"
|
|
87
|
-
puts "1. Add BUSINESS_ACCOUNT_ID to .env"
|
|
88
|
-
puts "2. Create templates in Kapso dashboard"
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
puts "\nš” Templates solve the 24-hour problem!"
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'dotenv/load' rescue nil
|
|
5
|
+
require_relative '../lib/kapso_client_ruby'
|
|
6
|
+
|
|
7
|
+
puts "š Kapso Template Finder"
|
|
8
|
+
puts "=" * 30
|
|
9
|
+
|
|
10
|
+
kapso_api_key = ENV['KAPSO_API_KEY']
|
|
11
|
+
phone_number_id = ENV['PHONE_NUMBER_ID']
|
|
12
|
+
business_account_id = ENV['BUSINESS_ACCOUNT_ID']
|
|
13
|
+
|
|
14
|
+
unless kapso_api_key && phone_number_id
|
|
15
|
+
puts "ā Missing credentials. Run: ruby sdk_test.rb"
|
|
16
|
+
exit 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
client = KapsoClientRuby::Client.new(
|
|
20
|
+
kapso_api_key: kapso_api_key,
|
|
21
|
+
base_url: ENV['WHATSAPP_BASE_URL'] || 'https://app.kapso.ai/api/meta'
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
puts "Phone: #{phone_number_id}"
|
|
25
|
+
puts "Business Account: #{business_account_id || 'Not set'}"
|
|
26
|
+
|
|
27
|
+
print "Destination (+56912345678): "
|
|
28
|
+
to_number = gets.chomp
|
|
29
|
+
to_number = "+56912345678" if to_number.empty?
|
|
30
|
+
|
|
31
|
+
puts "\nš Finding Templates..."
|
|
32
|
+
found_templates = []
|
|
33
|
+
|
|
34
|
+
# Try Business Account if available
|
|
35
|
+
if business_account_id
|
|
36
|
+
puts "Checking Business Account..."
|
|
37
|
+
begin
|
|
38
|
+
response = client.templates.list(business_account_id: business_account_id)
|
|
39
|
+
if response.data && response.data.any?
|
|
40
|
+
response.data.each do |template|
|
|
41
|
+
found_templates << {
|
|
42
|
+
name: template.name,
|
|
43
|
+
language: template.language,
|
|
44
|
+
status: template.status
|
|
45
|
+
}
|
|
46
|
+
puts "ā
#{template.name} (#{template.language}) - #{template.status}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
rescue => e
|
|
50
|
+
puts "ā Error: #{e.message}"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Test common names if none found
|
|
55
|
+
if found_templates.empty?
|
|
56
|
+
puts "Testing common template names..."
|
|
57
|
+
["hello_world", "welcome_message"].each do |name|
|
|
58
|
+
print "Testing #{name}... "
|
|
59
|
+
begin
|
|
60
|
+
client.messages.send_template(
|
|
61
|
+
phone_number_id: phone_number_id,
|
|
62
|
+
to: to_number,
|
|
63
|
+
name: name,
|
|
64
|
+
language: "en_US"
|
|
65
|
+
)
|
|
66
|
+
puts "ā
WORKS"
|
|
67
|
+
found_templates << { name: name, language: "en_US", status: "APPROVED" }
|
|
68
|
+
rescue => e
|
|
69
|
+
puts "ā Not found" if e.message.include?("does not exist")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
puts "\n=" * 30
|
|
75
|
+
puts "š RESULTS"
|
|
76
|
+
|
|
77
|
+
if found_templates.any?
|
|
78
|
+
puts "Found #{found_templates.length} template(s):"
|
|
79
|
+
found_templates.each do |t|
|
|
80
|
+
puts "\n⢠#{t[:name]} (#{t[:language]})"
|
|
81
|
+
puts " Status: #{t[:status]}"
|
|
82
|
+
end
|
|
83
|
+
puts "\nšÆ Templates work 24/7 - no time limits!"
|
|
84
|
+
else
|
|
85
|
+
puts "No templates found"
|
|
86
|
+
puts "\nNext steps:"
|
|
87
|
+
puts "1. Add BUSINESS_ACCOUNT_ID to .env"
|
|
88
|
+
puts "2. Create templates in Kapso dashboard"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
puts "\nš” Templates solve the 24-hour problem!"
|