Order Confirmation Call
- Node.js
- Python
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:
Parameter | Value | Required | Data Type | Description |
---|---|---|---|---|
your_app_id | 2222XXX | Yes | string | This refers to the Application ID provided by PIOPIY. Used to identify which application is making the call. |
your_app_secret | ab4cbb8e-xxx-xxxx-xxxx-xxxxxxxxxxx | Yes | string | This is the APP Secret provided by PIOPIY. It authenticates and authorizes the call, ensuring only authorized apps initiate calls. |
agent_phone_number | 9198765xxxxx | Yes | number | This is the agent phone number you want to connect. Typically, it's the number of the person or agent receiving the call. |
piopiy_callerid | 9180314xxxxx | Yes | number | This 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
}
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_python_example.git
Next, navigate to the order_confirmation_call directory:
cd order_confirmation_call
And open the confirmation_call.py file:
confirmation_call.py
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
from flask import Flask, request, jsonify
from piopiy import RestClient, Action
app = Flask(__name__)
# Initialize RestClient with your App ID and Secret
piopiy = RestClient("your_app_id", "your_app_secret")
action = Action()
music_file = 'Your order confimation music file or music file URL' # Your order confimation music file or music file URL
ngrok_url = 'http://ngrok.order.confirmation.io/dtmf' # Add your local ngrok URL
customer_number = "Your customer number" # Your customer phone number with country code
piopiy_number = "Your piopiy number" # Your piopiy number provided by the Piopiy TeleCMI platform
order_confimation_pcmo_function = action.PCMO() # Use this PCMO function to confirm your order input
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
action.playGetInput(ngrok_url, music_file, options)
try:
response = piopiy.voice.call(customer_number, piopiy_number, order_confimation_pcmo_function)
print('Success response:', response)
except Exception as error:
print('Error:', error)
# Set up the webhook server
@app.route('/dtmf', methods=['POST'])
def dtmf():
action = Action()
dtmf = request.json.get('dtmf') # Assuming DTMF input is in the body of the request
if dtmf == 1:
action.playMusic("Your example order confirmation music file or music file URL")
return jsonify(action.PCMO())
else:
action.playMusic("Your example order cancellation music file or music file URL")
return jsonify(action.PCMO())
if __name__ == '__main__':
app.run(port=3001, debug=True)
4. Run the code
Execute the code using python:
python transaction_alert_call/alert_call.py
Properties
These are the list of properties and its description
Property | Type | Description |
---|---|---|
status | string | The Status of the call. |
request_id | string | The Unique ID for this call. |
HTTP status codes
cmi_code | cmi_code type | Description |
---|---|---|
200 | Success | We received the request. |
401 | Error | Authentication failed. |