messaging-services-reference
Skill2 starsChanged 8 months agoMITView on GitHub
Twilio development skill: messaging-services-reference
In this repository66 other files it gives its agents.
- adversarial-reviewSkill
- agent-connectSkill
- agent-teams-guideSkill
- agent-testingSkill
- android-sdkSkill
- brainstormSkill
- branded-callingSkill
- callbacksSkill
- compliance-regulatorySkill
- conferenceSkill
- context-engineeringSkill
- context-hubSkill
- conversational-intelligenceSkill
- conversation-relay-referenceSkill
- conversation-relaySkill
- conversationrelaySkill
- conversations-v2Skill
- customer-memorySkill
- deepgramSkill
- deep-validationSkill
- elastic-sip-trunkingSkill
- env-doctorSkill
- event-streamsSkill
- getting-startedSkill
- hooks-referenceSkill
- iamSkill
- ios-sdkSkill
- ivr-crawlerSkill
- ivr-migratorSkill
- lookupSkill
- media-streamsSkill
- memory-systemsSkill
- messaging-servicesSkill
- messagingSkill
- multi-agent-patternsSkill
- operational-gotchasSkill
- paymentsSkill
- paySkill
- phone-numbersSkill
- proxySkill
- real-time-transcriptionSkill
- recordingsSkill
- segmentSkill
- sendgrid-emailSkill
- sip-byocSkill
- sipSkill
- sync-referenceSkill
- syncSkill
- taskrouter-referenceSkill
- taskrouterSkill
- tdd-workflowSkill
- tool-boundariesSkill
- twilio-cliSkill
- twilio-invariantsSkill
- verify-referenceSkill
- verifySkill
- video-patternsSkill
- videoSkill
- voice-insightsSkill
- voice-referenceSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 264
Test numbers: +15005550006 (success), +15005550001 (invalid).
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- ABOUTME: Complete Messaging Services API reference, sender pool management, and common patterns. --><!-- ABOUTME: Companion to CLAUDE.md — contains full code samples, service features, and testing guides. -->Messaging Services Reference
For essential patterns, gotchas, and quick reference, see CLAUDE.md.
Key Difference: from vs messagingServiceSid
// Basic SMS - specify sender number
await client.messages.create({
to: '+1234567890',
from: '+0987654321',
body: 'Hello!'
});
// Messaging Service - let Twilio pick optimal sender
await client.messages.create({
to: '+1234567890',
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: 'Hello!'
});API Examples
Sending Messages
const client = context.getTwilioClient();
// Basic send
const message = await client.messages.create({
to: '+1234567890',
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: 'Your order has shipped!'
});
// With media (MMS)
const message = await client.messages.create({
to: '+1234567890',
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: 'Check out this image!',
mediaUrl: ['https://example.com/image.jpg']
});
// With status callback
const message = await client.messages.create({
to: '+1234567890',
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: 'Tracking delivery...',
statusCallback: 'https://your-app.com/status'
});
// Schedule message (up to 7 days in advance)
const message = await client.messages.create({
to: '+1234567890',
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: 'Scheduled reminder!',
scheduleType: 'fixed',
sendAt: new Date(Date.now() + 3600000).toISOString()
});Managing Sender Pool
// List phone numbers in the service
const phoneNumbers = await client.messaging.v1
.services(context.TWILIO_MESSAGING_SERVICE_SID)
.phoneNumbers.list();
// Add phone number to service
await client.messaging.v1
.services(context.TWILIO_MESSAGING_SERVICE_SID)
.phoneNumbers.create({
phoneNumberSid: 'PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});
// Remove phone number from service
await client.messaging.v1
.services(context.TWILIO_MESSAGING_SERVICE_SID)
.phoneNumbers(phoneNumberSid).remove();Service Configuration
// Get service details
const service = await client.messaging.v1
.services(context.TWILIO_MESSAGING_SERVICE_SID).fetch();
// Update service settings
await client.messaging.v1
.services(context.TWILIO_MESSAGING_SERVICE_SID).update({
stickySender: true,
mmsConverter: true,
smartEncoding: true,
fallbackUrl: 'https://fallback.example.com/sms',
inboundRequestUrl: 'https://your-app.com/incoming',
statusCallback: 'https://your-app.com/status'
});Service Features
Sticky Sender
Maintains consistent sender number per recipient. Config: { "stickySender": true }.
Geographic Matching
Selects sender number closest to recipient. Config: { "areaCodeGeomatch": true }.
MMS Conversion
Auto-converts MMS to SMS with link for unsupported carriers. Config: { "mmsConverter": true }.
Smart Encoding
Converts special characters to GSM-compatible equivalents, reducing segments and cost. Config: { "smartEncoding": true }.
Link Shortening
Track link clicks with branded short links:
const message = await client.messages.create({
to: '+1234567890',
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: 'Check out our sale: https://example.com/big-sale-promo-2024',
shortenUrls: true
});
// Results in: "Check out our sale: https://twil.io/abc123"A2P 10DLC Registration
// Check registration status
const brandRegistration = await client.messaging.v1
.brandRegistrations(brandSid).fetch();
const campaignRegistration = await client.messaging.v1
.services(serviceSid)
.usAppToPersonUsecases.list();Common Patterns
High-Volume Notifications
exports.handler = async (context, event, callback) => {
const client = context.getTwilioClient();
const { recipients, message } = event;
const results = await Promise.allSettled(
recipients.map(recipient =>
client.messages.create({
to: recipient,
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: message
})
)
);
const sent = results.filter(r => r.status === 'fulfilled').length;
const failed = results.filter(r => r.status === 'rejected').length;
return callback(null, { sent, failed, total: recipients.length });
};Opt-Out Handling
Twilio auto-handles STOP, STOPALL, UNSUBSCRIBE, CANCEL, END, QUIT (never reaches webhook).
exports.handler = async (context, event, callback) => {
const twiml = new Twilio.twiml.MessagingResponse();
if (event.Body.toUpperCase() === 'HELP') {
twiml.message('Reply STOP to unsubscribe. For support: support@example.com');
return callback(null, twiml);
}
twiml.message('Thanks for your message!');
return callback(null, twiml);
};Status Tracking
exports.handler = async (context, event, callback) => {
const { MessageSid, MessageStatus, ErrorCode, ErrorMessage } = event;
console.log(`Message ${MessageSid}: ${MessageStatus}`);
if (MessageStatus === 'failed' || MessageStatus === 'undelivered') {
console.log(`Delivery failed: ${ErrorCode} - ${ErrorMessage}`);
}
return callback(null, { success: true });
};Scheduled Campaigns
exports.handler = async (context, event, callback) => {
const client = context.getTwilioClient();
const { recipients, message, sendAt } = event;
const scheduledTime = new Date(sendAt);
const maxTime = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
if (scheduledTime > maxTime) {
return callback(null, { success: false, error: 'Max 7 days in advance' });
}
const results = await Promise.allSettled(
recipients.map(recipient =>
client.messages.create({
to: recipient,
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: message,
scheduleType: 'fixed',
sendAt: scheduledTime.toISOString()
})
)
);
return callback(null, {
scheduled: results.filter(r => r.status === 'fulfilled').length,
failed: results.filter(r => r.status === 'rejected').length
});
};Error Handling Pattern
exports.handler = async (context, event, callback) => {
const client = context.getTwilioClient();
try {
const message = await client.messages.create({
to: event.to,
messagingServiceSid: context.TWILIO_MESSAGING_SERVICE_SID,
body: event.body
});
return callback(null, { success: true, sid: message.sid });
} catch (error) {
if (error.code === 21610) {
return callback(null, { success: false, error: 'Recipient has opted out' });
}
if (error.code === 21611) {
return callback(null, { success: false, error: 'No numbers in sender pool' });
}
if (error.code === 30004) {
return callback(null, { success: false, error: 'Blocked by carrier' });
}
throw error;
}
};Testing
Test numbers: +15005550006 (success), +15005550001 (invalid).
describe('Messaging Service', () => {
it('should send message via messaging service', async () => {
const context = createTestContext();
const event = { to: '+15005550006', body: 'Test message' };
await sendHandler(context, event, callback);
const [, response] = callback.mock.calls[0];
expect(response.success).toBe(true);
expect(response.sid).toMatch(/^SM/);
});
});Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

