### Install Plivo Node.js SDK Source: https://github.com/plivo/plivo-node/blob/master/README.md Install the Plivo Node.js SDK using npm. For beta features, install the beta version. ```bash npm install plivo ``` ```bash npm install plivo@beta ``` -------------------------------- ### Install Plivo Node.js SDK Source: https://context7.com/plivo/plivo-node/llms.txt Install the SDK using npm. This is the first step to integrating Plivo into your Node.js application. ```bash npm install plivo ``` -------------------------------- ### Generated Plivo XML Example Source: https://github.com/plivo/plivo-node/blob/master/README.md Example of Plivo XML generated by the SDK, used for managing call flows. ```xml Hello, world! ``` -------------------------------- ### Manage Rented Numbers with Plivo Node.js SDK Source: https://context7.com/plivo/plivo-node/llms.txt These examples demonstrate how to list all numbers associated with your account, update a number's configuration (like linking an app or setting an alias), and release (unrent) a number. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // List all numbers on your account client.numbers.list({ type: 'local', services: 'voice,sms', limit: 10 }) .then(numbers => numbers.forEach(n => console.log(n.number, n.alias))) .catch(err => console.error('Error:', err)); ``` ```javascript // Update a number — link app and enable CNAM lookup client.numbers.update('+14155551234', { appId: 'XXXXXXXXXXXXXXXXXX', alias: 'Support Line', cnamLookup: 'enabled', cnam: 'Acme Corp' }) .then(response => console.log(response.message)) .catch(err => console.error('Error:', err)); ``` ```javascript // Unrent (release) a number client.numbers.unrent('+14155551234') .then(() => console.log('Number released')) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Manage Conferences with Plivo Node.js SDK Source: https://context7.com/plivo/plivo-node/llms.txt Examples for managing conferences, including listing active conferences, retrieving details of a specific conference, and controlling individual members (mute, unmute, kick). ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // List all active conferences client.conferences.list() .then(response => { console.log('Active conferences:', response.conferences); }) .catch(err => console.error('Error:', err)); ``` ```javascript // Get conference details client.conferences.get('my-conference-room') .then(conf => { console.log('Members:', conf.conferenceMemberCount); console.log('Run time:', conf.conferenceRunTime, 'secs'); conf.members.forEach(m => console.log(' Member:', m.memberId, m.callUuid)); }) .catch(err => console.error('Error:', err)); ``` ```javascript // Mute/unmute a member client.conferences.muteMember('my-conference-room', '1') .then(r => console.log('Muted member:', r.memberId)) .catch(err => console.error('Error:', err)); ``` ```javascript client.conferences.unmuteMember('my-conference-room', '1') .then(() => console.log('Unmuted')) .catch(err => console.error('Error:', err)); ``` ```javascript // Kick a member client.conferences.kickMember('my-conference-room', '1') .then(() => console.log('Member kicked')) .catch(err => console.error('Error:', err)); ``` ```javascript // Start recording the conference client.conferences.record('my-conference-room', { fileFormat: 'mp3', callbackUrl: 'https://example.com/conf-recording' }) .then(r => console.log('Recording ID:', r.recordingId, '| URL:', r.url)) .catch(err => console.error('Error:', err)); ``` ```javascript // Hang up the entire conference client.conferences.hangup('my-conference-room') .then(() => console.log('Conference ended')) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Send Interactive CTA URLs with Plivo Node.js Source: https://github.com/plivo/plivo-node/blob/master/README.md This example demonstrates sending a WhatsApp message with a Call-to-Action (CTA) URL button. Ensure the 'plivo' module is imported and authentication is configured. ```javascript let plivo = require('plivo'); var client = new plivo.Client("",""); const interactive = { "type": "cta_url", "header": { "type": "media", "media": "https://xyz.com/s3/img.jpg" }, "body": { "text": "Know More" }, "footer": { "text": "Plivo" }, "action": { "buttons": [ { "title": "Click here", "cta_url": "https:plivo.com" } ] } } client.messages.create({ src:"+14156667778", dst:"+14156667777", type:"whatsapp", interactive:interactive }).then(function (response) { console.log(response); }); ``` -------------------------------- ### Look up phone number carrier and format Source: https://context7.com/plivo/plivo-node/llms.txt Use this to get carrier and formatting details for a given phone number. Requires authentication credentials. ```javascript const plivo = require('plivo'); const client = new plivo.Client('', ''); client.lookup.get('+14156667778') .then(response => { console.log('Phone number:', response.phoneNumber); console.log('Country:', response.country); console.log('Carrier:', response.carrier); console.log('Format:', response.format); }) .catch(err => console.error('Lookup failed:', err)); ``` -------------------------------- ### Send Quick Reply Buttons with Plivo Node.js Source: https://github.com/plivo/plivo-node/blob/master/README.md Use this to send WhatsApp messages with quick reply buttons. Ensure the 'plivo' module is installed and your authentication credentials are set. ```javascript let plivo = require('plivo'); var client = new plivo.Client("",""); const interactive = { "type": "button", "header": { "type": "media", "media": "https://xyz.com/s3/img.jpg" }, "body": { "text": "Make your selection" }, "action": { "buttons": [ { "title": "Click here", "id": "bt1" }, { "title": "Know More", "id": "bt2" }, { "title": "Request Callback", "id": "bt3" } ] } } client.messages.create({ src:"+14156667778", dst:"+14156667777", type:"whatsapp", interactive:interactive }).then(function (response) { console.log(response); }); ``` -------------------------------- ### Record and Stop Call Recording Source: https://context7.com/plivo/plivo-node/llms.txt Start or stop call recording for an active call. When starting, specify parameters like fileFormat, transcriptionType, and callback URLs. Ensure the callUUID is valid. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); const callUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Start recording client.calls.record(callUUID, { fileFormat: 'mp3', transcriptionType: 'auto', transcriptionUrl: 'https://example.com/transcription', callbackUrl: 'https://example.com/recording-done' }) .then(response => { console.log('Recording ID:', response.recordingId); console.log('Recording URL:', response.url); }) .catch(err => console.error('Error:', err)); // Stop recording client.calls.stopRecording(callUUID) .then(() => console.log('Recording stopped')) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Export Environment Variables for Local Development Source: https://github.com/plivo/plivo-node/blob/master/README.md These environment variables are required for local development setup using Docker. Ensure you replace placeholders with your actual Plivo credentials and API endpoints. ```bash export PLIVO_AUTH_ID= export PLIVO_AUTH_TOKEN= export PLIVO_API_DEV_HOST= export PLIVO_API_PROD_HOST= ``` -------------------------------- ### Get Account Details Source: https://context7.com/plivo/plivo-node/llms.txt Retrieve details of your main Plivo account, such as name, cash credits, and timezone. Ensure the client is initialized before calling this method. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Get account details client.accounts.get() .then(account => { console.log('Account name:', account.name); console.log('Cash credits:', account.cashCredits); console.log('Timezone:', account.timezone); }) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Record a Live Call Source: https://context7.com/plivo/plivo-node/llms.txt Start or stop call recording during an active call. The `record` method initiates recording with specified options, and `stopRecording` halts the ongoing recording. ```APIDOC ## client.calls.record / client.calls.stopRecording ### Description Start or stop call recording during an active call. ### Method `POST` ### Endpoint `/calls/{call_uuid}/` ### Parameters #### Path Parameters - **call_uuid** (string) - Required - The unique identifier for the call. #### Request Body (for record) - **fileFormat** (string) - Optional - The format of the recording file (e.g., 'mp3', 'wav'). Defaults to 'wav'. - **transcriptionType** (string) - Optional - Type of transcription ('auto' or 'none'). - **transcriptionUrl** (string) - Optional - URL to send transcription results to. - **callbackUrl** (string) - Optional - URL to send recording completion notification to. ### Request Example ```javascript const callUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Start recording client.calls.record(callUUID, { fileFormat: 'mp3', transcriptionType: 'auto', transcriptionUrl: 'https://example.com/transcription', callbackUrl: 'https://example.com/recording-done' }) .then(response => { console.log('Recording ID:', response.recordingId); console.log('Recording URL:', response.url); }) .catch(err => console.error('Error:', err)); // Stop recording client.calls.stopRecording(callUUID) .then(() => console.log('Recording stopped')) .catch(err => console.error('Error:', err)); ``` ### Response #### Success Response (200) - **recordingId** (string) - The unique identifier for the recording. - **url** (string) - The URL where the recording can be accessed. - **message** (string) - Indicates the status of the operation (e.g., 'Recording started', 'Recording stopped'). ``` -------------------------------- ### Retrieve Message Details Source: https://context7.com/plivo/plivo-node/llms.txt Fetch a specific message by its UUID using `get` or list messages with various filters using `list`. ```APIDOC ## client.messages.get / client.messages.list — Retrieve Message Details Fetch a specific message by UUID or list messages with filters. ### Get a specific message ```javascript client.messages.get('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') .then(msg => { console.log('State:', msg.messageState); console.log('From:', msg.fromNumber, '-> To:', msg.toNumber); console.log('Units:', msg.units, '| Amount:', msg.totalAmount); console.log('Error code:', msg.errorCode); }) .catch(err => console.error('Error:', err)); ``` ### List messages with filters ```javascript client.messages.list({ messageState: 'delivered', messageTime__gte: '2024-01-01 00:00:00', messageTime__lte: '2024-01-31 23:59:59', limit: 20, offset: 0 }) .then(messages => { console.log('Total:', messages.meta.totalCount); messages.forEach(m => console.log(m.messageUuid, m.messageState)); }) .catch(err => console.error('Error:', err)); ``` ``` -------------------------------- ### Get and List Live Calls with Plivo Node.js Source: https://context7.com/plivo/plivo-node/llms.txt Use `getLiveCall` to fetch details of a specific active call by its UUID. Use `listLiveCalls` to retrieve a list of all currently active calls on your account. Ensure you have the Plivo client initialized. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Get a specific live call client.calls.getLiveCall('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') .then(call => { console.log('Status:', call.callStatus); console.log('From:', call.from, '-> To:', call.to); console.log('Session start:', call.sessionStart); console.log('STIR verification:', call.stirVerification); }) .catch(err => console.error('Error:', err)); // List all live calls client.calls.listLiveCalls() .then(calls => calls.forEach(c => console.log('Live call UUID:', c.callUuid))) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Get PHLO Details Source: https://context7.com/plivo/plivo-node/llms.txt Retrieves the details of a specific PHLO using its UUID. This includes information about the PHLO's configuration and status. ```APIDOC ## Get PHLO Details ### Description Retrieves the details of a specific PHLO using its unique identifier. ### Method GET ### Endpoint /v1/Accounts/{account_id}/Phlo/{phlo_uuid}/ ### Parameters #### Path Parameters - **account_id** (string) - Required - Your Plivo authentication ID. - **phlo_uuid** (string) - Required - The unique identifier for the PHLO. ### Response #### Success Response (200) - **uuid** (string) - The unique identifier for the PHLO. - **name** (string) - The name of the PHLO. - **created_at** (string) - The timestamp when the PHLO was created. - **updated_at** (string) - The timestamp when the PHLO was last updated. - **version** (string) - The current version of the PHLO. - **status** (string) - The status of the PHLO (e.g., 'active', 'inactive'). #### Response Example ```json { "uuid": "your-phlo-uuid", "name": "My Awesome PHLO", "created_at": "2023-10-27T09:00:00Z", "updated_at": "2023-10-27T09:30:00Z", "version": "1.0", "status": "active" } ``` ``` -------------------------------- ### Retrieve Call Details Source: https://context7.com/plivo/plivo-node/llms.txt Fetch details of a completed call by its UUID, or list all calls with optional filters. The `get` method retrieves a single call, while `list` allows for filtering and pagination. ```APIDOC ## client.calls.get / client.calls.list ### Description Fetch details of a completed call by its UUID, or list all calls with optional filters. ### Method `GET` (for list) / `GET` (for get) ### Endpoint `/calls/{call_uuid}` (for get) `/calls/` (for list) ### Parameters #### Path Parameters (for get) - **call_uuid** (string) - Required - The unique identifier for the call. #### Query Parameters (for list) - **fromNumber** (string) - Optional - Filter calls by the originating number. - **billDuration__gte** (integer) - Optional - Filter calls with a bill duration greater than or equal to the specified value. - **limit** (integer) - Optional - The maximum number of calls to return. - **offset** (integer) - Optional - The number of calls to skip before returning results. ### Request Example ```javascript // Get a specific call client.calls.get('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') .then(call => { console.log('Direction:', call.callDirection); console.log('Duration:', call.callDuration, 'secs'); console.log('Total amount:', call.totalAmount); console.log('Hangup cause:', call.hangupCauseName); }) .catch(err => console.error('Error:', err)); // List calls with filters client.calls.list({ fromNumber: '+14156667778', billDuration__gte: 60, limit: 10, offset: 0 }) .then(calls => { console.log('Total found:', calls.meta.totalCount); calls.forEach(c => console.log(c.callUuid, c.callDirection)); }) .catch(err => console.error('Error:', err)); ``` ### Response #### Success Response (200) - **call** (object) - Details of a single call (when using `get`). - **calls** (array) - A list of call objects (when using `list`). - **callUuid** (string) - The unique identifier for the call. - **callDirection** (string) - The direction of the call. - **callDuration** (integer) - The duration of the call in seconds. - **totalAmount** (string) - The total cost of the call. - **hangupCauseName** (string) - The reason the call was hung up. - **meta** (object) - Metadata for the list response (when using `list`). - **totalCount** (integer) - The total number of calls matching the filters. ``` -------------------------------- ### Build Complex IVR Response with Plivo XML Source: https://context7.com/plivo/plivo-node/llms.txt Use plivo.Response to construct interactive voice response (IVR) call flows. This example demonstrates collecting digits and fallback messages. ```javascript const plivo = require('plivo'); // Build a complex IVR response const response = new plivo.Response(); // Say a greeting, then collect digits const getDigits = response.addGetDigits({ action: 'https://example.com/ivr-action', method: 'POST', numDigits: 1, timeout: 10, validDigits: '123', retries: 2, playBeep: false }); getDigits.addSpeak('Press 1 for Sales, 2 for Support, or 3 to leave a message.'); // Fallback if no digits collected response.addSpeak('We did not receive your input. Goodbye.', { voice: 'WOMAN', language: 'en-US' }); response.addHangup({}); console.log(response.toXML()); /* Output: Press 1 for Sales... We did not receive your input. Goodbye. */ ``` -------------------------------- ### Initialize Plivo Client Source: https://context7.com/plivo/plivo-node/llms.txt Create a Client instance using your Plivo auth credentials. Credentials can be read from environment variables or provided explicitly. Proxy and timeout options are also available. ```javascript const plivo = require('plivo'); // Using environment variables (recommended) const client = new plivo.Client(); ``` ```javascript const plivo = require('plivo'); // Explicit credentials const client = new plivo.Client('', ''); ``` ```javascript const plivo = require('plivo'); // With proxy and timeout options const client = new plivo.Client('', '', { proxy: 'http://proxy.example.com:8080', timeout: 10000 // ms }); ``` -------------------------------- ### Initialize Plivo Client with Credentials Source: https://github.com/plivo/plivo-node/blob/master/README.md Initialize the Plivo client by providing authentication credentials directly. ```javascript let plivo = require('plivo'); let client = new plivo.Client('', ''); ``` -------------------------------- ### Initialize Plivo Client with Environment Variables Source: https://github.com/plivo/plivo-node/blob/master/README.md Initialize the Plivo client without arguments to automatically fetch authentication credentials from PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN environment variables. ```javascript let plivo = require('plivo'); let client = new plivo.Client(); ``` -------------------------------- ### Run a PHLO with Plivo Source: https://github.com/plivo/plivo-node/blob/master/README.md Execute a Plivo PHLO using the PhloClient. Requires authentication credentials and the PHLO ID. ```javascript let plivo = require('plivo'); var PhloClient = plivo.PhloClient; var phloClient = phlo = null; phloClient = new PhloClient('', ''); phloClient.phlo('').run().then(function (result) { console.log('Phlo run result', result); }); ``` -------------------------------- ### Get Specific Subaccount Source: https://context7.com/plivo/plivo-node/llms.txt Retrieve details for a specific subaccount using its auth ID. This allows you to view the subaccount's name and enabled status. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Get a specific subaccount client.subaccounts.get('SAXXXXXXXXXXXXXXXXXX') .then(sub => console.log('Subaccount:', sub.name, '| Enabled:', sub.enabled)) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Plivo Resource Management Interface Source: https://github.com/plivo/plivo-node/blob/master/README.md Demonstrates the consistent interfaces for creating, retrieving, updating, deleting, and listing resources using the Plivo client. ```javascript client.resources.create(name,params); // Create client.resources.get(id); // Get client.resources.update(params); // Update client.resources.delete(id); // Delete client.resources.list({limit:5,offset:0}); // List all resources, max 20 at a time ``` -------------------------------- ### Build Conference Response with Plivo XML Source: https://context7.com/plivo/plivo-node/llms.txt Generate Plivo XML to create a conference room. Configure settings like muting, recording, and wait sound. ```javascript const confResponse = new plivo.Response(); confResponse.addConference('my-room', { muted: false, startConferenceOnEnter: true, endConferenceOnExit: false, record: true, recordFileFormat: 'mp3', maxMembers: 10, waitSound: 'https://example.com/hold-music.mp3' }); ``` -------------------------------- ### Build Real-time Streaming Response with Plivo XML Source: https://context7.com/plivo/plivo-node/llms.txt Generate Plivo XML for real-time audio streaming via WebSockets. Configure bidirectional streaming, audio track, and content type. ```javascript const streamResponse = new plivo.Response(); streamResponse.addStream('wss://stream.example.com/audio', { bidirectional: false, audioTrack: 'inbound', contentType: 'audio/x-l16;rate=8000', statusCallbackUrl: 'https://example.com/stream-events' }); console.log(streamResponse.toXML()); ``` -------------------------------- ### Build Record Response with Plivo XML Source: https://context7.com/plivo/plivo-node/llms.txt Create a Plivo XML response to record an inbound call. Configure recording length, file format, and transcription options. ```javascript const recordResponse = new plivo.Response(); recordResponse.addRecord({ action: 'https://example.com/recording-done', maxLength: 300, fileFormat: 'mp3', playBeep: true, transcriptionType: 'auto', transcriptionUrl: 'https://example.com/transcription' }); ``` -------------------------------- ### Search and Buy Phone Numbers with Plivo Node.js SDK Source: https://context7.com/plivo/plivo-node/llms.txt Use these snippets to search for available phone numbers based on criteria like country, type, pattern, and services. The 'buy' snippet shows how to purchase a number, requiring the number and an application ID. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Search for available US local numbers client.numbers.search('US', { type: 'local', pattern: '415', services: 'voice,sms', limit: 5 }) .then(numbers => { numbers.forEach(n => { console.log(n.number, '| SMS:', n.smsEnabled, '| Voice:', n.voiceEnabled); console.log(' Monthly rate:', n.monthlyRentalRate); }); }) .catch(err => console.error('Error:', err)); ``` ```javascript // Buy a phone number client.numbers.buy('+14155551234', 'XXXXXXXXXXXXXXXXXX') // number, app_id .then(response => { console.log('Status:', response.status); console.log('Numbers:', response.numbers); }) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Send SMS, MMS, and WhatsApp Messages with Plivo Node.js Source: https://context7.com/plivo/plivo-node/llms.txt The `client.messages.create` method supports sending SMS, MMS with media URLs, and various WhatsApp message types including free-form text, templated messages, and interactive button messages. Specify the `type` parameter accordingly. For templated and interactive messages, provide the respective `template` or `interactive` objects. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Send an SMS client.messages.create({ src: '+14156667778', dst: '+14156667777', text: 'Hello from Plivo!', url: 'https://example.com/sms-status', method: 'POST' }) .then(response => { console.log('Message UUID:', response.messageUuid); console.log('Message:', response.message); }) .catch(err => console.error('Error:', err)); ``` ```javascript // Send an MMS with media client.messages.create({ src: '+14156667778', dst: '+14156667777', text: 'Check out this image!', type: 'mms', media_urls: ['https://media.example.com/image.jpg'], url: 'https://example.com/mms-status' }) .then(response => console.log('MMS UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ```javascript // Send a WhatsApp free-form text client.messages.create({ src: '+14156667778', dst: '+14156667777', type: 'whatsapp', text: 'Hello via WhatsApp!' }) .then(response => console.log('WA UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ```javascript // Send a WhatsApp templated message const template = { name: 'order_confirmation', language: 'en_US', components: [ { type: 'header', parameters: [{ type: 'media', media: 'https://example.com/logo.jpg' }] }, { type: 'body', parameters: [{ type: 'text', text: 'Order #12345' }] } ] }; client.messages.create({ src: '+14156667778', dst: '+14156667777', type: 'whatsapp', template: template, url: 'https://example.com/wa-status' }) .then(response => console.log('Templated WA UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ```javascript // Send a WhatsApp interactive quick-reply message const interactive = { type: 'button', header: { type: 'media', media: 'https://example.com/banner.jpg' }, body: { text: 'Would you like to confirm your appointment?' }, action: { buttons: [ { title: 'Confirm', id: 'btn_confirm' }, { title: 'Cancel', id: 'btn_cancel' } ] } }; client.messages.create({ src: '+14156667778', dst: '+14156667777', type: 'whatsapp', interactive: interactive }) .then(response => console.log('Interactive WA UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### client.verify_session Source: https://context7.com/plivo/plivo-node/llms.txt Send OTP codes via SMS, WhatsApp, or voice and validate them. ```APIDOC ## client.verify_session — Verify (OTP) Sessions ### Description Send OTP codes via SMS, WhatsApp, or voice and validate them. ### Methods - `create`: Creates a verification session and sends an OTP. - `validate`: Validates the OTP entered by the user. - `get`: Retrieves details of a verification session. ### create #### Parameters - **recipient** (string) - Required - The phone number to send the OTP to. - **channel** (string) - Required - The channel to use ('sms', 'voice', 'whatsapp'). - **locale** (string) - Optional - The locale for the OTP message. - **brand_name** (string) - Optional - The name of the brand sending the OTP. - **code_length** (integer) - Optional - The length of the OTP code. - **app_uuid** (string) - Required - The UUID of the Verify application. - **url** (string) - Optional - A callback URL for verification events. ### validate #### Parameters - **id** (string) - Required - The session UUID of the verification session. - **otp** (string) - Required - The OTP entered by the user. ### get #### Parameters - **id** (string) - Required - The session UUID of the verification session. ### Request Example (Create Session) ```javascript const plivo = require('plivo'); const client = new plivo.Client(); client.verify_session.create({ recipient: '+14156667777', channel: 'sms', locale: 'en', brand_name: 'Acme', code_length: 6, app_uuid: 'your-verify-app-uuid', url: 'https://example.com/verify-callback' }) .then(response => { console.log('Session UUID:', response.sessionUuid); console.log('Message:', response.message); }) .catch(err => console.error('Error:', err)); ``` ### Request Example (Validate OTP) ```javascript client.verify_session.validate({ id: 'session-uuid-here', otp: '123456' }) .then(response => console.log('Validation result:', response.message)) .catch(err => console.error('Validation failed:', err)); ``` ### Request Example (Get Session Details) ```javascript client.verify_session.get('session-uuid-here') .then(session => { console.log('Status:', session.status); console.log('Attempt count:', session.count); console.log('Channel:', session.channel); }) .catch(err => console.error('Error:', err)); ``` ### Response (Create Session) #### Success Response (200) - **sessionUuid** (string) - The UUID of the created verification session. - **message** (string) - A message indicating the status of the operation. ### Response (Validate OTP) #### Success Response (200) - **message** (string) - The result of the validation (e.g., 'approved' or 'failed'). ### Response (Get Session Details) #### Success Response (200) - **status** (string) - The current status of the session. - **count** (integer) - The number of attempts made. - **channel** (string) - The channel used for the session. ``` -------------------------------- ### Run PHLO Flow with Plivo Node.js SDK Source: https://context7.com/plivo/plivo-node/llms.txt Execute a pre-built PHLO workflow with custom payload parameters. Ensure you have your Plivo authentication credentials and the PHLO UUID. ```javascript const plivo = require('plivo'); const phloClient = new plivo.PhloClient('', ''); // Run a PHLO with custom payload phloClient.phlo('your-phlo-uuid').run({ from: '+14156667778', to: '+14156667777' }) .then(result => console.log('PHLO result:', result)) .catch(err => console.error('PHLO run failed:', err)); // Get PHLO details phloClient.phlo.get('your-phlo-uuid') .then(phlo => console.log('PHLO info:', phlo)) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Make a Voice Call with Plivo Source: https://github.com/plivo/plivo-node/blob/master/README.md Initiate a voice call using the Plivo client. Requires source and destination phone numbers, and a URL for the call's answer. ```javascript let plivo = require('plivo'); let client = new plivo.Client(); client.calls.create( '+14156667778', '+14156667777', 'http://answer.url' ).then(function(response) { console.log(response) }); ``` -------------------------------- ### Create Subaccount Source: https://context7.com/plivo/plivo-node/llms.txt Create a new subaccount under your main Plivo account. Requires a name and a boolean indicating if it should be enabled. The response includes the new auth ID and token. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Create a subaccount client.subaccounts.create('Sales Team', true) .then(response => { console.log('New auth_id:', response.authId); console.log('New auth_token:', response.authToken); }) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### client.lookup.get Source: https://context7.com/plivo/plivo-node/llms.txt Look up carrier and format information for any phone number. ```APIDOC ## client.lookup.get — Phone Number Lookup ### Description Look up carrier and format information for any phone number. ### Method GET (Implied by SDK method) ### Endpoint Not explicitly defined, SDK method. ### Parameters #### Path Parameters - **phoneNumber** (string) - Required - The phone number to look up (e.g., '+14156667778'). ### Request Example ```javascript const plivo = require('plivo'); const client = new plivo.Client('', ''); client.lookup.get('+14156667778') .then(response => { console.log('Phone number:', response.phoneNumber); console.log('Country:', response.country); console.log('Carrier:', response.carrier); console.log('Format:', response.format); }) .catch(err => console.error('Lookup failed:', err)); ``` ### Response #### Success Response (200) - **phoneNumber** (string) - The looked-up phone number. - **country** (string) - The country associated with the phone number. - **carrier** (string) - The carrier of the phone number. - **format** (string) - The formatted version of the phone number. ``` -------------------------------- ### Inject Audio: Speak Text and Play Music Source: https://context7.com/plivo/plivo-node/llms.txt Add audio to a live call using text-to-speech or by playing a media file. Options include specifying voice and language for text-to-speech. You can also stop the music playback. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); const callUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Speak text into the call client.calls.speakText(callUUID, 'Your order has been confirmed. Thank you!', { voice: 'WOMAN', language: 'en-US' }) .then(response => console.log(response.message)) .catch(err => console.error('Error:', err)); // Play an audio file client.calls.playMusic(callUUID, 'https://media.example.com/hold-music.mp3') .then(response => console.log(response.message)) .catch(err => console.error('Error:', err)); // Stop playing music client.calls.stopPlayingMusic(callUUID) .then(() => console.log('Music stopped')) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Send SMS, MMS, or WhatsApp Messages Source: https://context7.com/plivo/plivo-node/llms.txt Send various types of messages including SMS, MMS with media, and different formats of WhatsApp messages (templated, free-form, interactive, or location) using the `create` method. ```APIDOC ## client.messages.create — Send SMS, MMS, or WhatsApp Messages Send an SMS, MMS (with media), or WhatsApp message (templated, free-form, interactive, or location). ### Send an SMS ```javascript client.messages.create({ src: '+14156667778', dst: '+14156667777', text: 'Hello from Plivo!', url: 'https://example.com/sms-status', method: 'POST' }) .then(response => { console.log('Message UUID:', response.messageUuid); console.log('Message:', response.message); }) .catch(err => console.error('Error:', err)); ``` ### Send an MMS with media ```javascript client.messages.create({ src: '+14156667778', dst: '+14156667777', text: 'Check out this image!', type: 'mms', media_urls: ['https://media.example.com/image.jpg'], url: 'https://example.com/mms-status' }) .then(response => console.log('MMS UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ### Send a WhatsApp free-form text ```javascript client.messages.create({ src: '+14156667778', dst: '+14156667777', type: 'whatsapp', text: 'Hello via WhatsApp!' }) .then(response => console.log('WA UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ### Send a WhatsApp templated message ```javascript const template = { name: 'order_confirmation', language: 'en_US', components: [ { type: 'header', parameters: [{ type: 'media', media: 'https://example.com/logo.jpg' }] }, { type: 'body', parameters: [{ type: 'text', text: 'Order #12345' }] } ] }; client.messages.create({ src: '+14156667778', dst: '+14156667777', type: 'whatsapp', template: template, url: 'https://example.com/wa-status' }) .then(response => console.log('Templated WA UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ### Send a WhatsApp interactive quick-reply message ```javascript const interactive = { type: 'button', header: { type: 'media', media: 'https://example.com/banner.jpg' }, body: { text: 'Would you like to confirm your appointment?' }, action: { buttons: [ { title: 'Confirm', id: 'btn_confirm' }, { title: 'Cancel', id: 'btn_cancel' } ] } }; client.messages.create({ src: '+14156667778', dst: '+14156667777', type: 'whatsapp', interactive: interactive }) .then(response => console.log('Interactive WA UUID:', response.messageUuid)) .catch(err => console.error('Error:', err)); ``` ``` -------------------------------- ### Real-Time Audio Streaming Source: https://context7.com/plivo/plivo-node/llms.txt Fork a live call's audio stream to a WebSocket service for real-time processing. Configure stream parameters like bidirectional, audioTrack, and contentType. You can also stop a specific stream using its ID. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); const callUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Start audio stream client.calls.stream(callUUID, 'wss://stream.example.com/audio', { bidirectional: false, audioTrack: 'inbound', streamTimeout: 3600, contentType: 'audio/x-l16;rate=8000', statusCallbackUrl: 'https://example.com/stream-status', statusCallbackMethod: 'POST' }) .then(response => { console.log('Stream ID:', response.streamId); console.log('Message:', response.message); }) .catch(err => console.error('Error:', err)); // Stop a specific stream client.calls.stopStream(callUUID, 'stream-id-here') .then(() => console.log('Stream stopped')) .catch(err => console.error('Error:', err)); ``` -------------------------------- ### Real-Time Audio Streaming Source: https://context7.com/plivo/plivo-node/llms.txt Fork a live call's audio stream to a WebSocket service for real-time processing. The `stream` method initiates the stream, and `stopStream` terminates a specific stream. ```APIDOC ## client.calls.stream / client.calls.stopStream ### Description Fork a live call's audio stream to a WebSocket service for real-time processing (e.g., transcription, AI). ### Method `POST` ### Endpoint `/calls/{call_uuid}/` ### Parameters #### Path Parameters - **call_uuid** (string) - Required - The unique identifier for the call. #### Request Body (for stream) - **ws_url** (string) - Required - The WebSocket URL to stream the audio to. - **bidirectional** (boolean) - Optional - Whether to stream audio in both directions. Defaults to `false`. - **audioTrack** (string) - Optional - Which audio track to stream ('inbound', 'outbound', or 'both'). Defaults to 'inbound'. - **streamTimeout** (integer) - Optional - The duration in seconds to stream the audio. Defaults to 3600. - **contentType** (string) - Optional - The content type of the audio stream (e.g., 'audio/x-l16;rate=8000'). - **statusCallbackUrl** (string) - Optional - URL to send stream status notifications to. - **statusCallbackMethod** (string) - Optional - The HTTP method for the status callback. #### Request Body (for stopStream) - **stream_id** (string) - Required - The unique identifier for the stream to stop. ### Request Example ```javascript const callUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Start audio stream client.calls.stream(callUUID, 'wss://stream.example.com/audio', { bidirectional: false, audioTrack: 'inbound', streamTimeout: 3600, contentType: 'audio/x-l16;rate=8000', statusCallbackUrl: 'https://example.com/stream-status', statusCallbackMethod: 'POST' }) .then(response => { console.log('Stream ID:', response.streamId); console.log('Message:', response.message); }) .catch(err => console.error('Error:', err)); // Stop a specific stream client.calls.stopStream(callUUID, 'stream-id-here') .then(() => console.log('Stream stopped')) .catch(err => console.error('Error:', err)); ``` ### Response #### Success Response (200) - **streamId** (string) - The unique identifier for the initiated stream. - **message** (string) - Indicates the status of the streaming operation. ``` -------------------------------- ### Live Call Audio Injection Source: https://context7.com/plivo/plivo-node/llms.txt Inject audio into an active call using text-to-speech or by playing a media file. The `speakText` method converts text to speech, and `playMusic` plays an audio file. `stopPlayingMusic` halts audio playback. ```APIDOC ## client.calls.speakText / client.calls.playMusic / client.calls.stopPlayingMusic ### Description Inject audio into an active call — either text-to-speech or a media file. ### Method `POST` ### Endpoint `/calls/{call_uuid}/` ### Parameters #### Path Parameters - **call_uuid** (string) - Required - The unique identifier for the call. #### Request Body (for speakText) - **text** (string) - Required - The text to be spoken. - **voice** (string) - Optional - The voice to use for text-to-speech (e.g., 'WOMAN', 'MAN'). - **language** (string) - Optional - The language for the text-to-speech (e.g., 'en-US'). #### Request Body (for playMusic) - **url** (string) - Required - The URL of the audio file to play. ### Request Example ```javascript const callUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Speak text into the call client.calls.speakText(callUUID, 'Your order has been confirmed. Thank you!', { voice: 'WOMAN', language: 'en-US' }) .then(response => console.log(response.message)) .catch(err => console.error('Error:', err)); // Play an audio file client.calls.playMusic(callUUID, 'https://media.example.com/hold-music.mp3') .then(response => console.log(response.message)) .catch(err => console.error('Error:', err)); // Stop playing music client.calls.stopPlayingMusic(callUUID) .then(() => console.log('Music stopped')) .catch(err => console.error('Error:', err)); ``` ### Response #### Success Response (200) - **message** (string) - Indicates the status of the audio injection operation. ``` -------------------------------- ### Manage Recordings with Plivo Node.js SDK Source: https://context7.com/plivo/plivo-node/llms.txt Retrieve details of a specific recording using its ID, list recordings associated with a particular call, or delete a recording. ```javascript const plivo = require('plivo'); const client = new plivo.Client(); // Get a recording by ID client.recordings.get('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') .then(rec => { console.log('URL:', rec.recordingUrl); console.log('Duration (ms):', rec.recordingDurationMs); console.log('Format:', rec.recordingFormat); }) .catch(err => console.error('Error:', err)); ``` ```javascript // List recordings for a specific call client.recordings.list({ callUuid: 'call-uuid-here', limit: 10 }) .then(recordings => recordings.forEach(r => console.log(r.recordingId, r.recordingUrl))) .catch(err => console.error('Error:', err)); ``` ```javascript // Delete a recording client.recordings.delete('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') .then(() => console.log('Recording deleted')) .catch(err => console.error('Error:', err)); ```