Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
fix: Twilio API calls random issues with asyncio
Clémence Lesnéaaab29f2ca1e
diff --git a/persistence/twilio.py b/persistence/twilio.pyindex 100932f..aa79132 100644--- a/persistence/twilio.py+++ b/persistence/twilio.py@@ -4,7 +4,6 @@ from helpers.pydantic_types.phone_numbers import PhoneNumberfrom models.readiness import ReadinessStatusfrom persistence.isms import ISmsfrom twilio.base.exceptions import TwilioRestException-from twilio.http.async_http_client import AsyncTwilioHttpClientfrom twilio.rest import Client@@ -19,10 +18,9 @@ class TwilioSms(ISms):_logger.info(f"Using Twilio from number {config.phone_number}")self._config = configself._client = Client(- http_client=AsyncTwilioHttpClient(),password=config.auth_token.get_secret_value(),username=config.account_sid,- )+ ) # TODO: Use async client, but get multiple "attached to a different loop" errors with AsyncTwilioHttpClientasync def areadiness(self) -> ReadinessStatus:"""@@ -32,8 +30,8 @@ class TwilioSms(ISms):"""account_sid = self._config.account_sidtry:- account = await self._client.api.accounts(account_sid).fetch_async()- balance = await account.balance.fetch_async()+ account = self._client.api.accounts(account_sid).fetch()+ balance = account.balance.fetch()assert balance.balance and float(balance.balance) > 0return ReadinessStatus.OKexcept AssertionError:@@ -45,7 +43,7 @@ class TwilioSms(ISms):success = False_logger.info(f"SMS content: {content}")try:- res = await self._client.messages.create_async(+ res = self._client.messages.create(body=content,from_=str(self._config.phone_number),to=str(phone_number),