kapso-client-ruby 1.0.0 → 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 +478 -0
- data/README.md +1053 -734
- 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 +388 -0
- data/examples/rails/models.rb +240 -0
- data/examples/rails/notifications_controller.rb +227 -0
- 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 +76 -0
- data/lib/kapso_client_ruby/rails/generators/templates/env.erb +21 -0
- data/lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb +33 -0
- data/lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb +138 -0
- data/lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb +62 -0
- data/lib/kapso_client_ruby/rails/railtie.rb +55 -0
- data/lib/kapso_client_ruby/rails/service.rb +189 -0
- data/lib/kapso_client_ruby/rails/tasks.rake +167 -0
- 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 -68
- 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 +24 -3
data/Rakefile
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
desc 'Run RSpec tests'
|
|
4
|
-
task :spec do
|
|
5
|
-
sh 'bundle exec rspec'
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
desc 'Run RuboCop'
|
|
9
|
-
task :rubocop do
|
|
10
|
-
sh 'bundle exec rubocop'
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
desc 'Run all linting and tests'
|
|
14
|
-
task test: [:rubocop, :spec]
|
|
15
|
-
|
|
16
|
-
desc 'Generate YARD documentation'
|
|
17
|
-
task :docs do
|
|
18
|
-
sh 'bundle exec yard doc'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
desc 'Clean up generated files'
|
|
22
|
-
task :clean do
|
|
23
|
-
sh 'rm -rf coverage/ doc/ .yardoc/'
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
desc 'Build the gem'
|
|
27
|
-
task :build do
|
|
28
|
-
sh 'gem build kapso-client-ruby.gemspec'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
desc 'Install the gem locally'
|
|
32
|
-
task install: :build do
|
|
33
|
-
sh 'gem install kapso-client-ruby-*.gem'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
desc 'Release the gem'
|
|
37
|
-
task release: [:clean, :test, :build] do
|
|
38
|
-
puts 'Run `gem push kapso-client-ruby-*.gem` to release'
|
|
39
|
-
end
|
|
40
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
desc 'Run RSpec tests'
|
|
4
|
+
task :spec do
|
|
5
|
+
sh 'bundle exec rspec'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
desc 'Run RuboCop'
|
|
9
|
+
task :rubocop do
|
|
10
|
+
sh 'bundle exec rubocop'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
desc 'Run all linting and tests'
|
|
14
|
+
task test: [:rubocop, :spec]
|
|
15
|
+
|
|
16
|
+
desc 'Generate YARD documentation'
|
|
17
|
+
task :docs do
|
|
18
|
+
sh 'bundle exec yard doc'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc 'Clean up generated files'
|
|
22
|
+
task :clean do
|
|
23
|
+
sh 'rm -rf coverage/ doc/ .yardoc/'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc 'Build the gem'
|
|
27
|
+
task :build do
|
|
28
|
+
sh 'gem build kapso-client-ruby.gemspec'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
desc 'Install the gem locally'
|
|
32
|
+
task install: :build do
|
|
33
|
+
sh 'gem install kapso-client-ruby-*.gem'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
desc 'Release the gem'
|
|
37
|
+
task release: [:clean, :test, :build] do
|
|
38
|
+
puts 'Run `gem push kapso-client-ruby-*.gem` to release'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
41
|
task default: :test
|
data/TEMPLATE_TOOLS_GUIDE.md
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
# 📋 Kapso Template Management Tools
|
|
2
|
-
|
|
3
|
-
## The 24-Hour Problem & Solution
|
|
4
|
-
|
|
5
|
-
**Problem**: You're getting "24 hours have passed" errors when sending messages.
|
|
6
|
-
**Solution**: Use template messages - they work anytime, no 24-hour limit!
|
|
7
|
-
|
|
8
|
-
## 🛠️ Template Tools (Simplified)
|
|
9
|
-
|
|
10
|
-
### 1. `scripts/kapso_template_finder.rb` - **MAIN TOOL** ⭐
|
|
11
|
-
```bash
|
|
12
|
-
ruby scripts/kapso_template_finder.rb
|
|
13
|
-
```
|
|
14
|
-
**Purpose**: Complete template discovery and testing
|
|
15
|
-
**Features**:
|
|
16
|
-
- Fetches your actual created templates from Kapso
|
|
17
|
-
|
|
18
|
-
### 2. `scripts/test.rb` - Basic Message Testing
|
|
19
|
-
```bash
|
|
20
|
-
ruby scripts/test.rb
|
|
21
|
-
```
|
|
22
|
-
**Purpose**: Test regular message sending
|
|
23
|
-
**Use when**: Testing within 24-hour window
|
|
24
|
-
**Features**:
|
|
25
|
-
- Test regular messages
|
|
26
|
-
- Shows 24h error if outside window
|
|
27
|
-
|
|
28
|
-
## 📋 Setup Instructions
|
|
29
|
-
|
|
30
|
-
### Step 1: Find Your Business Account ID
|
|
31
|
-
|
|
32
|
-
1. **Login to Kapso Dashboard**: https://app.kapso.ai/
|
|
33
|
-
2. **Navigate to WhatsApp Business section**
|
|
34
|
-
3. **Look for**:
|
|
35
|
-
- "Business Account ID"
|
|
36
|
-
- "WABA ID"
|
|
37
|
-
- Long number (15+ digits)
|
|
38
|
-
4. **Add to `.env` file**:
|
|
39
|
-
```properties
|
|
40
|
-
BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Step 2: Discover Your Templates
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
ruby scripts/kapso_template_finder.rb
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
✅ **Current Status**: Found 1 template `reply_message (es_MX) - PENDING`
|
|
50
|
-
⏳ **Waiting for approval** - Template will work once Meta approves it
|
|
51
|
-
|
|
52
|
-
### Step 3: Test Templates
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
ruby test_specific_template.rb
|
|
56
|
-
# Enter template name when prompted
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## 🎯 Creating Templates in Kapso
|
|
60
|
-
|
|
61
|
-
### Via Kapso Dashboard:
|
|
62
|
-
1. Login to https://app.kapso.ai/
|
|
63
|
-
2. Find "WhatsApp Templates" or "Template Builder"
|
|
64
|
-
3. Create simple text template:
|
|
65
|
-
- **Name**: `hello_world` or `welcome_message`
|
|
66
|
-
- **Language**: `en_US`
|
|
67
|
-
- **Category**: `UTILITY` (usually fastest approval)
|
|
68
|
-
- **Content**: "Hello {{1}}, welcome to our service!"
|
|
69
|
-
|
|
70
|
-
### Template Approval:
|
|
71
|
-
- **Pending**: Template submitted, waiting for Meta approval
|
|
72
|
-
- **Approved**: Ready to use anytime
|
|
73
|
-
- **Rejected**: Need to fix and resubmit
|
|
74
|
-
- **Time**: Usually 24-48 hours for approval
|
|
75
|
-
|
|
76
|
-
## 🚀 Using Templates in Code
|
|
77
|
-
|
|
78
|
-
```ruby
|
|
79
|
-
# Once your template is approved:
|
|
80
|
-
response = client.messages.send_template(
|
|
81
|
-
phone_number_id: "your_phone_number",
|
|
82
|
-
to: "+56912345678",
|
|
83
|
-
name: "reply_message", # Your actual template name
|
|
84
|
-
language: "es_MX" # Your template language
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
# Templates work 24/7 - no time restrictions!
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## 🔄 Workflow Summary
|
|
91
|
-
|
|
92
|
-
1. **Check templates**: `ruby scripts/kapso_template_finder.rb`
|
|
93
|
-
2. ✅ **Template found**: `reply_message (es_MX) - PENDING`
|
|
94
|
-
3. ⏳ **Wait for approval**: Meta is reviewing your template
|
|
95
|
-
4. **Once approved**: Use `reply_message` template for 24/7 messaging
|
|
96
|
-
|
|
97
|
-
## ❓ Troubleshooting
|
|
98
|
-
|
|
99
|
-
### "Template not found"
|
|
100
|
-
- Template name is wrong
|
|
101
|
-
- Template not approved yet
|
|
102
|
-
- Language code incorrect
|
|
103
|
-
|
|
104
|
-
### "24 hours error" (with templates)
|
|
105
|
-
- This shouldn't happen with templates
|
|
106
|
-
- Contact Kapso support
|
|
107
|
-
|
|
108
|
-
### "Business Account ID not found"
|
|
109
|
-
- Check Kapso dashboard for WABA ID
|
|
110
|
-
- Add to .env file
|
|
111
|
-
- Contact Kapso support if unclear
|
|
112
|
-
|
|
113
|
-
## 📞 Support Resources
|
|
114
|
-
|
|
115
|
-
- **Kapso Dashboard**: https://app.kapso.ai/
|
|
116
|
-
- **Kapso Support**: Contact through dashboard
|
|
117
|
-
- **WhatsApp Template Policies**: Check Meta Business documentation
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
1
|
+
# 📋 Kapso Template Management Tools
|
|
2
|
+
|
|
3
|
+
## The 24-Hour Problem & Solution
|
|
4
|
+
|
|
5
|
+
**Problem**: You're getting "24 hours have passed" errors when sending messages.
|
|
6
|
+
**Solution**: Use template messages - they work anytime, no 24-hour limit!
|
|
7
|
+
|
|
8
|
+
## 🛠️ Template Tools (Simplified)
|
|
9
|
+
|
|
10
|
+
### 1. `scripts/kapso_template_finder.rb` - **MAIN TOOL** ⭐
|
|
11
|
+
```bash
|
|
12
|
+
ruby scripts/kapso_template_finder.rb
|
|
13
|
+
```
|
|
14
|
+
**Purpose**: Complete template discovery and testing
|
|
15
|
+
**Features**:
|
|
16
|
+
- Fetches your actual created templates from Kapso
|
|
17
|
+
|
|
18
|
+
### 2. `scripts/test.rb` - Basic Message Testing
|
|
19
|
+
```bash
|
|
20
|
+
ruby scripts/test.rb
|
|
21
|
+
```
|
|
22
|
+
**Purpose**: Test regular message sending
|
|
23
|
+
**Use when**: Testing within 24-hour window
|
|
24
|
+
**Features**:
|
|
25
|
+
- Test regular messages
|
|
26
|
+
- Shows 24h error if outside window
|
|
27
|
+
|
|
28
|
+
## 📋 Setup Instructions
|
|
29
|
+
|
|
30
|
+
### Step 1: Find Your Business Account ID
|
|
31
|
+
|
|
32
|
+
1. **Login to Kapso Dashboard**: https://app.kapso.ai/
|
|
33
|
+
2. **Navigate to WhatsApp Business section**
|
|
34
|
+
3. **Look for**:
|
|
35
|
+
- "Business Account ID"
|
|
36
|
+
- "WABA ID"
|
|
37
|
+
- Long number (15+ digits)
|
|
38
|
+
4. **Add to `.env` file**:
|
|
39
|
+
```properties
|
|
40
|
+
BUSINESS_ACCOUNT_ID=your_business_account_id_here
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Step 2: Discover Your Templates
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
ruby scripts/kapso_template_finder.rb
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
✅ **Current Status**: Found 1 template `reply_message (es_MX) - PENDING`
|
|
50
|
+
⏳ **Waiting for approval** - Template will work once Meta approves it
|
|
51
|
+
|
|
52
|
+
### Step 3: Test Templates
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
ruby test_specific_template.rb
|
|
56
|
+
# Enter template name when prompted
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 🎯 Creating Templates in Kapso
|
|
60
|
+
|
|
61
|
+
### Via Kapso Dashboard:
|
|
62
|
+
1. Login to https://app.kapso.ai/
|
|
63
|
+
2. Find "WhatsApp Templates" or "Template Builder"
|
|
64
|
+
3. Create simple text template:
|
|
65
|
+
- **Name**: `hello_world` or `welcome_message`
|
|
66
|
+
- **Language**: `en_US`
|
|
67
|
+
- **Category**: `UTILITY` (usually fastest approval)
|
|
68
|
+
- **Content**: "Hello {{1}}, welcome to our service!"
|
|
69
|
+
|
|
70
|
+
### Template Approval:
|
|
71
|
+
- **Pending**: Template submitted, waiting for Meta approval
|
|
72
|
+
- **Approved**: Ready to use anytime
|
|
73
|
+
- **Rejected**: Need to fix and resubmit
|
|
74
|
+
- **Time**: Usually 24-48 hours for approval
|
|
75
|
+
|
|
76
|
+
## 🚀 Using Templates in Code
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
# Once your template is approved:
|
|
80
|
+
response = client.messages.send_template(
|
|
81
|
+
phone_number_id: "your_phone_number",
|
|
82
|
+
to: "+56912345678",
|
|
83
|
+
name: "reply_message", # Your actual template name
|
|
84
|
+
language: "es_MX" # Your template language
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Templates work 24/7 - no time restrictions!
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 🔄 Workflow Summary
|
|
91
|
+
|
|
92
|
+
1. **Check templates**: `ruby scripts/kapso_template_finder.rb`
|
|
93
|
+
2. ✅ **Template found**: `reply_message (es_MX) - PENDING`
|
|
94
|
+
3. ⏳ **Wait for approval**: Meta is reviewing your template
|
|
95
|
+
4. **Once approved**: Use `reply_message` template for 24/7 messaging
|
|
96
|
+
|
|
97
|
+
## ❓ Troubleshooting
|
|
98
|
+
|
|
99
|
+
### "Template not found"
|
|
100
|
+
- Template name is wrong
|
|
101
|
+
- Template not approved yet
|
|
102
|
+
- Language code incorrect
|
|
103
|
+
|
|
104
|
+
### "24 hours error" (with templates)
|
|
105
|
+
- This shouldn't happen with templates
|
|
106
|
+
- Contact Kapso support
|
|
107
|
+
|
|
108
|
+
### "Business Account ID not found"
|
|
109
|
+
- Check Kapso dashboard for WABA ID
|
|
110
|
+
- Add to .env file
|
|
111
|
+
- Contact Kapso support if unclear
|
|
112
|
+
|
|
113
|
+
## 📞 Support Resources
|
|
114
|
+
|
|
115
|
+
- **Kapso Dashboard**: https://app.kapso.ai/
|
|
116
|
+
- **Kapso Support**: Contact through dashboard
|
|
117
|
+
- **WhatsApp Template Policies**: Check Meta Business documentation
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
121
|
**Remember**: Templates solve the 24-hour limitation permanently! Regular messages work within 24h of customer reply, templates work anytime. 🎯
|
data/WHATSAPP_24_HOUR_GUIDE.md
CHANGED
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
# WhatsApp 24-Hour Window Policy - Solutions Guide
|
|
2
|
-
|
|
3
|
-
## The Problem You're Experiencing
|
|
4
|
-
|
|
5
|
-
**Error Message**: "Meta reported a deli### Long-term**: Design your messaging strategy around the 24h rule
|
|
6
|
-
|
|
7
|
-
## Kapso.ai Specific Features
|
|
8
|
-
|
|
9
|
-
Since you're using Kapso.ai, you may have access to:
|
|
10
|
-
|
|
11
|
-
- **Template Library**: Pre-built approved templates
|
|
12
|
-
- **Template Builder**: Easy template creation interface
|
|
13
|
-
- **Auto-Approval**: Faster template approval process
|
|
14
|
-
- **Template Analytics**: Usage statistics and delivery rates
|
|
15
|
-
- **Bulk Template Management**: Manage multiple templates
|
|
16
|
-
|
|
17
|
-
Check your Kapso dashboard for:
|
|
18
|
-
1. **Available Templates** - Already approved and ready to use
|
|
19
|
-
2. **Template Status** - Pending, approved, or rejected templates
|
|
20
|
-
3. **Template Builder** - Create new templates without Meta Business Manager
|
|
21
|
-
|
|
22
|
-
## Why This Existsy error. Re-engagement message Message failed to send because more than 24 hours have passed since the customer last replied to this number."
|
|
23
|
-
|
|
24
|
-
This is **NOT** a bug in your Ruby SDK - it's a WhatsApp Business API policy.
|
|
25
|
-
|
|
26
|
-
## Understanding the 24-Hour Rule
|
|
27
|
-
|
|
28
|
-
WhatsApp Business API has a **conversation window** policy:
|
|
29
|
-
|
|
30
|
-
### ✅ Within 24 Hours (Free Messaging Window)
|
|
31
|
-
- **Trigger**: Customer sends you a message
|
|
32
|
-
- **Duration**: 24 hours from their last message
|
|
33
|
-
- **Allowed**: ANY message type (text, images, audio, video, documents)
|
|
34
|
-
- **No restrictions**: Send as many messages as you want
|
|
35
|
-
|
|
36
|
-
### ❌ After 24 Hours (Template-Only Window)
|
|
37
|
-
- **Trigger**: 24+ hours since customer's last message
|
|
38
|
-
- **Restriction**: ONLY pre-approved template messages allowed
|
|
39
|
-
- **Regular messages**: Will be rejected with your error
|
|
40
|
-
|
|
41
|
-
## Solutions
|
|
42
|
-
|
|
43
|
-
### Option 1: Use Template Messages (Recommended)
|
|
44
|
-
|
|
45
|
-
Template messages work anytime and are designed for business communications:
|
|
46
|
-
|
|
47
|
-
```ruby
|
|
48
|
-
# Send a template message (works 24/7)
|
|
49
|
-
response = client.messages.send_template(
|
|
50
|
-
phone_number_id: phone_number_id,
|
|
51
|
-
to: "+56912345678",
|
|
52
|
-
template_name: "hello_world", # Must be pre-approved
|
|
53
|
-
template_language: "en_US"
|
|
54
|
-
)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Option 2: Wait for Customer Reply
|
|
58
|
-
|
|
59
|
-
- Customer sends any message → Opens 24-hour window
|
|
60
|
-
- You can then send regular messages for 24 hours
|
|
61
|
-
|
|
62
|
-
### Option 3: Create Templates via Kapso.ai
|
|
63
|
-
|
|
64
|
-
✅ **Current Status**: You already have templates in progress!
|
|
65
|
-
|
|
66
|
-
1. **Kapso Dashboard**: ✅ Connected (Business Account: `your_business_id_account`)
|
|
67
|
-
2. **Template Found**: `reply_message (es_MX) - PENDING`
|
|
68
|
-
3. **Status**: Waiting for Meta approval (usually 24-48 hours)
|
|
69
|
-
4. **Once Approved**: Use `your_template` template for 24/7 messaging
|
|
70
|
-
5. **Test Tool**: `ruby scripts/kapso_template_finder.rb`
|
|
71
|
-
|
|
72
|
-
## Prevention Strategies
|
|
73
|
-
|
|
74
|
-
### For Customer Service
|
|
75
|
-
- Respond within 24 hours of customer messages
|
|
76
|
-
- Use templates for follow-ups after 24h
|
|
77
|
-
- Set up auto-responses within the window
|
|
78
|
-
|
|
79
|
-
### For Marketing
|
|
80
|
-
- Always use approved template messages
|
|
81
|
-
- Create templates for different campaigns
|
|
82
|
-
- Schedule template sends anytime
|
|
83
|
-
|
|
84
|
-
### For Notifications
|
|
85
|
-
- Use templates for order updates, reminders, etc.
|
|
86
|
-
- Create templates for common notifications
|
|
87
|
-
- Test templates before going live
|
|
88
|
-
|
|
89
|
-
## Template Message Examples
|
|
90
|
-
|
|
91
|
-
### Basic Template (No Variables)
|
|
92
|
-
```ruby
|
|
93
|
-
client.messages.send_template(
|
|
94
|
-
phone_number_id: phone_number_id,
|
|
95
|
-
to: phone_number,
|
|
96
|
-
template_name: "hello_world",
|
|
97
|
-
template_language: "en_US"
|
|
98
|
-
)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Template with Variables
|
|
102
|
-
```ruby
|
|
103
|
-
client.messages.send_template(
|
|
104
|
-
phone_number_id: phone_number_id,
|
|
105
|
-
to: phone_number,
|
|
106
|
-
template_name: "order_confirmation",
|
|
107
|
-
template_language: "en_US",
|
|
108
|
-
components: [
|
|
109
|
-
{
|
|
110
|
-
type: "body",
|
|
111
|
-
parameters: [
|
|
112
|
-
{ type: "text", text: "John" }, # Customer name
|
|
113
|
-
{ type: "text", text: "12345" } # Order number
|
|
114
|
-
]
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
)
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## Next Steps
|
|
121
|
-
|
|
122
|
-
1. **Immediate**: Use `ruby template_test.rb` to test template messages
|
|
123
|
-
2. **Short-term**: Create templates in Meta Business Manager
|
|
124
|
-
3. **Long-term**: Design your messaging strategy around the 24h rule
|
|
125
|
-
|
|
126
|
-
## Why This Exists
|
|
127
|
-
|
|
128
|
-
WhatsApp enforces this to:
|
|
129
|
-
- Prevent spam
|
|
130
|
-
- Ensure quality business communications
|
|
131
|
-
- Protect user experience
|
|
132
|
-
- Maintain platform integrity
|
|
133
|
-
|
|
1
|
+
# WhatsApp 24-Hour Window Policy - Solutions Guide
|
|
2
|
+
|
|
3
|
+
## The Problem You're Experiencing
|
|
4
|
+
|
|
5
|
+
**Error Message**: "Meta reported a deli### Long-term**: Design your messaging strategy around the 24h rule
|
|
6
|
+
|
|
7
|
+
## Kapso.ai Specific Features
|
|
8
|
+
|
|
9
|
+
Since you're using Kapso.ai, you may have access to:
|
|
10
|
+
|
|
11
|
+
- **Template Library**: Pre-built approved templates
|
|
12
|
+
- **Template Builder**: Easy template creation interface
|
|
13
|
+
- **Auto-Approval**: Faster template approval process
|
|
14
|
+
- **Template Analytics**: Usage statistics and delivery rates
|
|
15
|
+
- **Bulk Template Management**: Manage multiple templates
|
|
16
|
+
|
|
17
|
+
Check your Kapso dashboard for:
|
|
18
|
+
1. **Available Templates** - Already approved and ready to use
|
|
19
|
+
2. **Template Status** - Pending, approved, or rejected templates
|
|
20
|
+
3. **Template Builder** - Create new templates without Meta Business Manager
|
|
21
|
+
|
|
22
|
+
## Why This Existsy error. Re-engagement message Message failed to send because more than 24 hours have passed since the customer last replied to this number."
|
|
23
|
+
|
|
24
|
+
This is **NOT** a bug in your Ruby SDK - it's a WhatsApp Business API policy.
|
|
25
|
+
|
|
26
|
+
## Understanding the 24-Hour Rule
|
|
27
|
+
|
|
28
|
+
WhatsApp Business API has a **conversation window** policy:
|
|
29
|
+
|
|
30
|
+
### ✅ Within 24 Hours (Free Messaging Window)
|
|
31
|
+
- **Trigger**: Customer sends you a message
|
|
32
|
+
- **Duration**: 24 hours from their last message
|
|
33
|
+
- **Allowed**: ANY message type (text, images, audio, video, documents)
|
|
34
|
+
- **No restrictions**: Send as many messages as you want
|
|
35
|
+
|
|
36
|
+
### ❌ After 24 Hours (Template-Only Window)
|
|
37
|
+
- **Trigger**: 24+ hours since customer's last message
|
|
38
|
+
- **Restriction**: ONLY pre-approved template messages allowed
|
|
39
|
+
- **Regular messages**: Will be rejected with your error
|
|
40
|
+
|
|
41
|
+
## Solutions
|
|
42
|
+
|
|
43
|
+
### Option 1: Use Template Messages (Recommended)
|
|
44
|
+
|
|
45
|
+
Template messages work anytime and are designed for business communications:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# Send a template message (works 24/7)
|
|
49
|
+
response = client.messages.send_template(
|
|
50
|
+
phone_number_id: phone_number_id,
|
|
51
|
+
to: "+56912345678",
|
|
52
|
+
template_name: "hello_world", # Must be pre-approved
|
|
53
|
+
template_language: "en_US"
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Option 2: Wait for Customer Reply
|
|
58
|
+
|
|
59
|
+
- Customer sends any message → Opens 24-hour window
|
|
60
|
+
- You can then send regular messages for 24 hours
|
|
61
|
+
|
|
62
|
+
### Option 3: Create Templates via Kapso.ai
|
|
63
|
+
|
|
64
|
+
✅ **Current Status**: You already have templates in progress!
|
|
65
|
+
|
|
66
|
+
1. **Kapso Dashboard**: ✅ Connected (Business Account: `your_business_id_account`)
|
|
67
|
+
2. **Template Found**: `reply_message (es_MX) - PENDING`
|
|
68
|
+
3. **Status**: Waiting for Meta approval (usually 24-48 hours)
|
|
69
|
+
4. **Once Approved**: Use `your_template` template for 24/7 messaging
|
|
70
|
+
5. **Test Tool**: `ruby scripts/kapso_template_finder.rb`
|
|
71
|
+
|
|
72
|
+
## Prevention Strategies
|
|
73
|
+
|
|
74
|
+
### For Customer Service
|
|
75
|
+
- Respond within 24 hours of customer messages
|
|
76
|
+
- Use templates for follow-ups after 24h
|
|
77
|
+
- Set up auto-responses within the window
|
|
78
|
+
|
|
79
|
+
### For Marketing
|
|
80
|
+
- Always use approved template messages
|
|
81
|
+
- Create templates for different campaigns
|
|
82
|
+
- Schedule template sends anytime
|
|
83
|
+
|
|
84
|
+
### For Notifications
|
|
85
|
+
- Use templates for order updates, reminders, etc.
|
|
86
|
+
- Create templates for common notifications
|
|
87
|
+
- Test templates before going live
|
|
88
|
+
|
|
89
|
+
## Template Message Examples
|
|
90
|
+
|
|
91
|
+
### Basic Template (No Variables)
|
|
92
|
+
```ruby
|
|
93
|
+
client.messages.send_template(
|
|
94
|
+
phone_number_id: phone_number_id,
|
|
95
|
+
to: phone_number,
|
|
96
|
+
template_name: "hello_world",
|
|
97
|
+
template_language: "en_US"
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Template with Variables
|
|
102
|
+
```ruby
|
|
103
|
+
client.messages.send_template(
|
|
104
|
+
phone_number_id: phone_number_id,
|
|
105
|
+
to: phone_number,
|
|
106
|
+
template_name: "order_confirmation",
|
|
107
|
+
template_language: "en_US",
|
|
108
|
+
components: [
|
|
109
|
+
{
|
|
110
|
+
type: "body",
|
|
111
|
+
parameters: [
|
|
112
|
+
{ type: "text", text: "John" }, # Customer name
|
|
113
|
+
{ type: "text", text: "12345" } # Order number
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Next Steps
|
|
121
|
+
|
|
122
|
+
1. **Immediate**: Use `ruby template_test.rb` to test template messages
|
|
123
|
+
2. **Short-term**: Create templates in Meta Business Manager
|
|
124
|
+
3. **Long-term**: Design your messaging strategy around the 24h rule
|
|
125
|
+
|
|
126
|
+
## Why This Exists
|
|
127
|
+
|
|
128
|
+
WhatsApp enforces this to:
|
|
129
|
+
- Prevent spam
|
|
130
|
+
- Ensure quality business communications
|
|
131
|
+
- Protect user experience
|
|
132
|
+
- Maintain platform integrity
|
|
133
|
+
|
|
134
134
|
The Ruby SDK is working perfectly - this is just how WhatsApp Business API works! 🚀
|