proomt

Search

Search posts, papers, and topics

All posts

TwilioAmanda Lange, Matthew Setter11 min readtutorialintermediate

How to Connect Your Twilio Agent to External APIs with PHP

Summary

A step‑by‑step tutorial showing how to build a Twilio voice agent in PHP (using OpenSwoole) that calls OpenAI’s gpt‑4o‑mini model and can invoke an external REST API (Cat Facts) via tool‑calling, wiring everything together with Twilio Conversation Relay and a WebSocket server.

  • Set up a PHP 8.5+ project with Composer and install openai‑php/client, guzzlehttp/guzzle, vlucas/phpdotenv, and twilio/sdk.
  • Use a .env file for the OpenAI API key and server host/port.
  • Run an OpenSwoole WebSocket server (Swoole\\WebSocket\Server) that serves a TwiML endpoint at /voice, which returns a <Connect><ConversationRelay> pointing to the WS endpoint.
  • ConversationRelayHandler manages per‑connection state, handling setup, prompt, interrupt, and error messages from Twilio’s Conversation Relay.

Shows a concrete integration pattern for voice‑first LLM agents that need real‑time data, combining Twilio Conversation Relay, a coroutine‑based PHP server, and OpenAI function calling. The code is complete and runnable, making it a useful reference for engineers building similar voice‑AI products.

6/10

Related reading

  1. On-Demand Masked Sessions with Twilio Proxy, Voice and Serverless

    A step‑by‑step tutorial showing how to build a Just‑in‑Time masked‑call workflow with Twilio Voice, Proxy, and Sync, using a two‑bounce out‑of‑session pattern to collect a tracking code via IVR, resolve the counterpart’s number, stash it in Sync, and auto‑create a Proxy session on the fly—all deployed as Twilio Serverless Functions.

    Twiliotwilio.com18 min
  2. 9 top conversational AI platforms in 2026

    Twilio’s blog lists the nine leading conversational‑AI platforms for 2026, highlighting how the market consolidated and what capabilities matter when choosing a vendor. It details Twilio’s own infrastructure tools—ConversationRelay, Agent Connect, Orchestrator, and Memory—showing sub‑second latency and full‑stack reliability for voice and messaging.

    Twiliotwilio.com12 min
  3. Building Sentry's Laravel AI Integration

    Sentry added zero‑config Agent Tracing for Laravel AI agents. The integration hooks into Laravel AI events and HTTP request events to create Chat spans for each LLM call, matching requests by provider URL prefix. Updating to sentry‑laravel 4.27 automatically instruments agents without any user code changes.

    Sentrysentry.io4 min
  4. GPT-Live 1 now available on AI Gateway

    Vercel AI Gateway now offers OpenAI’s GPT‑Live 1, a full‑duplex voice model that can listen and speak simultaneously. The SDK lets you start a voice session and optionally delegate work to any text model, with code examples for both patterns.

    Vercelvercel.com1 minrelease
  5. Why client SDK generation belongs in the open

    Google partnered with Speakeasy to open‑source their OpenAPI‑based multi‑language SDK generator, covering Python, TypeScript, Go, Java, C#, PHP, and Ruby. The move replaces a now‑defunct proprietary generator, reduces maintenance overhead to ~1 engineer, and adds a CLI and documentation server generator under AGPLv3.

    Google Developersgoogleblog.com3 min