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
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
namespace :kapso do
|
|
4
|
-
desc 'Test Kapso configuration and send a test message'
|
|
5
|
-
task test: :environment do
|
|
6
|
-
puts "š§ Testing Kapso configuration..."
|
|
7
|
-
|
|
8
|
-
# Check configuration
|
|
9
|
-
client = KapsoClientRuby::Client.new
|
|
10
|
-
puts "ā
Kapso client initialized"
|
|
11
|
-
puts "š± Phone Number ID: #{client.phone_number_id}"
|
|
12
|
-
puts "š¢ Business Account ID: #{client.business_account_id}"
|
|
13
|
-
|
|
14
|
-
# Test API connection
|
|
15
|
-
begin
|
|
16
|
-
templates = client.templates.list(limit: 1)
|
|
17
|
-
puts "ā
API connection successful"
|
|
18
|
-
puts "š Found #{templates.dig('data')&.length || 0} templates"
|
|
19
|
-
rescue => e
|
|
20
|
-
puts "ā API connection failed: #{e.message}"
|
|
21
|
-
exit 1
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Send test message if phone number is provided
|
|
25
|
-
test_number = ENV['KAPSO_TEST_PHONE_NUMBER']
|
|
26
|
-
if test_number
|
|
27
|
-
puts "\nš¤ Sending test message to #{test_number}..."
|
|
28
|
-
service = KapsoMessageService.new
|
|
29
|
-
service.send_test_message
|
|
30
|
-
else
|
|
31
|
-
puts "\nš” Set KAPSO_TEST_PHONE_NUMBER to test messaging"
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
desc 'List available WhatsApp message templates'
|
|
36
|
-
task templates: :environment do
|
|
37
|
-
puts "š Fetching WhatsApp templates..."
|
|
38
|
-
|
|
39
|
-
service = KapsoMessageService.new
|
|
40
|
-
templates_response = service.list_templates
|
|
41
|
-
|
|
42
|
-
if templates_response && templates_response['data']
|
|
43
|
-
templates = templates_response['data']
|
|
44
|
-
puts "Found #{templates.length} templates:\n\n"
|
|
45
|
-
|
|
46
|
-
templates.each do |template|
|
|
47
|
-
puts "š #{template['name']}"
|
|
48
|
-
puts " Status: #{template['status']}"
|
|
49
|
-
puts " Language: #{template['language']}"
|
|
50
|
-
puts " Category: #{template['category']}"
|
|
51
|
-
puts " Created: #{Time.at(template['created_time']).to_s}" if template['created_time']
|
|
52
|
-
puts ""
|
|
53
|
-
end
|
|
54
|
-
else
|
|
55
|
-
puts "ā Failed to fetch templates or no templates found"
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
desc 'Check message status'
|
|
60
|
-
task :message_status, [:message_id] => :environment do |task, args|
|
|
61
|
-
message_id = args[:message_id]
|
|
62
|
-
|
|
63
|
-
unless message_id
|
|
64
|
-
puts "ā Please provide a message ID: rake kapso:message_status[message_id]"
|
|
65
|
-
exit 1
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
puts "š Checking status for message: #{message_id}"
|
|
69
|
-
|
|
70
|
-
service = KapsoMessageService.new
|
|
71
|
-
status = service.get_message_status(message_id)
|
|
72
|
-
|
|
73
|
-
if status
|
|
74
|
-
puts "š Message Status:"
|
|
75
|
-
puts " ID: #{status['id']}"
|
|
76
|
-
puts " Status: #{status['status']}"
|
|
77
|
-
puts " Timestamp: #{Time.at(status['timestamp']).to_s}" if status['timestamp']
|
|
78
|
-
puts " Recipient: #{status['recipient_id']}" if status['recipient_id']
|
|
79
|
-
|
|
80
|
-
if status['errors']
|
|
81
|
-
puts " Errors: #{status['errors']}"
|
|
82
|
-
end
|
|
83
|
-
else
|
|
84
|
-
puts "ā Failed to get message status"
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
desc 'Validate webhook configuration'
|
|
89
|
-
task validate_webhook: :environment do
|
|
90
|
-
puts "š Validating webhook configuration..."
|
|
91
|
-
|
|
92
|
-
# Check required environment variables
|
|
93
|
-
required_vars = %w[KAPSO_WEBHOOK_VERIFY_TOKEN]
|
|
94
|
-
optional_vars = %w[KAPSO_WEBHOOK_SECRET]
|
|
95
|
-
|
|
96
|
-
required_vars.each do |var|
|
|
97
|
-
if ENV[var].present?
|
|
98
|
-
puts "ā
#{var} is set"
|
|
99
|
-
else
|
|
100
|
-
puts "ā #{var} is not set (required)"
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
optional_vars.each do |var|
|
|
105
|
-
if ENV[var].present?
|
|
106
|
-
puts "ā
#{var} is set (recommended for security)"
|
|
107
|
-
else
|
|
108
|
-
puts "ā ļø #{var} is not set (optional but recommended)"
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
# Check if routes are properly configured
|
|
113
|
-
begin
|
|
114
|
-
webhook_path = Rails.application.routes.url_helpers.kapso_webhooks_path rescue nil
|
|
115
|
-
if webhook_path
|
|
116
|
-
puts "ā
Webhook routes are configured"
|
|
117
|
-
puts " Webhook URL: #{Rails.application.config.force_ssl ? 'https' : 'http'}://yourapp.com#{webhook_path}"
|
|
118
|
-
else
|
|
119
|
-
puts "ā ļø Webhook routes may not be configured. Make sure to add:"
|
|
120
|
-
puts " post '/webhooks/kapso', to: 'kapso_webhooks#create'"
|
|
121
|
-
puts " get '/webhooks/kapso', to: 'kapso_webhooks#verify'"
|
|
122
|
-
end
|
|
123
|
-
rescue => e
|
|
124
|
-
puts "ā ļø Could not check webhook routes: #{e.message}"
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
desc 'Generate sample environment file'
|
|
129
|
-
task :sample_env do
|
|
130
|
-
puts "š Generating .env.kapso.sample file..."
|
|
131
|
-
|
|
132
|
-
env_content = <<~ENV
|
|
133
|
-
# Kapso API Configuration
|
|
134
|
-
# Copy this to your .env file and fill in your actual values
|
|
135
|
-
|
|
136
|
-
# Required: Your Kapso API access token
|
|
137
|
-
KAPSO_API_KEY=your_api_key_here
|
|
138
|
-
|
|
139
|
-
# Required: Your WhatsApp Business phone number ID
|
|
140
|
-
KAPSO_PHONE_NUMBER_ID=your_phone_number_id_here
|
|
141
|
-
|
|
142
|
-
# Required: Your WhatsApp Business account ID
|
|
143
|
-
KAPSO_BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
|
144
|
-
|
|
145
|
-
# Optional: API configuration
|
|
146
|
-
KAPSO_API_HOST=https://graph.facebook.com
|
|
147
|
-
KAPSO_API_VERSION=v18.0
|
|
148
|
-
KAPSO_TIMEOUT=30
|
|
149
|
-
|
|
150
|
-
# Optional: Debug and retry settings
|
|
151
|
-
KAPSO_DEBUG=false
|
|
152
|
-
KAPSO_RETRY_ON_FAILURE=true
|
|
153
|
-
KAPSO_MAX_RETRIES=3
|
|
154
|
-
|
|
155
|
-
# Webhook configuration
|
|
156
|
-
KAPSO_WEBHOOK_VERIFY_TOKEN=your_webhook_verify_token_here
|
|
157
|
-
KAPSO_WEBHOOK_SECRET=your_webhook_secret_here
|
|
158
|
-
|
|
159
|
-
# Testing
|
|
160
|
-
KAPSO_TEST_PHONE_NUMBER=+1234567890
|
|
161
|
-
ENV
|
|
162
|
-
|
|
163
|
-
File.write('.env.kapso.sample', env_content)
|
|
164
|
-
puts "ā
Created .env.kapso.sample"
|
|
165
|
-
puts "š” Copy this to .env and update with your actual credentials"
|
|
166
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :kapso do
|
|
4
|
+
desc 'Test Kapso configuration and send a test message'
|
|
5
|
+
task test: :environment do
|
|
6
|
+
puts "š§ Testing Kapso configuration..."
|
|
7
|
+
|
|
8
|
+
# Check configuration
|
|
9
|
+
client = KapsoClientRuby::Client.new
|
|
10
|
+
puts "ā
Kapso client initialized"
|
|
11
|
+
puts "š± Phone Number ID: #{client.phone_number_id}"
|
|
12
|
+
puts "š¢ Business Account ID: #{client.business_account_id}"
|
|
13
|
+
|
|
14
|
+
# Test API connection
|
|
15
|
+
begin
|
|
16
|
+
templates = client.templates.list(limit: 1)
|
|
17
|
+
puts "ā
API connection successful"
|
|
18
|
+
puts "š Found #{templates.dig('data')&.length || 0} templates"
|
|
19
|
+
rescue => e
|
|
20
|
+
puts "ā API connection failed: #{e.message}"
|
|
21
|
+
exit 1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Send test message if phone number is provided
|
|
25
|
+
test_number = ENV['KAPSO_TEST_PHONE_NUMBER']
|
|
26
|
+
if test_number
|
|
27
|
+
puts "\nš¤ Sending test message to #{test_number}..."
|
|
28
|
+
service = KapsoMessageService.new
|
|
29
|
+
service.send_test_message
|
|
30
|
+
else
|
|
31
|
+
puts "\nš” Set KAPSO_TEST_PHONE_NUMBER to test messaging"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc 'List available WhatsApp message templates'
|
|
36
|
+
task templates: :environment do
|
|
37
|
+
puts "š Fetching WhatsApp templates..."
|
|
38
|
+
|
|
39
|
+
service = KapsoMessageService.new
|
|
40
|
+
templates_response = service.list_templates
|
|
41
|
+
|
|
42
|
+
if templates_response && templates_response['data']
|
|
43
|
+
templates = templates_response['data']
|
|
44
|
+
puts "Found #{templates.length} templates:\n\n"
|
|
45
|
+
|
|
46
|
+
templates.each do |template|
|
|
47
|
+
puts "š #{template['name']}"
|
|
48
|
+
puts " Status: #{template['status']}"
|
|
49
|
+
puts " Language: #{template['language']}"
|
|
50
|
+
puts " Category: #{template['category']}"
|
|
51
|
+
puts " Created: #{Time.at(template['created_time']).to_s}" if template['created_time']
|
|
52
|
+
puts ""
|
|
53
|
+
end
|
|
54
|
+
else
|
|
55
|
+
puts "ā Failed to fetch templates or no templates found"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
desc 'Check message status'
|
|
60
|
+
task :message_status, [:message_id] => :environment do |task, args|
|
|
61
|
+
message_id = args[:message_id]
|
|
62
|
+
|
|
63
|
+
unless message_id
|
|
64
|
+
puts "ā Please provide a message ID: rake kapso:message_status[message_id]"
|
|
65
|
+
exit 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
puts "š Checking status for message: #{message_id}"
|
|
69
|
+
|
|
70
|
+
service = KapsoMessageService.new
|
|
71
|
+
status = service.get_message_status(message_id)
|
|
72
|
+
|
|
73
|
+
if status
|
|
74
|
+
puts "š Message Status:"
|
|
75
|
+
puts " ID: #{status['id']}"
|
|
76
|
+
puts " Status: #{status['status']}"
|
|
77
|
+
puts " Timestamp: #{Time.at(status['timestamp']).to_s}" if status['timestamp']
|
|
78
|
+
puts " Recipient: #{status['recipient_id']}" if status['recipient_id']
|
|
79
|
+
|
|
80
|
+
if status['errors']
|
|
81
|
+
puts " Errors: #{status['errors']}"
|
|
82
|
+
end
|
|
83
|
+
else
|
|
84
|
+
puts "ā Failed to get message status"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
desc 'Validate webhook configuration'
|
|
89
|
+
task validate_webhook: :environment do
|
|
90
|
+
puts "š Validating webhook configuration..."
|
|
91
|
+
|
|
92
|
+
# Check required environment variables
|
|
93
|
+
required_vars = %w[KAPSO_WEBHOOK_VERIFY_TOKEN]
|
|
94
|
+
optional_vars = %w[KAPSO_WEBHOOK_SECRET]
|
|
95
|
+
|
|
96
|
+
required_vars.each do |var|
|
|
97
|
+
if ENV[var].present?
|
|
98
|
+
puts "ā
#{var} is set"
|
|
99
|
+
else
|
|
100
|
+
puts "ā #{var} is not set (required)"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
optional_vars.each do |var|
|
|
105
|
+
if ENV[var].present?
|
|
106
|
+
puts "ā
#{var} is set (recommended for security)"
|
|
107
|
+
else
|
|
108
|
+
puts "ā ļø #{var} is not set (optional but recommended)"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Check if routes are properly configured
|
|
113
|
+
begin
|
|
114
|
+
webhook_path = Rails.application.routes.url_helpers.kapso_webhooks_path rescue nil
|
|
115
|
+
if webhook_path
|
|
116
|
+
puts "ā
Webhook routes are configured"
|
|
117
|
+
puts " Webhook URL: #{Rails.application.config.force_ssl ? 'https' : 'http'}://yourapp.com#{webhook_path}"
|
|
118
|
+
else
|
|
119
|
+
puts "ā ļø Webhook routes may not be configured. Make sure to add:"
|
|
120
|
+
puts " post '/webhooks/kapso', to: 'kapso_webhooks#create'"
|
|
121
|
+
puts " get '/webhooks/kapso', to: 'kapso_webhooks#verify'"
|
|
122
|
+
end
|
|
123
|
+
rescue => e
|
|
124
|
+
puts "ā ļø Could not check webhook routes: #{e.message}"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
desc 'Generate sample environment file'
|
|
129
|
+
task :sample_env do
|
|
130
|
+
puts "š Generating .env.kapso.sample file..."
|
|
131
|
+
|
|
132
|
+
env_content = <<~ENV
|
|
133
|
+
# Kapso API Configuration
|
|
134
|
+
# Copy this to your .env file and fill in your actual values
|
|
135
|
+
|
|
136
|
+
# Required: Your Kapso API access token
|
|
137
|
+
KAPSO_API_KEY=your_api_key_here
|
|
138
|
+
|
|
139
|
+
# Required: Your WhatsApp Business phone number ID
|
|
140
|
+
KAPSO_PHONE_NUMBER_ID=your_phone_number_id_here
|
|
141
|
+
|
|
142
|
+
# Required: Your WhatsApp Business account ID
|
|
143
|
+
KAPSO_BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
|
144
|
+
|
|
145
|
+
# Optional: API configuration
|
|
146
|
+
KAPSO_API_HOST=https://graph.facebook.com
|
|
147
|
+
KAPSO_API_VERSION=v18.0
|
|
148
|
+
KAPSO_TIMEOUT=30
|
|
149
|
+
|
|
150
|
+
# Optional: Debug and retry settings
|
|
151
|
+
KAPSO_DEBUG=false
|
|
152
|
+
KAPSO_RETRY_ON_FAILURE=true
|
|
153
|
+
KAPSO_MAX_RETRIES=3
|
|
154
|
+
|
|
155
|
+
# Webhook configuration
|
|
156
|
+
KAPSO_WEBHOOK_VERIFY_TOKEN=your_webhook_verify_token_here
|
|
157
|
+
KAPSO_WEBHOOK_SECRET=your_webhook_secret_here
|
|
158
|
+
|
|
159
|
+
# Testing
|
|
160
|
+
KAPSO_TEST_PHONE_NUMBER=+1234567890
|
|
161
|
+
ENV
|
|
162
|
+
|
|
163
|
+
File.write('.env.kapso.sample', env_content)
|
|
164
|
+
puts "ā
Created .env.kapso.sample"
|
|
165
|
+
puts "š” Copy this to .env and update with your actual credentials"
|
|
166
|
+
end
|
|
167
167
|
end
|