-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_send_now.rb
More file actions
68 lines (60 loc) · 2.3 KB
/
test_send_now.rb
File metadata and controls
68 lines (60 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
#!/usr/bin/env ruby
# frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
require 'ccai'
require 'faraday'
require 'json'
# Load environment variables
begin
require 'dotenv'
Dotenv.load
rescue LoadError
end
# Test with query parameter ?send=true
puts "Testing email send with ?send=true parameter..."
connection = Faraday.new do |conn|
conn.headers['Authorization'] = "Bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhbmRyZWFzQGFsbGNvZGUuY29tIiwiaXNzIjoiY2xvdWRjb250YWN0IiwibmJmIjoxNzUyMDg5MDk2LCJpYXQiOjE3NTIwODkwOTYsInJvbGUiOiJVU0VSIiwiY2xpZW50SWQiOjEyMzEsImlkIjoxMjIzLCJ0eXBlIjoiQVBJX0tFWSIsImtleV9yYW5kb21faWQiOiIzNTAxZjVmNC0zOWYyLTRjYzctYTk2Yi04ZDkyZjVlMjM5ZGUifQ.XjtDPpyYUJNJjLrpM1pdQ4Sqk90eaagqzPX2v1gwHDP1wOV4fTbB44UGDRXtWyGvN-Fz7o84_Ab-VlAjNCyEmXcDzmzscnwFSbqiZrWLAM_W3Mutd36vArl9QSG_osuYdf9T2wmAduUZu2bcnvKHdBbEaBUalJSSUoHwHsMBX3w"
conn.headers['Content-Type'] = 'application/json'
conn.headers['Accept'] = '*/*'
conn.headers['AccountId'] = '1223'
conn.headers['ClientId'] = '1231'
conn.headers['Origin'] = 'https://test-cloudcontactai.allcode.com'
end
campaign_data = {
subject: 'CCAI Ruby - Send Now Test',
title: 'Ruby Send Now Test',
message: '<h1>Hello Andreas!</h1><p>Testing immediate send with query parameter.</p><p>Time: ' + Time.now.to_s + '</p>',
senderEmail: 'noreply@allcode.com',
replyEmail: 'support@allcode.com',
senderName: 'CCAI Ruby Client',
accounts: [
{ firstName: 'Andreas', lastName: 'AllCode', email: 'andreas@allcode.com', phone: '' }
],
campaignType: 'EMAIL',
addToList: 'noList',
contactInput: 'accounts',
fromType: 'single',
senders: []
}
begin
response = connection.post(
'https://email-campaigns-test-cloudcontactai.allcode.com/api/v1/campaigns?send=true',
campaign_data.to_json
)
if response.success?
result = JSON.parse(response.body)
puts "✅ Campaign created with send=true: #{result['id']}"
puts "Status: #{result['status']}"
puts "Total Sent: #{result['totalSent']}"
puts "Total Pending: #{result['totalPending']}"
if result['totalSent'] > 0
puts "🎉 EMAIL ACTUALLY SENT!"
else
puts "⚠️ Still pending, but trying query parameter worked"
end
else
puts "❌ Failed: #{response.status} - #{response.body}"
end
rescue => e
puts "❌ Error: #{e.message}"
end