Skip to content

The agent that grows with you

fix(sms): a non-string or blank standalone-send key fails closed instead of raising

kshitijk4pooradf4a4b48cf9
diff --git a/plugins/platforms/sms/adapter.py b/plugins/platforms/sms/adapter.py
index 82f86307257..729a27df78a 100644
--- a/plugins/platforms/sms/adapter.py
+++ b/plugins/platforms/sms/adapter.py
@@ -302,7 +302,7 @@ def _strip_markdown_for_sms(message: str) -> str:
async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_files=None, force_document=False):
"""Out-of-process SMS delivery via the Twilio REST API (standalone_sender_fn contract)."""
- auth_token = (getattr(pconfig, "api_key", None) or _get_scoped_secret("TWILIO_AUTH_TOKEN", "")).strip()
+ auth_token = str(getattr(pconfig, "api_key", None) or _get_scoped_secret("TWILIO_AUTH_TOKEN", "") or "").strip()
if not AIOHTTP_AVAILABLE:
return send_error("aiohttp not installed. Run: pip install aiohttp")
account_sid = _get_scoped_secret("TWILIO_ACCOUNT_SID", "")
diff --git a/tests/gateway/test_sms.py b/tests/gateway/test_sms.py
index 7312224a58e..ea6f00cd204 100644
--- a/tests/gateway/test_sms.py
+++ b/tests/gateway/test_sms.py
@@ -319,6 +319,20 @@ class TestMultiplexProfileScope:
reset_secret_scope(token)
assert "TWILIO_PHONE_NUMBER required" in result["error"]
+ @pytest.mark.asyncio
+ async def test_standalone_send_with_a_non_string_or_blank_key_fails_closed(self):
+ """A YAML int api_key must not raise, and a blank one must not reach Twilio."""
+ from plugins.platforms.sms.adapter import _standalone_send
+
+ env = {"TWILIO_ACCOUNT_SID": "ACtest", "TWILIO_AUTH_TOKEN": "", "TWILIO_PHONE_NUMBER": "+15550001111"}
+ with patch.dict(os.environ, env):
+ result = await _standalone_send(PlatformConfig(enabled=True, api_key=" "), "+15550002222", "hi")
+ assert "not configured" in result["error"]
+ env["TWILIO_ACCOUNT_SID"] = "" # keep the int case off the network
+ with patch.dict(os.environ, env):
+ result = await _standalone_send(PlatformConfig(enabled=True, api_key=123), "+15550002222", "hi")
+ assert "not configured" in result["error"]
+
@pytest.mark.asyncio
async def test_oversized_cron_output_reaches_twilio_in_1600_char_chunks():