Skip to main content

Inbound Call Center

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 inbound_call_center directory:

cd inbound_call_center

And open the inbound_call.js file:

inbound_call.js

3. Configure the call parameters

Replace the value in the Inbound Call Center code with your actual values for

  • agent_phone_number

  • piopiy_callerid

const express = require("express");
const { PiopiyAction } = require("piopiy");
const app = express();
app.use(express.json());

app.post("/inbound-call", (req, res) => {
const action = new PiopiyAction();

const agent_phone_number = ["agent_phone_number", "agent_phone_number", "agent_phone_number"]; // Multiple agent's phone number with country code
const piopiy_callerid = "piopiy_callerid"; // Your piopiy number provided by the Piopiy TeleCMI platform.

const options = {
duration: 10, // (Optional) Maximum duration of the call in seconds
timeout: 20, // (Optional) Time to wait for the call to be answered
loop: 1, // (Optional) Number of retry attempts if the call is not answered
ring_type: "group", // (Optional) Type of ringing for the call.
};

action.call(agent_phone_number, piopiy_callerid, options);
res.send(action.PCMO());
});

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

4. Run the code

Execute the code using Node.js:

node inbound_call_center/inbound_call.js

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.

5. Create a public URL using ngrok

To expose your local server to the internet, use ngrok to create a public URL:

ngrok http 3001

Copy the URL provided by ngrok. This URL will look something like https://customer.to.delivey.agent.ngrok.io.

6. Configure Piopiy dashboard

Log in to your Piopiy dashboard and paste the ngrok URL into the "Answer URL" input field. Ensure that the endpoint is set correctly to handle inbound calls.

https://customer.to.delivey.agent.ngrok.io/inbound

7. Expected Call Flow

When the code is executed, the call will follow these steps:

1.Initial call to Call Masking Number: The call is initiated from the customer to the call masking number.

2.Call received by Delivery Agent: The delivery agent receives the call via the call masking number.