Hi <%= customer_name %>,
Thanks for signing up! Your account is now active.
Get started by exploring our features:
- π€ AI Voice Calls
- π¬ SMS Messaging
- π§ Email Campaigns
Enterprise-grade Voice, SMS, Email & AI API for Ruby & Rails applications
The Ruby gem will be available via RubyGems when released:
# Coming soon!
gem install team_connect
# Or add to your Gemfile
gem 'team_connect'
# For now, use net/http or http gem
gem 'http'
Here's how you'll use the Ruby gem once it's available:
# Future gem usage
require 'team_connect'
# Initialize with your API key
client = TeamConnect.new('tc_live_your_api_key_here')
# Make a voice call
call_result = client.voice.make_call(
to: '+447123456789',
message: 'Hello from Team Connect!'
)
puts "Call initiated: #{call_result.call_id}"
# Send an SMS
sms_result = client.sms.send(
to: '+447123456789',
message: 'Your verification code is 123456'
)
puts "SMS sent: #{sms_result.message_id}"
# Send an email
email_result = client.email.send(
to: 'customer@example.com',
subject: 'Welcome to our service',
html: 'Welcome!
Thanks for signing up.
'
)
puts "Email sent: #{email_result.message_id}"
# AI Chat
ai_result = client.ai.chat([
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' }
])
puts "AI Response: #{ai_result.response}"
Until the gem is ready, use our REST API with the HTTP gem:
require 'http'
require 'json'
class TeamConnectAPI
API_BASE_URL = 'https://us-central1-customerservice-2156c.cloudfunctions.net'
def initialize(api_key)
@api_key = api_key
@http = HTTP.headers(
'Content-Type' => 'application/json'
).timeout(30)
end
private
def make_request(service, action, data)
payload = {
service: service,
action: action,
data: data,
api_key: @api_key
}
response = @http.post("#{API_BASE_URL}/executeAPI", json: payload)
case response.code
when 401
raise TeamConnectError, 'Invalid API key'
when 402
raise InsufficientCreditsError, 'Insufficient credits. Please top up your account.'
when 429
raise RateLimitError, 'Rate limit exceeded'
when 500
raise TeamConnectError, 'Internal server error'
when 200
JSON.parse(response.body)
else
error_data = JSON.parse(response.body) rescue {}
raise TeamConnectError, error_data['error'] || 'Unknown error'
end
end
end
# Custom exception classes
class TeamConnectError < StandardError; end
class InsufficientCreditsError < TeamConnectError; end
class RateLimitError < TeamConnectError; end
# Initialize the API client
client = TeamConnectAPI.new('tc_live_your_api_key_here')
Make AI-powered voice calls to any phone number:
# Add to TeamConnectAPI class
def make_call(to:, message:, from: nil, voice: nil, webhook_url: nil)
begin
result = make_request('voice', 'make_call', {
to: to,
message: message,
from: from,
voice: voice,
webhook_url: webhook_url
})
OpenStruct.new(result['result']) if result['success']
rescue => e
puts "Call failed: #{e.message}"
nil
end
end
# Example usage
call_result = client.make_call(
to: '+447123456789',
message: 'Hi, this is Sarah from Dad-Link calling to confirm your appointment tomorrow at 2 PM. Can you please confirm if this time still works for you?',
voice: 'Polly.Amy' # British English voice
)
if call_result
puts "β
Call initiated successfully!"
puts "Call ID: #{call_result.call_id}"
puts "Status: #{call_result.status}"
puts "To: #{call_result.to}"
puts "From: #{call_result.from}"
else
puts "β Call failed"
end
client.make_call(
to: customer.phone,
message: "Hi #{customer.name}, this is confirming your #{appointment.service} appointment tomorrow at #{appointment.time}. Reply YES to confirm or NO to reschedule."
)
client.make_call(
to: customer.phone,
message: "Hello #{customer.name}, this is a friendly reminder that your payment of Β£#{invoice.amount} is due. You can pay online at #{payment_url} or call us back."
)
Send SMS messages to any mobile number:
# Add to TeamConnectAPI class
def send_sms(to:, message:, from: nil)
begin
result = make_request('sms', 'send', {
to: to,
message: message,
from: from
})
OpenStruct.new(result['result']) if result['success']
rescue => e
puts "SMS failed: #{e.message}"
nil
end
end
# Example usage
sms_result = client.send_sms(
to: '+447123456789',
message: 'Your verification code is 123456. Valid for 5 minutes.'
)
if sms_result
puts "β
SMS sent successfully!"
puts "Message ID: #{sms_result.message_id}"
puts "Status: #{sms_result.status}"
puts "To: #{sms_result.to}"
else
puts "β SMS failed"
end
code = SecureRandom.random_number(100000..999999)
user.update(verification_code: code)
client.send_sms(
to: user.phone,
message: "Your #{app_name} verification code: #{code}"
)
client.send_sms(
to: order.customer.phone,
message: "Your order ##{order.number} is #{order.status}. Track: #{order.tracking_url}"
)
Send HTML emails with high deliverability:
# Add to TeamConnectAPI class
def send_email(to:, subject:, html:, from_name: nil)
begin
result = make_request('email', 'send', {
to: to,
subject: subject,
html: html,
from_name: from_name || 'Team Connect'
})
OpenStruct.new(result['result']) if result['success']
rescue => e
puts "Email failed: #{e.message}"
nil
end
end
# Example usage with ERB template
require 'erb'
template = <<~HTML
Welcome to <%= company_name %>!
Hi <%= customer_name %>,
Thanks for signing up! Your account is now active.
Get started by exploring our features:
- π€ AI Voice Calls
- π¬ SMS Messaging
- π§ Email Campaigns
HTML
# Render template with variables
html_content = ERB.new(template).result(binding.tap do |b|
b.local_variable_set(:company_name, 'Dad-Link')
b.local_variable_set(:customer_name, 'John Doe')
b.local_variable_set(:dashboard_url, 'https://team-connect.co.uk/dashboard.html')
end)
email_result = client.send_email(
to: 'customer@example.com',
subject: 'Welcome to Dad-Link - Your Account is Ready!',
html: html_content,
from_name: 'Dad-Link Team'
)
if email_result
puts "β
Email sent successfully!"
puts "Message ID: #{email_result.message_id}"
puts "Status: #{email_result.status}"
puts "To: #{email_result.to}"
else
puts "β Email failed"
end
Use GPT-4 for intelligent conversations:
# Add to TeamConnectAPI class
def ai_chat(messages, model: 'gpt-4')
begin
result = make_request('ai', 'chat', {
messages: messages,
model: model
})
OpenStruct.new(result['result']) if result['success']
rescue => e
puts "AI chat failed: #{e.message}"
nil
end
end
# Example usage
conversation = [
{
role: 'system',
content: 'You are a helpful customer service assistant for Dad-Link, a communication platform.'
},
{
role: 'user',
content: 'How do I set up voice calls in my Ruby application?'
}
]
ai_result = client.ai_chat(conversation)
if ai_result
puts "β
AI Response:"
puts ai_result.response
puts "Tokens used: #{ai_result.tokens_used}"
puts "Model: #{ai_result.model}"
else
puts "β AI chat failed"
end
Future Rails integration will include generators, ActiveRecord integrations, and background jobs:
# Future Rails integration
# config/initializers/team_connect.rb
TeamConnect.configure do |config|
config.api_key = Rails.application.credentials.team_connect_api_key
config.default_from_number = '+441234567890'
config.default_sms_number = '+441234567890'
config.default_from_email = 'noreply@yourapp.com'
config.webhook_url = Rails.application.routes.url_helpers.team_connect_webhooks_url
end
# app/models/user.rb
class User < ApplicationRecord
include TeamConnect::Contactable
# Adds methods like:
# user.send_voice_call(message)
# user.send_sms(message)
# user.send_email(subject, html)
end
# app/controllers/team_connect_controller.rb
class TeamConnectController < ApplicationController
include TeamConnect::WebhookHandler
# Automatically handles webhook events
def voice_call_completed(event)
# Handle completed voice call
call = Call.find_by(team_connect_id: event.call_id)
call.update(status: event.status, duration: event.duration)
end
def sms_delivered(event)
# Handle SMS delivery
message = SmsMessage.find_by(team_connect_id: event.message_id)
message.update(status: :delivered)
end
end
# Background jobs with Sidekiq/Resque
class VoiceCallJob < ApplicationJob
def perform(user_id, message)
user = User.find(user_id)
user.send_voice_call(message)
end
end
# Usage in your app
VoiceCallJob.perform_later(user.id, 'Your appointment is confirmed')
# Rake tasks
# rails team_connect:install
# rails generate team_connect:webhook_controller
# rails generate team_connect:migration
Robust error handling for production Ruby applications:
require 'logger'
# Custom exception classes
class TeamConnectError < StandardError
attr_reader :code, :response
def initialize(message, code: nil, response: nil)
super(message)
@code = code
@response = response
end
end
class InsufficientCreditsError < TeamConnectError; end
class InvalidAPIKeyError < TeamConnectError; end
class RateLimitError < TeamConnectError; end
class TeamConnectAPIEnhanced
API_BASE_URL = 'https://us-central1-customerservice-2156c.cloudfunctions.net'
def initialize(api_key:, timeout: 30, max_retries: 3, logger: nil)
@api_key = api_key
@timeout = timeout
@max_retries = max_retries
@logger = logger || Logger.new($stdout)
@http = HTTP.headers('Content-Type' => 'application/json').timeout(@timeout)
end
def make_call_safe(to:, message:, **options)
with_retries do
result = make_request('voice', 'make_call', {
to: to,
message: message,
**options
})
OpenStruct.new(result['result']) if result['success']
end
rescue InsufficientCreditsError => e
@logger.error "π° Credit Error: #{e.message}"
@logger.info "π‘ Top up at: https://team-connect.co.uk/api-dashboard.html#topup"
nil
rescue InvalidAPIKeyError => e
@logger.error "π Auth Error: #{e.message}"
@logger.info "π‘ Check your API key in the dashboard"
nil
rescue RateLimitError => e
@logger.warn "β±οΈ Rate Limit: #{e.message}"
@logger.info "π‘ Slow down your requests or upgrade your plan"
nil
rescue TeamConnectError => e
@logger.error "β API Error: #{e.message}"
nil
end
def send_sms_safe(to:, message:, **options)
with_retries do
result = make_request('sms', 'send', {
to: to,
message: message,
**options
})
OpenStruct.new(result['result']) if result['success']
end
rescue => e
@logger.error "SMS Error: #{e.message}"
nil
end
def send_email_safe(to:, subject:, html:, **options)
with_retries do
result = make_request('email', 'send', {
to: to,
subject: subject,
html: html,
**options
})
OpenStruct.new(result['result']) if result['success']
end
rescue => e
@logger.error "Email Error: #{e.message}"
nil
end
private
def with_retries
attempts = 0
begin
attempts += 1
yield
rescue HTTP::TimeoutError, HTTP::ConnectionError => e
if attempts <= @max_retries
wait_time = 2 ** (attempts - 1)
@logger.warn "Connection error, retrying in #{wait_time}s... (attempt #{attempts})"
sleep(wait_time)
retry
else
raise TeamConnectError, "Connection failed after #{@max_retries} retries: #{e.message}"
end
end
end
def make_request(service, action, data)
payload = {
service: service,
action: action,
data: data,
api_key: @api_key
}
response = @http.post("#{API_BASE_URL}/executeAPI", json: payload)
case response.code
when 401
raise InvalidAPIKeyError, 'Invalid or revoked API key'
when 402
error_data = JSON.parse(response.body) rescue {}
raise InsufficientCreditsError, error_data['error'] || 'Insufficient credits'
when 429
raise RateLimitError, 'Rate limit exceeded'
when 500
raise TeamConnectError, 'Internal server error', code: 500
when 200
JSON.parse(response.body)
else
error_data = JSON.parse(response.body) rescue {}
raise TeamConnectError, error_data['error'] || 'Unknown error', code: response.code
end
end
end
# Usage example with comprehensive error handling
logger = Logger.new($stdout)
logger.level = Logger::INFO
client = TeamConnectAPIEnhanced.new(
api_key: 'tc_live_your_api_key_here',
logger: logger
)
# Safe method calls that won't raise exceptions
call_result = client.make_call_safe(
to: '+447123456789',
message: 'Hello, this is a test call with error handling.',
voice: 'Polly.Amy'
)
if call_result
puts "β
Call successful: #{call_result.call_id}"
else
puts "β Call failed - check logs for details"
end
sms_result = client.send_sms_safe(
to: '+447123456789',
message: 'Test SMS with error handling'
)
if sms_result
puts "β
SMS successful: #{sms_result.message_id}"
else
puts "β SMS failed - check logs for details"
end
Transparent, pay-per-use pricing with no monthly fees:
Service | Price | Unit | Ruby Example |
---|---|---|---|
π Voice Calls | 7p | per minute | client.make_call(to: number, message: text) |
π¬ SMS Messages | 3p | per message | client.send_sms(to: number, message: text) |
π§ Email Sending | 0.15p | per email | client.send_email(to: email, subject: subject, html: html) |
π€ AI Processing | 15p | per request | client.ai_chat(messages) |
Typical monthly usage for a Rails SaaS app:
π³ Top up credits: Visit your API Dashboard to add credits. Minimum top-up: Β£5.00
Need help? Contact us at support@team-connect.co.uk
β Back to API Dashboard | REST API Docs | Python SDK
Β© 2025 Dad-Link. All rights reserved. | Last updated: 2025-08-05 15:02:58 UTC