-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance twilio plugin following coderabbit recommendations
- Loading branch information
Showing
56 changed files
with
5,427 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Required Twilio settings | ||
TWILIO_ACCOUNT_SID=your_account_sid | ||
TWILIO_AUTH_TOKEN=your_auth_token | ||
TWILIO_PHONE_NUMBER=your_twilio_phone_number | ||
TWILIO_CHARACTER=character.json | ||
|
||
# Required for voice features | ||
WEBHOOK_PORT=3004 | ||
WEBHOOK_BASE_URL=your_ngrok_url | ||
|
||
# Optional - for voice quality | ||
ELEVENLABS_XI_API_KEY=your_key | ||
|
||
# Optional ElevenLabs configuration | ||
# ELEVENLABS_MODEL_ID=eleven_monolingual_v1 | ||
# ELEVENLABS_VOICE_ID=your_voice_id | ||
# ELEVENLABS_VOICE_STABILITY=0.5 | ||
# ELEVENLABS_VOICE_SIMILARITY_BOOST=0.9 | ||
# ELEVENLABS_VOICE_STYLE=0.66 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist/ | ||
node_modules/ | ||
.turbo/ | ||
pnpm-lock.yaml | ||
docs/ | ||
../../characters/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# @elizaos/plugin-twilio | ||
|
||
A Twilio plugin for ElizaOS that enables SMS and voice call capabilities. | ||
|
||
## Features | ||
|
||
- 📱 SMS Messaging | ||
- Send SMS messages | ||
- Receive and respond to SMS messages | ||
- Natural conversation handling | ||
|
||
- 📞 Voice Calls | ||
- Make outgoing calls | ||
- Receive incoming calls | ||
- Natural voice conversations using ElevenLabs | ||
- Speech recognition and response | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @elizaos/plugin-twilio | ||
``` | ||
|
||
## Configuration | ||
|
||
1. Set up environment variables in your `.env` file: | ||
|
||
```env | ||
# Twilio Configuration | ||
TWILIO_ACCOUNT_SID=your_account_sid | ||
TWILIO_AUTH_TOKEN=your_auth_token | ||
TWILIO_PHONE_NUMBER=your_twilio_phone_number | ||
TWILIO_CHARACTER=character.json | ||
# Webhook Configuration | ||
WEBHOOK_PORT=3004 | ||
WEBHOOK_BASE_URL=your_webhook_url | ||
# ElevenLabs (for voice synthesis) | ||
ELEVENLABS_XI_API_KEY=your_elevenlabs_api_key | ||
``` | ||
|
||
2. Configure your character file to enable Twilio actions: | ||
|
||
```json | ||
{ | ||
"settings": { | ||
"actions": { | ||
"enabled": ["sms", "call"] | ||
}, | ||
"voice": { | ||
"elevenlabs": { | ||
"voiceId": "your_voice_id", | ||
"stability": 0.3, | ||
"similarityBoost": 0.5, | ||
"style": 0.5, | ||
"useSpeakerBoost": false | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
### Interacting with the Agent | ||
|
||
You can interact with the agent in two ways: | ||
|
||
#### Via SMS | ||
1. Save the Twilio phone number: {TWILIO_PHONE_NUMBER} | ||
2. Send a text message to start a conversation | ||
3. The agent will respond based on its character configuration | ||
4. Continue the natural conversation via SMS | ||
|
||
#### Via Voice Call | ||
1. Call the Twilio phone number: {TWILIO_PHONE_NUMBER} | ||
2. The agent will answer and start a conversation | ||
3. Speak naturally - the agent uses speech recognition | ||
4. The agent will respond with natural voice using ElevenLabs | ||
|
||
### Sending Messages Through the Agent | ||
|
||
Best Practices: | ||
1. For direct messages, use "saying" or "telling" | ||
2. For AI-generated content, use "about" | ||
3. Always include the full phone number with "+" prefix | ||
4. Keep messages concise (160 char limit) | ||
|
||
#### SMS Commands | ||
|
||
``` | ||
Send an SMS to +1234567890 saying Hello world! | ||
Send SMS to +1234567890 about the weather forecast | ||
``` | ||
|
||
#### Voice Call Commands | ||
|
||
``` | ||
Call +1234567890 and tell them about the latest updates | ||
Call +1234567890 to say that we need to schedule a meeting | ||
``` | ||
|
||
## Development | ||
|
||
```bash | ||
# Install dependencies | ||
npm install | ||
|
||
# Run tests | ||
npm test | ||
|
||
# Build the plugin | ||
npm run build | ||
``` | ||
|
||
## Webhook Setup | ||
|
||
For local development, use ngrok or similar to expose your webhook: | ||
|
||
```bash | ||
ngrok http 3004 | ||
``` | ||
|
||
Then update your `WEBHOOK_BASE_URL` in `.env` with the ngrok URL. | ||
|
||
## Notes | ||
|
||
- Voice calls require ElevenLabs API key for text-to-speech | ||
- Messages are limited to 160 characters for SMS | ||
- Voice responses are optimized for natural conversation flow | ||
- All phone numbers must be in international format (+1234567890) | ||
- The agent's responses are based on its configured character personality | ||
- Incoming messages and calls are handled automatically through webhooks | ||
|
||
## License | ||
|
||
MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "@elizaos/plugin-twilio", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"prebuild": "pnpm clean", | ||
"build": "tsx scripts/build.ts && tsc --emitDeclarationOnly --declaration", | ||
"dev": "tsc -w" | ||
}, | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"express": "^4.x.x", | ||
"twilio": "^4.x.x", | ||
"uuid": "^9.0.0", | ||
"elevenlabs-node": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.21", | ||
"@types/node": "^20.0.0", | ||
"@types/uuid": "^9.0.0", | ||
"esbuild": "^0.19.0", | ||
"glob": "^10.0.0", | ||
"rimraf": "^5.0.5", | ||
"tsx": "^4.7.0", | ||
"typescript": "^5.0.0", | ||
"@types/twilio": "^3.19.3", | ||
"vitest": "^1.0.0", | ||
"@vitest/coverage-v8": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { build } from 'esbuild'; | ||
import { glob } from 'glob'; | ||
import { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
async function buildPlugin() { | ||
console.log('🔍 Finding source files...'); | ||
const entryPoints = await glob('src/**/*.ts', { | ||
cwd: dirname(__dirname), | ||
absolute: true, | ||
}); | ||
console.log(`📁 Found ${entryPoints.length} files to build`); | ||
|
||
try { | ||
console.log('🚀 Starting build...'); | ||
await build({ | ||
entryPoints, | ||
outdir: 'dist', | ||
platform: 'node', | ||
format: 'esm', | ||
target: 'node18', | ||
bundle: true, | ||
sourcemap: true, | ||
external: [ | ||
'@elizaos/core', | ||
'twilio', | ||
'express', | ||
'uuid' | ||
], | ||
logLevel: 'info', | ||
mainFields: ['module', 'main'], | ||
banner: { | ||
js: '// @ts-check\n' | ||
}, | ||
outExtension: { '.js': '.js' } | ||
}); | ||
|
||
console.log('✅ Build completed successfully'); | ||
} catch (error) { | ||
console.error('❌ Build failed:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
buildPlugin().catch(err => { | ||
console.error('❌ Unhandled error:', err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"esModuleInterop": true, | ||
"outDir": "./dist", | ||
"rootDir": ".", | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"*.ts", | ||
"*.mts" | ||
], | ||
"exclude": [ | ||
"../src", | ||
"../dist", | ||
"../node_modules" | ||
] | ||
} |
Oops, something went wrong.