Twilio SMS Automation について
Twilioを使ったSMS、音声通話、認証のワークフローを設計するスキルです。メッセージテンプレート、一括配信、番号管理、配信分析を扱います。
主な機能
- 01SMSテンプレートと双方向メッセージ
- 02SMS、通話、メール、WhatsAppによる認証
- 03発信通話とIVRメニュー
- 04一括配信キャンペーンの設定
- 05電話番号の検索とプロビジョニング
- 06配信分析とステータス追跡
活用シーン
- 01注文や配送の通知送信
- 02アプリへの電話番号認証の追加
- 03オプトイン済み宛先への一括配信
- 04発信通話とIVRフローの設定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ claude-office-skills/ skills --skill twilio-sms-automationインストール後、Claude Code で/twilio-sms-automationを入力して読み込まれたか確認します。
詳細
Twilio SMS 自動化
Twilio を使用して SMS、音声、認証のワークフローを自動化するための包括的なスキルです。
主要なワークフロー
1. SMS メッセージ送信フロー
SMS AUTOMATION FLOW:
┌─────────────────┐
│ Trigger │
│ (Event/API) │
└────────┬────────┘
▼
┌─────────────────┐
│ Message Build │
│ - Template │
│ - Personalize │
└────────┬────────┘
▼
┌─────────────────┐
│ Number Lookup │
│ - Validate │
│ - Format │
└────────┬────────┘
▼
┌─────────────────┐
│ Send │
│ - Twilio API │
│ - Queue │
└────────┬────────┘
▼
┌─────────────────┐
│ Delivery │
│ - Status │
│ - Callback │
└─────────────────┘
2. メッセージの設定
sms_config:
sender:
phone_number: "+1234567890"
messaging_service_sid: "MG..." # For higher throughput
defaults:
status_callback: "https://api.example.com/sms/status"
validity_period: 14400 # 4 hours
rate_limiting:
messages_per_second: 10
daily_limit_per_recipient: 5
compliance:
opt_out_keywords: ["STOP", "UNSUBSCRIBE", "CANCEL"]
opt_in_required: true
quiet_hours:
start: "21:00"
end: "09:00"
timezone: "America/New_York"
メッセージテンプレート
通知テンプレート
templates:
order_confirmation:
content: |
{{company}}: Your order #{{order_id}} has been confirmed!
Total: ${{total}}
Track: {{tracking_url}}
Reply HELP for assistance.
max_length: 160
shipping_update:
content: |
{{company}}: Your order #{{order_id}} has shipped!
Carrier: {{carrier}}
Tracking: {{tracking_number}}
Delivery: {{estimated_date}}
appointment_reminder:
content: |
Reminder: Your appointment with {{provider}} is tomorrow at {{time}}.
Location: {{address}}
Reply C to confirm or R to reschedule.
two_factor:
content: |
Your {{company}} verification code is: {{code}}
This code expires in 10 minutes.
Don't share this code with anyone.
会話テンプレート
two_way_messaging:
welcome:
trigger: opt_in
response: |
Welcome to {{company}} updates!
You'll receive order and shipping notifications.
Reply HELP for commands or STOP to unsubscribe.
help:
trigger: ["HELP", "?", "INFO"]
response: |
{{company}} SMS Commands:
STATUS - Check order status
TRACK - Get tracking info
SUPPORT - Contact support
STOP - Unsubscribe
status_inquiry:
trigger: ["STATUS", "ORDER"]
action: lookup_order
response: |
Order #{{order_id}}: {{status}}
{{#if tracking}}
Tracking: {{tracking_url}}
{{/if}}
unsubscribe:
trigger: ["STOP", "UNSUBSCRIBE"]
action: opt_out
response: |
You've been unsubscribed from {{company}} messages.
Reply START to resubscribe anytime.
認証(二要素認証)
Verify API の統合
verification_config:
channel: sms # or: call, email, whatsapp
code_settings:
length: 6
expiry_minutes: 10
rate_limits:
max_attempts: 5
lockout_minutes: 30
templates:
sms: "Your {{company}} code is {{code}}"
call: "Your verification code is {{code_spoken}}"
認証フロー
// Start Verification
const verification = await twilio.verify.v2
.services('VA...')
.verifications
.create({
to: '+1234567890',
channel: 'sms',
customCode: '123456', // Optional
locale: 'en'
});
// Check Verification
const check = await twilio.verify.v2
.services('VA...')
.verificationChecks
.create({
to: '+1234567890',
code: '123456'
});
// Result
if (check.status === 'approved') {
// Verification successful
} else {
// Invalid code
}
音声の自動化
発信
voice_config:
outbound_call:
from: "+1234567890"
twiml_url: "https://api.example.com/voice/script"
status_callback: "https://api.example.com/voice/status"
timeout: 30
record: true
twiml_script: |
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice">
Hello {{name}}, this is a reminder about your
appointment tomorrow at {{time}}.
</Say>
<Gather numDigits="1" action="/handle-response">
<Say>Press 1 to confirm, 2 to reschedule.</Say>
</Gather>
</Response>
IVR メニュー
ivr_menu:
greeting: |
Thank you for calling {{company}}.
For sales, press 1.
For support, press 2.
For billing, press 3.
To speak with an operator, press 0.
routing:
- digit: "1"
action: transfer
destination: "+1987654321"
queue: "sales"
- digit: "2"
action: transfer
destination: "+1876543210"
queue: "support"
- digit: "3"
action: transfer
destination: "+1765432109"
queue: "billing"
- digit: "0"
action: operator
fallback: voicemail
一括メッセージ送信
キャンペーンの設定
bulk_campaign:
name: "Holiday Promotion"
audience:
source: segment
filter:
opted_in: true
last_purchase: "> 30_days"
message:
template: holiday_promo
variables:
discount_code: "HOLIDAY20"
schedule:
start_time: "2024-11-25T10:00:00"
timezone: "America/New_York"
batch_size: 100
delay_between_batches: 60 # seconds
tracking:
delivery_report: true
click_tracking: true
conversion_tracking: true
一斉送信のステータス
CAMPAIGN STATUS: Holiday Promotion
═══════════════════════════════════════
Progress: ████████████████░░░░ 78%
DELIVERY STATS:
Sent: 7,800
Delivered: 7,450 (95.5%)
Failed: 125 (1.6%)
Pending: 225 (2.9%)
ENGAGEMENT:
Clicks: 1,245 (16.7%)
Replies: 89 (1.2%)
Opt-outs: 23 (0.3%)
ERRORS:
Invalid Number: 45
Unsubscribed: 52
Carrier Block: 18
Rate Limited: 10
ESTIMATED COMPLETION: 25 minutes
電話番号の管理
電話番号の検索
number_lookup:
capabilities:
- carrier_info
- caller_name
- line_type
validation:
- check_format
- verify_active
- detect_landline_vs_mobile
example_response:
phone_number: "+14155551234"
country_code: "US"
carrier:
name: "Verizon"
type: "mobile"
caller_name: "John Doe"
valid: true
電話番号のプロビジョニング
number_management:
search_criteria:
country: "US"
area_code: "415"
capabilities: ["SMS", "MMS", "Voice"]
purchase:
phone_number: "+14155559999"
friendly_name: "Marketing Line"
sms_url: "https://api.example.com/sms/incoming"
voice_url: "https://api.example.com/voice/incoming"
分析ダッシュボード
SMS ANALYTICS - LAST 30 DAYS
═══════════════════════════════════════
VOLUME:
Sent: 45,230
Delivered: 43,456 (96.1%)
Failed: 1,774 (3.9%)
BY TYPE:
Notifications ████████████░░░░ 62%
Marketing ██████░░░░░░░░░░ 23%
2FA ████░░░░░░░░░░░░ 15%
DELIVERY BY CARRIER:
Verizon ████████████████ 97%
AT&T ███████████████░ 95%
T-Mobile ██████████████░░ 94%
Sprint █████████████░░░ 92%
COST:
Total Spend: $1,245.67
Per Message: $0.0275
Per Delivered: $0.0287
ENGAGEMENT:
Link Clicks: 3,456 (7.9%)
Replies: 892 (2.1%)
Opt-outs: 56 (0.1%)
API の例
SMS の送信
// Simple SMS
const message = await twilio.messages.create({
body: 'Hello from Twilio!',
from: '+1234567890',
to: '+0987654321',
statusCallback: 'https://api.example.com/sms/status'
});
// With Messaging Service (recommended for scale)
const message = await twilio.messages.create({
body: 'Order confirmed!',
messagingServiceSid: 'MG...',
to: '+0987654321'
});
// MMS with Media
const mms = await twilio.messages.create({
body: 'Check out this image!',
from: '+1234567890',
to: '+0987654321',
mediaUrl: ['https://example.com/image.jpg']
});
SMS の受信処理
// Express webhook handler
app.post('/sms/incoming', (req, res) => {
const { From, Body } = req.body;
const twiml = new twilio.twiml.MessagingResponse();
if (Body.toUpperCase() === 'STATUS') {
twiml.message('Your order is on the way!');
} else {
twiml.message('Thanks for your message. We\'ll respond shortly.');
}
res.type('text/xml');
res.send(twiml.toString());
});
ベストプラクティス
- 同意を得る:メッセージを送信する前に、必ずオプトインを得てください
- オプトアウト方法を含める:すべてのメッセージに STOP キーワードを記載してください
- 静穏時間を尊重する:深夜にメッセージを送らないでください
- 電話番号を検証する:送信前に Lookup API を使用してください
- 失敗に対処する:一時的なエラーには再試行ロジックを使用してください
- 配信状況を監視する:キャリアごとの配信率を追跡してください
- コンプライアンスを遵守する:TCPA/CTIA のガイドラインに従ってください
- テンプレートを使用する:一貫性があり、テスト済みのメッセージを使用してください
コメント
Markdown 対応