Download the PHP package nextgenswitch/nextgenswitch-php without Composer
On this page you can find all versions of the php package nextgenswitch/nextgenswitch-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nextgenswitch-php
NextGenSwitch PHP SDK
The official PHP SDK for the NextGenSwitch Programmable Voice API. Create and modify calls, build escaped Voice XML, stream call audio to AI services, and parse Gather and Dial callbacks with typed PHP objects.
Requirements
- PHP 8.1 or newer
- DOM extension
- Composer
- A NextGenSwitch deployment and API credentials
Installation
Configure the Client
Keep credentials in environment variables or a secret manager.
The SDK sends credentials with the X-Authorization and X-Authorization-Secret headers documented by NextGenSwitch. Use HTTPS for remote deployments.
Create a Call
Use either inline Voice XML or a URL that returns a valid <Response>.
To use a hosted XML document:
Exactly one of responseXml or responseUrl is required.
Modify an Active Call
Build Voice XML
Supported helpers match the official API documentation:
| XML verb | SDK method |
|---|---|
<Say> |
say($text, $attributes) |
<Play> |
play($url, $attributes) |
<Gather> |
gather($attributes, $children) |
<Dial> |
dial($to, $attributes, $children) |
<Record> |
record($attributes) |
<Connect><Stream> |
stream($url, $parameters, $attributes) |
<Hangup> |
hangup() |
<Pause> |
pause($seconds) |
<Redirect> |
redirect($url, $method) |
<Bridge> |
bridge($callId, $bridgeAfterEstablish) |
<Leave> |
leave() |
Text and attribute values are encoded through PHP's DOM implementation instead of string concatenation.
Stream Audio to an AI Service
Do not put provider API keys in Voice XML. Resolve secrets on the WebSocket service.
Parse Action Callbacks
Dial callbacks can be parsed with DialResult::fromArray($_POST). Its established, duration, waitingDuration, bridgeCallId, and recordFile properties correspond to the documented callback fields.
Callback authenticity controls are deployment-specific and are not currently documented as a NextGenSwitch signature scheme. Restrict callback endpoints, require TLS, validate expected fields, and apply your own authentication controls where supported.
Errors
ValidationException: invalid SDK input before a request is sentApiException: a non-2xx API response; exposesstatusCode()andresponseBody()NextGenSwitchException: transport or other SDK failure
Runnable Examples
After composer install, configure credentials without committing them:
Then run or adapt these examples:
| Example | Purpose |
|---|---|
create-call.php |
Create a call with inline Gather instructions |
modify-call.php |
Replace the flow of an active call by call ID |
record-call.php |
Record caller audio with beep, transcription, trimming, and callback |
dial-with-recording.php |
Dial an external destination and record from answer |
stream-to-ai-agent.php |
Stream bidirectional audio to a WebSocket AI service |
gather-webhook.php |
Parse Gather input and return the next Voice XML flow |
dial-webhook.php |
Parse Dial completion and return follow-up Voice XML |
For example:
Replace all example.com callback, media, and WebSocket URLs with TLS endpoints you control. Validate callback input and never commit API or SIP credentials.
Development
The test workflow covers PHP 8.1, 8.2, 8.3, and 8.4.
Documentation and Support
- Programmable Voice API
- NextGenSwitch documentation
- NextGenSwitch website
- Report an SDK issue
- Contact NextGenSwitch
License
MIT