diff --git a/src/scitex/notify/README.md b/src/scitex/notify/README.md index 5f7d56c3..138f725c 100644 --- a/src/scitex/notify/README.md +++ b/src/scitex/notify/README.md @@ -1,6 +1,6 @@ # scitex.notify -Multi-backend notification system for SciTeX. Sends alerts via audio (TTS), phone calls (Twilio), email, desktop notifications, Emacs, browser popups, and webhooks. +Multi-backend notification system for SciTeX. Sends alerts via audio (TTS), phone calls (Twilio), SMS, email, desktop notifications, Emacs, browser popups, and webhooks. ## Quick Start @@ -13,6 +13,9 @@ scitex.notify.alert("Task complete!") # Phone call via Twilio scitex.notify.call("Wake up! Your experiment finished.") +# SMS via Twilio +scitex.notify.sms("Build finished!") + # Specify backend explicitly scitex.notify.alert("Error in pipeline", backend="email", level="error") @@ -29,7 +32,7 @@ scitex.notify.available_backends() | Backend | Description | Requirements | |---------|-------------|--------------| | `audio` | Text-to-Speech | `scitex-audio` package | -| `twilio` | Phone call | Twilio account + env vars | +| `twilio` | Phone call / SMS | Twilio account + env vars | | `email` | SMTP email | SMTP server config | | `emacs` | Minibuffer message | Running Emacs server | | `desktop` | System notification | Windows/macOS | @@ -71,6 +74,31 @@ To receive calls while in Do Not Disturb / silent mode: 2. **Settings -> Focus -> Do Not Disturb -> Allow Repeated Calls** -> ON 3. Use `repeat=2` -- the second call within 3 minutes bypasses silent mode +## SMS (Twilio) + +Uses the same Twilio env vars as phone calls. + +```python +import scitex + +# Simple SMS +scitex.notify.sms("Build finished!") + +# With title prefix +scitex.notify.sms("Pipeline error on node 3", title="SciTeX Alert") + +# Override destination +scitex.notify.sms("Urgent!", to_number="+61400000000") +``` + +CLI: + +```bash +scitex notify sms "Build finished!" +scitex notify sms "Alert!" --to +61400000000 +scitex notify sms "Error" --title "SciTeX" +``` + ## Configuration ### Environment Variables @@ -135,22 +163,43 @@ scitex.notify.call( **kwargs, ) -> bool +# Send SMS (no fallback) +scitex.notify.sms( + message: str, + title: str = None, # Prepended to message + to_number: str = None, # Override default + **kwargs, +) -> bool + # Async versions await scitex.notify.alert_async(...) await scitex.notify.call_async(...) +await scitex.notify.sms_async(...) # List available backends scitex.notify.available_backends() -> list[str] ``` +## CLI Commands + +```bash +scitex notify send "Task complete!" # Auto-fallback +scitex notify send "Error" --backend email --level error # Specific backend +scitex notify call "Wake up!" --repeat 2 # Phone call +scitex notify sms "Build finished!" # SMS +scitex notify backends # List backends +scitex notify config # Show config +scitex notify --help-recursive # All help +``` + ## MCP Tools Available via `scitex mcp serve`: | Tool | Description | |------|-------------| -| `notify` | Send notification via backend(s) | -| `notify_by_level` | Send using level-configured backends | -| `list_notification_backends` | List all backends and status | -| `available_notification_backends` | List working backends | -| `get_notification_config` | Get current configuration | +| `notify_send` | Send notification via backend(s) | +| `notify_call` | Make a phone call via Twilio | +| `notify_sms` | Send an SMS via Twilio | +| `notify_backends` | List all backends and availability | +| `notify_config` | Get current configuration | diff --git a/src/scitex/notify/__init__.py b/src/scitex/notify/__init__.py index b3e864fe..41c3076a 100755 --- a/src/scitex/notify/__init__.py +++ b/src/scitex/notify/__init__.py @@ -122,7 +122,7 @@ async def alert_async( if name not in available: continue try: - b = _get_backend(name, **kwargs) + b = _get_backend(name) result = await b.send(message, title=title, level=lvl, **kwargs) if result.success: return True diff --git a/src/scitex/notify/_backends/_twilio.py b/src/scitex/notify/_backends/_twilio.py index d61446af..da101bf6 100755 --- a/src/scitex/notify/_backends/_twilio.py +++ b/src/scitex/notify/_backends/_twilio.py @@ -58,10 +58,10 @@ async def send( **kwargs, ) -> NotifyResult: try: - to_number = kwargs.get("to_number", self.to_number) - from_number = kwargs.get("from_number", self.from_number) - flow_sid = kwargs.get("flow_sid", self.flow_sid) - repeat = kwargs.get("repeat", self.repeat) + to_number = kwargs.get("to_number") or self.to_number + from_number = kwargs.get("from_number") or self.from_number + flow_sid = kwargs.get("flow_sid") or self.flow_sid + repeat = kwargs.get("repeat") or self.repeat if not all([self.account_sid, self.auth_token, from_number, to_number]): raise ValueError(