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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +81 -81
  3. data/CHANGELOG.md +262 -91
  4. data/Gemfile +20 -20
  5. data/RAILS_INTEGRATION.md +477 -477
  6. data/README.md +1053 -752
  7. data/Rakefile +40 -40
  8. data/TEMPLATE_TOOLS_GUIDE.md +120 -120
  9. data/WHATSAPP_24_HOUR_GUIDE.md +133 -133
  10. data/examples/advanced_features.rb +352 -349
  11. data/examples/advanced_messaging.rb +241 -0
  12. data/examples/basic_messaging.rb +139 -136
  13. data/examples/enhanced_interactive.rb +400 -0
  14. data/examples/flows_usage.rb +307 -0
  15. data/examples/interactive_messages.rb +343 -0
  16. data/examples/media_management.rb +256 -253
  17. data/examples/rails/jobs.rb +387 -387
  18. data/examples/rails/models.rb +239 -239
  19. data/examples/rails/notifications_controller.rb +226 -226
  20. data/examples/template_management.rb +393 -390
  21. data/kapso-ruby-logo.jpg +0 -0
  22. data/lib/kapso_client_ruby/client.rb +321 -316
  23. data/lib/kapso_client_ruby/errors.rb +348 -329
  24. data/lib/kapso_client_ruby/rails/generators/install_generator.rb +75 -75
  25. data/lib/kapso_client_ruby/rails/generators/templates/env.erb +20 -20
  26. data/lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb +32 -32
  27. data/lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb +137 -137
  28. data/lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb +61 -61
  29. data/lib/kapso_client_ruby/rails/railtie.rb +54 -54
  30. data/lib/kapso_client_ruby/rails/service.rb +188 -188
  31. data/lib/kapso_client_ruby/rails/tasks.rake +166 -166
  32. data/lib/kapso_client_ruby/resources/calls.rb +172 -172
  33. data/lib/kapso_client_ruby/resources/contacts.rb +190 -190
  34. data/lib/kapso_client_ruby/resources/conversations.rb +103 -103
  35. data/lib/kapso_client_ruby/resources/flows.rb +382 -0
  36. data/lib/kapso_client_ruby/resources/media.rb +205 -205
  37. data/lib/kapso_client_ruby/resources/messages.rb +760 -380
  38. data/lib/kapso_client_ruby/resources/phone_numbers.rb +85 -85
  39. data/lib/kapso_client_ruby/resources/templates.rb +283 -283
  40. data/lib/kapso_client_ruby/types.rb +348 -262
  41. data/lib/kapso_client_ruby/version.rb +5 -5
  42. data/lib/kapso_client_ruby.rb +75 -74
  43. data/scripts/.env.example +17 -17
  44. data/scripts/kapso_template_finder.rb +91 -91
  45. data/scripts/sdk_setup.rb +404 -404
  46. data/scripts/test.rb +60 -60
  47. metadata +12 -3
@@ -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
- # Load Rails integration if Rails is available
16
- if defined?(Rails)
17
- require_relative 'kapso_client_ruby/rails/railtie'
18
- require_relative 'kapso_client_ruby/rails/service'
19
- end
20
-
21
- module KapsoClientRuby
22
- class << self
23
- # Configure default logging
24
- def logger
25
- @logger ||= Logger.new($stdout).tap do |log|
26
- log.level = Logger::INFO
27
- log.formatter = proc do |severity, datetime, progname, msg|
28
- "[#{datetime}] #{severity} #{progname}: #{msg}\n"
29
- end
30
- end
31
- end
32
-
33
- def logger=(logger)
34
- @logger = logger
35
- end
36
-
37
- # Global configuration
38
- def configure
39
- yield(configuration)
40
- end
41
-
42
- def configuration
43
- @configuration ||= Configuration.new
44
- end
45
-
46
- def reset_configuration!
47
- @configuration = Configuration.new
48
- end
49
- end
50
-
51
- class Configuration
52
- attr_accessor :debug, :timeout, :open_timeout, :max_retries, :retry_delay,
53
- :access_token, :kapso_api_key, :base_url, :api_version
54
-
55
- def initialize
56
- @debug = false
57
- @timeout = 60
58
- @open_timeout = 10
59
- @max_retries = 3
60
- @retry_delay = 1.0
61
- @base_url = 'https://graph.facebook.com'
62
- @api_version = 'v23.0'
63
- @access_token = nil
64
- @kapso_api_key = nil
65
- end
66
-
67
- def kapso_proxy?
68
- !@kapso_api_key.nil? && @base_url&.include?('kapso')
69
- end
70
-
71
- def valid?
72
- !@access_token.nil? || !@kapso_api_key.nil?
73
- end
74
- end
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!"