Making a Call with PCMO Actions
First you've completed the initial setup, the most important step is to But a PIOPIY number. After configuring the number, the customer can initiate a call to the PIOPIY number, and the system will first play the configured music, and then the call will be forwarded to the agent's number.
- Node.js
- Python
1.Prerequisites
Before you start, ensure you have the following:
2.Clone the repository
Use the git clone command to clone the PIOPIY node from our TeleCMI github repository.
git clone https://github.com/telecmi/piopiy_node_example.git
First, clone this repository to your local machine:
cd piopiy_node_example
3.Install the piopiy npm package
Once inside the project directory, install the required npm packages:
npm install
4.Code
const express = require("express");
const { PiopiyAction } = require("piopiy");
const app = express();
app.use(express.json());
app.post("/pcmo", (req, res) => {
const action = new PiopiyAction();
const agent_number = "Your agent phone number"; // Your agent phone number with country code.
const piopiy_number = "Your piopiy number"; // Your piopiy number provided by the Piopiy TeleCMI platform.
const options = { duration: 10, timeout: 20, loop: 1, record: true };
action.playMusic("https://example.com/your_music_file.wav");
action.call(agent_number, piopiy_number, options);
res.send(action.PCMO());
});
app.listen(3001, () => { console.log(`Server is running on port 3001`) })
5.Configure the call parameters
Replace the value in the Basic Call code with your actual values for
6.Run the code
Execute the code using Node.js:
node sdk_example/inbound_call/call_with_pcmo.js
7.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://inbound.basic.call.ngrok.io
.
8. Configure the Answer URL
Enter the ngrok URL into the answer URL field. For example, if your ngrok URL is https://inbound.basic.call.ngrok.io
, set the answer URL to:
https://inbound.basic.call.ngrok.io/pcmo
Then click the MAP APP button to configure it successfully.
9. Make an Incoming Call with PCMO
Once everything is set up, have the customer make an incoming call. The system will first play the configured music, and then the call will be forwarded to the agent's number.
1.Prerequisites
Before you start, ensure you have the following:
2.Clone the repository
Use the git clone command to clone the PIOPIY Python example from our TeleCMI GitHub repository.
git clone https://github.com/telecmi/piopiy_python_example.git
First, clone this repository to your local machine:
cd piopiy_python_example
3.Install the required packages
Once inside the project directory, create a virtual environment and install the required packages:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
pip install -r requirements.txt
4.Code
from flask import Flask, request, jsonify
from piopiy import Action
app = Flask(__name__)
@app.route('/pcmo', methods=['POST'])
def inbound_call():
action = Action()
agent_number = "Your agent phone number" # Your agent phone number with country code.
piopiy_number = "Your piopiy number" # Your piopiy number provided by the Piopiy TeleCMI platform
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
}
# Play a music file during the call
action.playMusic('https://example.com/your_music_file.wav')
# Initiate the call to the agent's number
action.call(agent_number, piopiy_number, options)
# Return the response in JSON format
return jsonify(action.PCMO())
if __name__ == '__main__':
app.run(port=5000, debug=True)
5.Configure the call parameters
Replace the value in the Basic Call code with your actual values for
6.Run the code
Execute the code using Python:
python sdk_example/inbound_call/call_with_pcmo.py
7.Create a public URL using ngrok
To expose your local server to the internet, use ngrok to create a public URL:
ngrok http 5000
Copy the URL provided by ngrok. This URL will look something like https://inbound.basic.call.ngrok.io
.
8.Configure the Answer URL
Enter the ngrok URL into the answer URL field. For example, if your ngrok URL is https://inbound.basic.call.ngrok.io
, set the answer URL to:
https://inbound.basic.call.ngrok.io/pcmo
Then click the MAP APP button to configure it successfully.
9. Make an Incoming Call with PCMO
Once everything is set up, have the customer make an incoming call. The system will first play the configured music, and then the call will be forwarded to the agent's number.