vocodedev / vocode-core

🤖 Build voice-based LLM agents. Modular + open source.
https://vocode.dev
MIT License
2.8k stars 475 forks source link

Twilio "create call" options not accessible through Vocode #251

Closed Einsight04 closed 1 year ago

Einsight04 commented 1 year ago

When creating a call with vocode we can only customize the following attributes:

to_phone=self.to_phone,
from_phone=self.from_phone,
record=self.telephony_client.get_telephony_config().record,
digits=self.digits,

But Twillio allows for much more customization that Vocode misses out on.

Current TwilioConfig:

class TwilioConfig(BaseModel):
    account_sid: str
    auth_token: str
    record: bool = False

Propsed TwilioConfig:

class TwilioConfig(BaseModel):
    account_sid: str
    auth_token: str
    record: bool = False
    recording_channels: Optional[str] = None
    recording_status_callback: Optional[str] = None
    recording_status_callback_method: Optional[str] = None
    method: Optional[str] = None
    fallback_url: Optional[str] = None
    fallback_method: Optional[str] = None
    status_callback: Optional[str] = None
    status_callback_event: Optional[list[str]] = None
    status_callback_method: Optional[str] = None
    timeout: Optional[int] = None
    sip_auth_username: Optional[str] = None
    sip_auth_password: Optional[str] = None
    machine_detection: Optional[str] = None
    machine_detection_timeout: Optional[int] = None
    recording_status_callback_event: Optional[list[str]] = None
    trim: Optional[str] = None
    caller_id: Optional[str] = None
    machine_detection_speech_threshold: Optional[int] = None
    machine_detection_speech_end_threshold: Optional[int] = None
    machine_detection_silence_timeout: Optional[int] = None
    async_amd: Optional[str] = None
    async_amd_status_callback: Optional[str] = None
    async_amd_status_callback_method: Optional[str] = None
    byoc: Optional[str] = None
    call_reason: Optional[str] = None
    call_token: Optional[str] = None
    recording_track: Optional[str] = None
    time_limit: Optional[int] = None
    twiml: Optional[str] = None
    application_sid: Optional[str] = None

Putting this into use only requires updating the parameters passed into Twillio's create() method and is overall a very minor yet impactful change.

ajar98 commented 1 year ago

agreed it would be nice to support all of these parameters - can we achieve this with a **kwargs somewhere instead? don't want to bloat TwilioConfig

Einsight04 commented 1 year ago

agreed it would be nice to support all of these parameters - can we achieve this with a **kwargs somewhere instead? don't want to bloat TwilioConfig

Although **kwargs are indeed possible when using Pydantic, it's worth noting that static type checkers like Pylance will continue to flag extra parameters that are not explicitly declared in the model.

By declaring optional parameters directly in the TwilioConfig model, we can avoid these warnings and also benefit from auto-completion.

If we still want to lessen the bloat, we can consider having an extra parameter in the model that accepts a dictionary for any additional fields. Like so:

class TwilioConfig(BaseModel):
    account_sid: str
    auth_token: str
    record: bool = False
    extra: Optional[Dict[str, Any]] = None

This keeps the model's interface clean and allows some degree of flexibility, while still benefiting from Pydantic's validation for the main fields.

Let me know how you'd like to approach this and ill pr.

Kian1354 commented 1 year ago

@Einsight04 i'm ok with either approach (as long as the vars are kept in a dict)

looks like @KShah707 took a stab at this in #271 – happy to merge once ready!

KShah707 commented 1 year ago

This 'extra' method seems nice, decouples the Vocode library from minor changes in the underlying Twilio api (as we don't need to update TwilioConfig if fields change). I think it's the best compromise but will sleep on it

Einsight04 commented 1 year ago

Duplicate merged in #274