Skip to main content

Order Confirmation Call

Steps to run the code

1. Prerequisites

Before you start, ensure you have the following:

2. Clone Repository

First, clone the repository by running the following command:

git clone https://github.com/telecmi/piopiy_node_example.git

Next, navigate to the order_confirmation_call directory:

cd order_confirmation_call

And open the confirmation_call.js file:

confirmation_call.js

3. Configure the call parameters

Replace the value in the Order Confirmation Call code with your actual values for

  • app_id & app_secret

  • music_file

  • customer_number

  • piopiy_number

const { PiopiyAction } = require("piopiy");

export const outgoing = async(req, res) => {
const action = new PiopiyAction();
const music_file = 'https://example.com/your_music_file.wav';

const ngrok_url = "https://ngrok.order.confirmation.io/dtmf";
const agent_number = "agent_phone_number";
const piopiy_number = "piopiy_number";

const options = {
max_digit: 1, // (Optional) Maximum number of digits expected from the user input
max_retry: 1, // (Optional) Maximum number of retry attempts
timeout: 1, // (Optional) Time allowed between DTMF inputs in seconds
}

// Initiate the call
await action.playGetInput(ngrok_url, music_file, options);

await piopiy.voice.call( customer_number, piopiy_number, alert_music_pcmo_function, options )

};

Handling DTMF Input

If the user presses 1, confirmation music is played using the playMusic() function. For any other input, cancellation music is played.

// Set up the server
const express = require("express");
const { outgoing } = require('./outgoing.js')
const app = express();
app.use(express.json());


app.post("/outgoing", outgoing)

app.post("/dtmf", (req, res) => {
const action = new PiopiyAction();
const dtmf = req.body.dtmf; // Assuming DTMF input is in the body of the request

if (dtmf == 1) {
// Music to play if customer confirms the order
action.playMusic("https://example.com/your_confirmation_music.mp3");
} else {
// Music to play if customer cancel the order
action.playMusic("https://example.com/your_order_not_confirmed_music.mp3");
}
res.send(action.PCMO());
});

app.listen(3001, () => {
console.log(`Server is running on port 3001`);
});

Here’s an explanation of each parameter in the PIOPIY:

ParameterValueRequiredData TypeDescription
your_app_id2222XXXYesstringThis refers to the Application ID provided by PIOPIY. Used to identify which application is making the call.
your_app_secretab4cbb8e-xxx-xxxx-xxxx-xxxxxxxxxxxYesstringThis is the APP Secret provided by PIOPIY. It authenticates and authorizes the call, ensuring only authorized apps initiate calls.
agent_phone_number9198765xxxxxYesnumberThis is the agent phone number you want to connect. Typically, it's the number of the person or agent receiving the call.
piopiy_callerid9180314xxxxxYesnumberThis is the Caller ID shown to the second participant. Can be a virtual number provided by PIOPIY.

4. Run the code

Execute the code using Node.js:

node transaction_alert_call/alert_call.js

Sample response

Below is the following sample call response.

{
"data": { "status": 'progress' },
"status": 'progress',
"request_id": 'X0uoi5LT5vCMOG6CZGEdMMYD5RL9raaEFa1p1IQ9EVm',
"cmi_code": 200
}

Properties

These are the list of properties and its description

PropertyTypeDescription
statusstringThe Status of the call.
request_idstringThe Unique ID for this call.

HTTP status codes

cmi_codecmi_code typeDescription
200SuccessWe received the request.
401ErrorAuthentication failed.