### Send SMS with Twilio SDK Source: https://github.com/twilio/twilio-php/blob/main/README.md Examples demonstrating how to initialize the Twilio client and send an SMS message. ```php // Send an SMS using Twilio's REST API and PHP messages->create( // The number you'd like to send the message to '+15558675309', [ // A Twilio phone number you purchased at https://console.twilio.com 'from' => '+15017250604', // The body of the text message you'd like to send 'body' => "Hey Jenny! Good luck on the bar exam!" ] ); ``` ```php messages->create( // The number you'd like to send the message to '+15558675309', [ // A Twilio phone number you purchased at https://console.twilio.com 'from' => '+15017250604', // The body of the text message you'd like to send 'body' => "Hey Jenny! Good luck on the bar exam!" ] ); ``` -------------------------------- ### Install Twilio SDK via Composer Source: https://github.com/twilio/twilio-php/blob/main/README.md Use this command to add the Twilio SDK as a dependency to your project. ```shell composer require twilio/sdk ``` -------------------------------- ### Configure Environment Variables for Proxy Source: https://github.com/twilio/twilio-php/blob/main/advanced-examples/custom-http-client.md Example configuration for an .env file to store Twilio credentials and proxy settings. ```env ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx AUTH_TOKEN= your_auth_token PROXY=127.0.0.1:8888 ``` -------------------------------- ### Send SMS with Twilio PHP (Default Client) Source: https://github.com/twilio/twilio-php/blob/main/advanced-examples/custom-http-client.md A basic example of sending an SMS message using the Twilio PHP Helper Library with its default HTTP client. ```php messages ->create( "+15558675310", array( 'body' => "Hey there!", 'from' => "+15017122661" ) ); ``` -------------------------------- ### Send SMS with Twilio PHP (Custom HTTP Client) Source: https://github.com/twilio/twilio-php/blob/main/advanced-examples/custom-http-client.md This example demonstrates sending an SMS message using a custom HTTP client, which is useful for configuring proxy authentication. Ensure you have a custom HTTP client class (e.g., MyRequestClass) and necessary environment variables set. ```php load(); use Twilio\Rest\Client; // Your Account Sid and Auth Token from twilio.com/console $sid = getenv('ACCOUNT_SID'); $token = getenv('AUTH_TOKEN'); $proxy = getenv('PROXY'); $httpClient = new MyRequestClass($proxy); $twilio = new Client($sid, $token, null, null, $httpClient); $message = $twilio->messages ->create( "+15558675310", array( 'body' => "Hey there!", 'from' => "+15017122661" ) ); print("Message SID: {$message->sid}"); ``` -------------------------------- ### Create a new git branch Source: https://github.com/twilio/twilio-php/blob/main/CONTRIBUTING.md Use this command to start a new feature or fix branch from the main branch. ```shell git checkout -b my-fix-branch main ``` -------------------------------- ### Memory API - Conversation Summaries Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Added patch and get methods for Conversation Summaries. ```APIDOC ## PATCH /v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId} ### Description Updates a conversation summary. ### Endpoint /v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId} ``` ```APIDOC ## GET /v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId} ### Description Retrieves a conversation summary. ### Endpoint /v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId} ``` -------------------------------- ### Listing Resources Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Use read() to return an array of instances or stream() to return an iterator for efficient paging. ```php $client->api->messages->read(); //=> [#, #, ...] ``` ```php foreach ($client->calls->stream() as $call) { print($call->sid); } ``` -------------------------------- ### Fetching Resource Instances Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Call fetch() on a context object to retrieve the actual instance with its properties. ```php $workspace = $client->taskrouter->workspaces('WSxxx') //=> $workspace->fetch(); //=> ``` -------------------------------- ### Initialize Twilio Client with Custom HttpClient Source: https://github.com/twilio/twilio-php/blob/main/advanced-examples/custom-http-client.md Loads environment variables and initializes the Twilio Client using the custom proxy-enabled HttpClient. ```php load(); use Twilio\Rest\Client; // Your Account Sid and Auth Token from twilio.com/console $sid = getenv('ACCOUNT_SID'); $token = getenv('AUTH_TOKEN'); $proxy = getenv('PROXY'); $httpClient = new MyRequestClass($proxy); $twilio = new Client($sid, $token, null, null, $httpClient); $message = $twilio->messages ->create( "+15558675310", array( 'body' => "Hey there!", 'from' => "+15017122661" ) ); print("Message SID: {$message->sid}"); ``` -------------------------------- ### Creating Resources with Consistent Arguments Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Use positional arguments for required parameters and an array for optional parameters. ```php $message = $client->messages->create( '+12335554444', array( 'from' => '+13344445555', 'body' => 'hello' ) ); ``` -------------------------------- ### Get an Existing Call with Twilio PHP Source: https://github.com/twilio/twilio-php/blob/main/README.md Retrieves details of a specific call using its Call SID. Ensure the Twilio autoloader is included. The fetched call object's properties, like 'to', can then be accessed. ```php calls("CA42ed11f93dc08b952027ffbc406d0868")->fetch(); print $call->to; ``` -------------------------------- ### Handle EnvironmentException for CurlClient in PHP Source: https://github.com/twilio/twilio-php/blob/main/README.md Catch errors related to missing curl dependencies when initializing the HTTP client. ```php options( 'GET', 'http://api.twilio.com', array(), array(), array(), $sid, $token ); } catch (EnvironmentException $e) { print $e->getCode(); } print $call->to; ``` -------------------------------- ### Handle ConfigurationException in PHP Source: https://github.com/twilio/twilio-php/blob/main/README.md Catch authentication or configuration errors during Twilio client initialization. ```php getCode(); } $call = $client->account->calls ->get("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); print $call->to; ``` -------------------------------- ### Local Docker testing workflow Source: https://github.com/twilio/twilio-php/blob/main/CONTRIBUTING.md Commands to clone, build, and test the project using Docker for a specific PHP version. ```shell git clone https://github.com/twilio/twilio-php.git cd twilio-php make install make docker-dev-build VERSION=7.4-rc make docker-dev-test VERSION=7.4-rc Modify code make docker-dev-test VERSION=7.4-rc ``` -------------------------------- ### Run test suite Source: https://github.com/twilio/twilio-php/blob/main/CONTRIBUTING.md Execute the full twilio-php test suite locally. ```shell make test ``` -------------------------------- ### Importing the Twilio Client Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Use the new namespace for auto-loading the Twilio Client. ```php use \Twilio\Rest\Client; ``` -------------------------------- ### Marketplace - Domain Transition Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Initial transition of APIs from `oauth.twilio.com` to the `www.twilio.com` domain. ```APIDOC ## Marketplace - Domain Transition ### Description This marks the initial transition of Marketplace-related APIs from `oauth.twilio.com` to `www.twilio.com`. ### Method N/A (Domain change) ### Endpoint N/A (Domain change) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Wise_owl - API Initialization and Updates Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Initialization of the Wise_owl API as an open-api spec and updates to Send Message and Create Chat to include `contexts`. ```APIDOC ## Wise_owl - API Initialization and Updates ### Description Initializes the Wise_owl API using an open-api specification and updates existing endpoints to include `contexts` within the Message object. ### Method N/A (API initialization and update) ### Endpoint N/A (API initialization and update) ### Parameters #### Message Object Update - **contexts** (array) - Required - Contexts to be included in the message. ### Request Example ```json { "message": { "body": "Hello", "contexts": [ { "key": "value" } ] } } ``` ### Response N/A ``` -------------------------------- ### Assistants - AI Assistants v1 Release Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Introduction of AI Assistants v1, enabling new capabilities for building intelligent assistants. ```APIDOC ## Assistants - AI Assistants v1 Release ### Description Launches AI Assistants version 1, providing a new set of tools and APIs for creating and managing AI-powered assistants. ### Method N/A (New API version release) ### Endpoint N/A (New API version release) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Library - Token Pagination Handling Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Handles existing query parameters correctly during token pagination in the twilio-php library. ```APIDOC ## Library - Token Pagination Handling ### Description Ensures that existing query parameters are correctly handled when using token-based pagination in the twilio-php library. ### Method N/A (Library feature) ### Endpoint N/A (Library feature) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Create Taskrouter Workflow (5.1.x) Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md The legacy method for creating a workflow requiring the assignment callback URL as a positional argument. ```php taskrouter->workspaces('WS123')->workflows->create( 'My New Workflow', '{...}', 'http://assignment-callback-url.com' ); ``` -------------------------------- ### Update Chat Members and Channels List Parameters Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md Reading members and listing channels now requires an options array as the first argument for the read, stream, and page methods. ```php chat->v1->services('IS123')->channels('CH123')->members->read(10); $client->chat->v1->services('IS123')->channels->read(10); ``` ```php chat->v1->services('IS123')->channels('CH123')->members->read(array(), 10); $client->chat->v1->services('IS123')->channels->read(array(), 10); $client->chat->v1->services('IS123')->channels('CH123')->members->read(array('type' => 'public'), 10); ``` -------------------------------- ### Memory API - FetchOperation Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md A new path has been added to fetch operations. ```APIDOC ## GET /v1/ControlPlane/Operations/{operationId} ### Description Fetches an operation. ### Endpoint /v1/ControlPlane/Operations/{operationId} ``` -------------------------------- ### Chat message creation with body parameter Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md In version 5.1x.x, the `Body` parameter was not required for Chat `Message` creation. This allowed for sending media in messages by providing a `media_sid` instead of a `body`. ```php chat->v2->service('IS123')->channel('CH123')->message->create("this is the body"); ``` -------------------------------- ### Create Taskrouter Workflow (5.2.x) Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md The updated method for creating a workflow where the assignment callback URL is passed within the options array, allowing for optional configuration. ```php taskrouter->workspaces('WS123')->workflows->create( 'My New Workflow', '{...}', array( 'assignmentCallbackUrl' => 'http://assignment-callback-url.com', ) ); ``` -------------------------------- ### Configuring a Custom HTTP Client Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Inject a custom HTTP client by passing an object that implements Twilio\Http\HttpClient. ```php $customClient = new MyCustomClient(); $client = new Client('ACxxx', 'AUTHTOKEN', array('httpClient' => customClient)); ``` -------------------------------- ### Create Call with Optional Arguments in Twilio-PHP Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Demonstrates three ways to create a call with optional arguments in twilio-php: the original associative array method, using the Options Factory, and using the Options Builder. ```php calls->create( '+14155551234', '+14155557890', array( 'applicationSid' => 'AP123', 'method' => 'POST', ) ); // Options Factory $client->calls->create( '+14155551234', '+14155557890', CallOptions::create( Values::NONE, 'AP123', 'POST' ) ); // Options Builder $client->calls->create( '+14155551234', '+14155557890', CallOptions::create()->setApplicationSid('AP123') ->setMethod('POST') ); ``` -------------------------------- ### Exception/Log Placeholder Source: https://github.com/twilio/twilio-php/blob/main/ISSUE_TEMPLATE.md Paste any exceptions or log messages generated by the issue here. This helps in diagnosing the problem. ```text # paste exception/log here ``` -------------------------------- ### Create a Custom Proxy-Enabled HttpClient Source: https://github.com/twilio/twilio-php/blob/main/advanced-examples/custom-http-client.md Extends the base CurlClient to allow proxy server and CA info configuration for outgoing requests. ```php proxy = $proxy; $this->cainfo = $cainfo; $this->http = new CurlClient(); } public function request( $method, $url, $params = array(), $data = array(), $headers = array(), $user = null, $password = null, $timeout = null): Response { // Here you can change the URL, headers and other request parameters $options = $this->options( $method, $url, $params, $data, $headers, $user, $password, $timeout ); $curl = curl_init($url); curl_setopt_array($curl, $options); if (!empty($this->proxy)) curl_setopt($curl, CURLOPT_PROXY, $this->proxy); if (!empty($this->cainfo)) curl_setopt($curl, CURLOPT_CAINFO, $this->cainfo); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true); $response = curl_exec($curl); $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $head = substr($response, 0, $headerSize); $body = substr($response, $headerSize); $responseHeaders = array(); $headerLines = preg_split("/\r?\n/", $head); foreach ($headerLines as $line) { if (!preg_match("/:/", $line)) continue; list($key, $value) = explode(':', $line, 2); $responseHeaders[trim($key)] = trim($value); } curl_close($curl); if (isset($buffer) && is_resource($buffer)) { fclose($buffer); } return new Response($statusCode, $body, $responseHeaders); } } ``` -------------------------------- ### Memory API - Profile Imports Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Endpoints for managing Profile Imports have been removed. ```APIDOC ## DELETE /v1/Stores/{storeId}/Profiles/Import ### Description Removes Profile Imports. ### Endpoint /v1/Stores/{storeId}/Profiles/Import ``` ```APIDOC ## DELETE /v1/Stores/{storeId}/Profiles/Import/{importId} ### Description Removes a specific Profile Import. ### Endpoint /v1/Stores/{storeId}/Profiles/Import/{importId} ``` -------------------------------- ### InvokeDocsMcp API Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md A new path has been added to invoke Mcp documentation. ```APIDOC ## POST /v1/docs ### Description Invokes Mcp documentation. ### Method POST ### Endpoint /v1/docs ``` -------------------------------- ### Accessing API Resources Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Access resources using the new API structure, optionally pinning to specific API versions. ```php // Old $feedback = $client->account->calls('CA123xxx')->getFeedback(); // New $feedback = $client->api->v2010->account->calls('CA123xxxx')->feedback()->fetch(); // OR $feedback = $client->calls('CA123xxxx')->feedback()->fetch(); ``` -------------------------------- ### Update TaskRouter Activities and Tasks Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md Demonstrates updated parameter handling for TaskRouter resources, moving from positional arguments to associative arrays. ```php taskrouter->v1->workspaces('WS123')->activities('WA123')->update('new friendly name'); $client->taskrouter->v1->workspaces('WS123')->activities->create('new friendly name', true); $client->taskrouter->v1->workspaces('WS123')->tasks->create('attributes', 'WW123', array('timeout' => 10)); ``` ```php taskrouter->v1->workspaces('WS123')->activities('WA123')->update(array('friendlyName' => 'new friendly name')); $client->taskrouter->v1->workspaces('WS123')->activities->create('new friendly name', array('available' => true)); $client->taskrouter->v1->workspaces('WS123')->tasks->create(array( 'attributes' => 'attributes', 'workflowSid' => 'WW123', 'timeout' => 10 )); ``` -------------------------------- ### Iterate Through Records with Twilio PHP Source: https://github.com/twilio/twilio-php/blob/main/README.md Demonstrates how the Twilio PHP library handles automatic paging for collections like messages. Use `read` for eager fetching into a list, `stream` for lazy iteration, or `page` for manual pagination. ```php messages->read([], $limit); foreach ($messageList as $msg) { print($msg->sid); } // Stream - returns an iterator of 'pageSize' messages at a time and lazily retrieves pages until 'limit' messages $messageStream = $client->messages->stream([], $limit, $pageSize); foreach ($messageStream as $msg) { print($msg->sid); } // Page - get the a single page by passing pageSize, pageToken and pageNumber $messagePage = $client->messages->page([], $pageSize); $nextPageData = $messagePage->nextPage(); // this will return data of next page foreach ($messagePage as $msg) { print($msg->sid); } ``` -------------------------------- ### Create Queue with FriendlyName Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md Enforces the requirement of the friendlyName parameter during queue creation. ```php api->v2010->accounts('AC123')->queues('QU123')->create(array('friendlyName' => 'Test')); ``` ```php api->v2010->accounts('AC123')->queues('QU123')->create('Test', array()); ``` -------------------------------- ### API - Calls API Optional Parameters Source: https://github.com/twilio/twilio-php/blob/main/CHANGES.md Addition of optional `clientNotificationUrl` parameter for create call and create participant APIs. ```APIDOC ## API - Calls API Optional Parameters ### Description Adds the optional `clientNotificationUrl` parameter to the create call and create participant APIs. ### Method POST (for create call and create participant) ### Endpoint - `/Calls` (create call) - `/Participants` (create participant) ### Parameters #### Request Body Parameters - **clientNotificationUrl** (string) - Optional - The URL to send client notifications to. ### Request Example ```json { "clientNotificationUrl": "http://example.com/notify", "...other_parameters": "..." } ``` ### Response #### Success Response (201) - **sid** (string) - The unique ID for the created resource. #### Response Example ```json { "sid": "CAxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "...other_fields": "..." } ``` ``` -------------------------------- ### Make a Call with Twilio PHP Source: https://github.com/twilio/twilio-php/blob/main/README.md Initiates an outbound call to a specified number. Requires Twilio Account SID, Auth Token, and a valid Twilio phone number. The 'url' parameter specifies TwiML to execute when the call connects. ```php calls->create( '8881231234', // Call this number '9991231234', // From a valid Twilio number [ 'url' => 'https://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient' ] ); ``` -------------------------------- ### Paging Resource Results Source: https://github.com/twilio/twilio-php/wiki/5.x-Migration-Guide Specify limit, page_size, or page_limit to control how resources are fetched. ```php $calls = $client->calls->read(array('limit' => 1000)); $calls->length; // 1000 ``` -------------------------------- ### Accessing Sandbox resource (deprecated) Source: https://github.com/twilio/twilio-php/blob/main/UPGRADE.md In version 5.5.x, the Sandbox resource was available for use. This resource has since been removed from the API and is no longer supported in later versions. ```php api->v2010->sandbox->read(); ```