twilio
Twilioは、SMSや電話、WhatsAppメッセージの送受信、二段階認証、IVRシステム構築など、アプリにコミュニケーション機能を組み込む際に役立つSkill。
📜 元の英語説明(参考)
Add SMS, voice calls, and WhatsApp messaging with Twilio. Use when a user asks to send SMS messages, make phone calls programmatically, add two-factor authentication via SMS, send WhatsApp messages, build an IVR system, set up phone number verification, receive incoming SMS, or build communication features into an app. Covers SMS, MMS, WhatsApp, Verify API (2FA), voice calls, and webhooks.
🇯🇵 日本人クリエイター向け解説
Twilioは、SMSや電話、WhatsAppメッセージの送受信、二段階認証、IVRシステム構築など、アプリにコミュニケーション機能を組み込む際に役立つSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o twilio.zip https://jpskill.com/download/15504.zip && unzip -o twilio.zip && rm twilio.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15504.zip -OutFile "$d\twilio.zip"; Expand-Archive "$d\twilio.zip" -DestinationPath $d -Force; ri "$d\twilio.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
twilio.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
twilioフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Twilio
概要
Twilio は、業界をリードするクラウドコミュニケーションプラットフォームです。このスキルでは、SMS/MMS メッセージの送信、WhatsApp メッセージング、二要素認証 (Verify API)、音声通話、および Webhook を介した着信メッセージの処理について説明します。Twilio は 100 以上の国で電話番号を提供し、キャリアレベルの複雑さを処理するため、シンプルな API を使用できます。
手順
ステップ 1: セットアップ
# Node.js
npm install twilio
# Python
pip install twilio
// lib/twilio.ts — クライアントの初期化
import twilio from 'twilio'
const client = twilio(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_AUTH_TOKEN
)
ステップ 2: SMS の送信
// sms.ts — SMS メッセージの送受信
import twilio from 'twilio'
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN)
// SMS の送信
const message = await client.messages.create({
body: 'ご注文 #1234 が発送されました! こちらで追跡してください: https://track.example.com/1234',
from: process.env.TWILIO_PHONE_NUMBER, // あなたの Twilio 番号
to: '+15551234567', // 受信者 (E.164 形式)
})
console.log(message.sid) // SM1234567890abcdef
// MMS (画像付き) の送信
await client.messages.create({
body: 'この写真を見てください!',
from: process.env.TWILIO_PHONE_NUMBER,
to: '+15551234567',
mediaUrl: ['https://example.com/photo.jpg'],
})
ステップ 3: 二要素認証 (Verify API)
// lib/verify.ts — 電話番号の検証 / 2FA
// Twilio Verify を使用 — コードの生成、配信、検証を処理
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN)
const VERIFY_SERVICE_SID = process.env.TWILIO_VERIFY_SERVICE_SID! // Twilio コンソールで作成
export async function sendVerificationCode(phoneNumber: string) {
/**
* 6 桁の認証コードを SMS で送信します。
* Twilio は、コードの生成、有効期限 (10 分)、およびレート制限を処理します。
*/
const verification = await client.verify.v2
.services(VERIFY_SERVICE_SID)
.verifications.create({
to: phoneNumber,
channel: 'sms', // または 'call', 'email', 'whatsapp'
})
return verification.status // 'pending'
}
export async function checkVerificationCode(phoneNumber: string, code: string) {
/**
* ユーザーが入力したコードを検証します。
* 正しい場合は 'approved'、間違っている場合は 'pending' を返します。
*/
const check = await client.verify.v2
.services(VERIFY_SERVICE_SID)
.verificationChecks.create({
to: phoneNumber,
code,
})
return check.status // 'approved' または 'pending'
}
ステップ 4: WhatsApp メッセージング
// whatsapp.ts — Twilio 経由で WhatsApp メッセージを送信
// Twilio コンソールで WhatsApp Business API のセットアップが必要
await client.messages.create({
body: '明日の午後 2 時に予約が確定しました。',
from: 'whatsapp:+14155238886', // Twilio WhatsApp サンドボックス番号
to: 'whatsapp:+15551234567',
})
// WhatsApp とテンプレート (会話を開始するために必要)
await client.messages.create({
from: 'whatsapp:+14155238886',
to: 'whatsapp:+15551234567',
contentSid: 'HXb5b62575e6e4ff6129ad7c8efe1f983e', // 承認済みテンプレート SID
contentVariables: JSON.stringify({ '1': 'John', '2': 'March 15' }),
})
ステップ 5: 着信メッセージの受信 (Webhook)
// app/api/webhooks/twilio/route.ts — 着信 SMS/WhatsApp メッセージの処理
import { NextRequest, NextResponse } from 'next/server'
import twilio from 'twilio'
const { MessagingResponse } = twilio.twiml
export async function POST(req: NextRequest) {
const formData = await req.formData()
const from = formData.get('From') as string
const body = formData.get('Body') as string
const messageSid = formData.get('MessageSid') as string
console.log(`Incoming from ${from}: ${body}`)
// TwiML で自動返信
const response = new MessagingResponse()
if (body.toLowerCase().includes('status')) {
response.message('ご注文は発送準備中です! 配達予定日: 明日')
} else if (body.toLowerCase().includes('help')) {
response.message('利用可能なコマンド: STATUS, HELP, CANCEL')
} else {
response.message('メッセージありがとうございます! オプションについては HELP と返信してください。')
}
return new NextResponse(response.toString(), {
headers: { 'Content-Type': 'text/xml' },
})
}
ステップ 6: 音声通話
// voice.ts — 自動電話をかける
// TwiML は通話中に何が起こるかを制御します
await client.calls.create({
url: 'https://myapp.com/api/voice/greeting', // TwiML エンドポイント
from: process.env.TWILIO_PHONE_NUMBER!,
to: '+15551234567',
})
// 音声 Webhook エンドポイント
// app/api/voice/greeting/route.ts
import twilio from 'twilio'
const { VoiceResponse } = twilio.twiml
export async function POST() {
const response = new VoiceResponse()
response.say({ voice: 'alice' }, 'こんにちは! 明日の午後 2 時に予約が確定しました。')
response.say('確認するには 1 を、再スケジュールするには 2 を押してください。')
const gather = response.gather({ numDigits: 1, action: '/api/voice/handle-input' })
gather.say('選択してください。')
return new Response(response.toString(), {
headers: { 'Content-Type': 'text/xml' },
})
}
例
例 1: SMS ベースの 2FA をログインフローに追加する
ユーザープロンプト: 「サインアップフローに電話番号の検証を追加してください。ユーザーが電話番号を入力し、コードを受信して検証します。」
エージェントは以下を行います。
- コンソールで Twilio Verify サービスを作成します。
- API エンドポイント
/api/verify/sendおよび/api/verify/checkを構築します。 - フロントエンドフロー: 電話入力 → コード送信 → コード入力 → 検証。
- エッジケースを処理します: レート制限、期限切れのコード、無効な番号。
例 2: 注文通知システムを構築する
ユーザープロンプト: 「注文が発送されたときに顧客に SMS を送信し、配達されたときに WhatsApp メッセージを送信します。追跡リンクを含めてください。」
エージェントは以下を行います。
- SMS および WhatsApp メッセージングチャネルを設定します。
- 注文ステータスの変更によってトリガーされる通知関数を作成します。
- Wh
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Twilio
Overview
Twilio is the leading cloud communications platform. This skill covers sending SMS/MMS messages, WhatsApp messaging, two-factor authentication (Verify API), voice calls, and handling incoming messages via webhooks. Twilio provides phone numbers in 100+ countries and handles carrier-level complexity so you work with a simple API.
Instructions
Step 1: Setup
# Node.js
npm install twilio
# Python
pip install twilio
// lib/twilio.ts — Client initialization
import twilio from 'twilio'
const client = twilio(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_AUTH_TOKEN
)
Step 2: Send SMS
// sms.ts — Send and receive SMS messages
import twilio from 'twilio'
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN)
// Send SMS
const message = await client.messages.create({
body: 'Your order #1234 has shipped! Track it at: https://track.example.com/1234',
from: process.env.TWILIO_PHONE_NUMBER, // your Twilio number
to: '+15551234567', // recipient (E.164 format)
})
console.log(message.sid) // SM1234567890abcdef
// Send MMS (with image)
await client.messages.create({
body: 'Check out this photo!',
from: process.env.TWILIO_PHONE_NUMBER,
to: '+15551234567',
mediaUrl: ['https://example.com/photo.jpg'],
})
Step 3: Two-Factor Authentication (Verify API)
// lib/verify.ts — Phone number verification / 2FA
// Uses Twilio Verify — handles code generation, delivery, and validation
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN)
const VERIFY_SERVICE_SID = process.env.TWILIO_VERIFY_SERVICE_SID! // create in Twilio console
export async function sendVerificationCode(phoneNumber: string) {
/**
* Send a 6-digit verification code via SMS.
* Twilio handles code generation, expiry (10 min), and rate limiting.
*/
const verification = await client.verify.v2
.services(VERIFY_SERVICE_SID)
.verifications.create({
to: phoneNumber,
channel: 'sms', // or 'call', 'email', 'whatsapp'
})
return verification.status // 'pending'
}
export async function checkVerificationCode(phoneNumber: string, code: string) {
/**
* Verify a code entered by the user.
* Returns 'approved' if correct, 'pending' if wrong.
*/
const check = await client.verify.v2
.services(VERIFY_SERVICE_SID)
.verificationChecks.create({
to: phoneNumber,
code,
})
return check.status // 'approved' or 'pending'
}
Step 4: WhatsApp Messaging
// whatsapp.ts — Send WhatsApp messages via Twilio
// Requires WhatsApp Business API setup in Twilio console
await client.messages.create({
body: 'Your appointment is confirmed for tomorrow at 2 PM.',
from: 'whatsapp:+14155238886', // Twilio WhatsApp sandbox number
to: 'whatsapp:+15551234567',
})
// WhatsApp with template (required for initiating conversations)
await client.messages.create({
from: 'whatsapp:+14155238886',
to: 'whatsapp:+15551234567',
contentSid: 'HXb5b62575e6e4ff6129ad7c8efe1f983e', // approved template SID
contentVariables: JSON.stringify({ '1': 'John', '2': 'March 15' }),
})
Step 5: Receive Incoming Messages (Webhooks)
// app/api/webhooks/twilio/route.ts — Handle incoming SMS/WhatsApp messages
import { NextRequest, NextResponse } from 'next/server'
import twilio from 'twilio'
const { MessagingResponse } = twilio.twiml
export async function POST(req: NextRequest) {
const formData = await req.formData()
const from = formData.get('From') as string
const body = formData.get('Body') as string
const messageSid = formData.get('MessageSid') as string
console.log(`Incoming from ${from}: ${body}`)
// Auto-reply with TwiML
const response = new MessagingResponse()
if (body.toLowerCase().includes('status')) {
response.message('Your order is on its way! Expected delivery: tomorrow.')
} else if (body.toLowerCase().includes('help')) {
response.message('Available commands: STATUS, HELP, CANCEL')
} else {
response.message('Thanks for your message! Reply HELP for options.')
}
return new NextResponse(response.toString(), {
headers: { 'Content-Type': 'text/xml' },
})
}
Step 6: Voice Calls
// voice.ts — Make automated phone calls
// TwiML controls what happens during the call
await client.calls.create({
url: 'https://myapp.com/api/voice/greeting', // TwiML endpoint
from: process.env.TWILIO_PHONE_NUMBER!,
to: '+15551234567',
})
// Voice webhook endpoint
// app/api/voice/greeting/route.ts
import twilio from 'twilio'
const { VoiceResponse } = twilio.twiml
export async function POST() {
const response = new VoiceResponse()
response.say({ voice: 'alice' }, 'Hello! Your appointment is confirmed for tomorrow at 2 PM.')
response.say('Press 1 to confirm, or 2 to reschedule.')
const gather = response.gather({ numDigits: 1, action: '/api/voice/handle-input' })
gather.say('Please make your selection.')
return new Response(response.toString(), {
headers: { 'Content-Type': 'text/xml' },
})
}
Examples
Example 1: Add SMS-based 2FA to a login flow
User prompt: "Add phone number verification to our signup flow. Users enter their phone number, receive a code, and verify it."
The agent will:
- Create a Twilio Verify service in the console.
- Build API endpoints:
/api/verify/sendand/api/verify/check. - Frontend flow: phone input → send code → code input → verify.
- Handle edge cases: rate limiting, expired codes, invalid numbers.
Example 2: Build an order notification system
User prompt: "Send customers an SMS when their order ships, and a WhatsApp message when it's delivered. Include tracking link."
The agent will:
- Set up SMS and WhatsApp messaging channels.
- Create notification functions triggered by order status changes.
- Use WhatsApp templates (required for business-initiated messages).
- Handle delivery status callbacks via webhooks.
Guidelines
- Use E.164 format for all phone numbers (
+15551234567, not555-123-4567). Twilio rejects incorrectly formatted numbers. - Use the Verify API for 2FA instead of sending raw SMS codes — it handles code generation, expiry, rate limiting, and fraud detection.
- WhatsApp requires pre-approved message templates for business-initiated conversations. User-initiated conversations (replies within 24h) allow freeform messages.
- Always validate webhook requests using Twilio's signature validation to prevent forged webhooks.
- SMS costs vary by country — US SMS costs ~$0.0079/message, international can be 10-50x more. Use WhatsApp for international messaging when possible (often cheaper).
- Set up a status callback URL to track message delivery. Not all SMS messages are delivered — carriers can silently drop them.