I have a script using Node.js that will display input digits entered by a user using Vonage in the telegram bot and under the message there are two buttons I want to handle them when click correct I want the conversation to continue in this code after pressing yes the call end.
I try with chatGPT he gives me these two functions vonage.voice.update and vonage.voice.updateCall but I think they are in the old version.
const { Vonage } = require("@vonage/server-sdk");
const express = require("express");
const app = express();
const TelegramBot = require("node-telegram-bot-api");
app.use(express.json());
const axios = require("axios");
const vonage = new Vonage({
apiKey: "apiKey",
apiSecret: "apiSecret",
applicationId: "applicationId",
privateKey: "privateKey",
});
app.get("/webhook/answer", (req, res) => {
// Create NCCO with greeting message
const { status } = req.body;
if (status === "answered") {
// Send message "The receiver answered"
bot.sendMessage(chatId, "The receiver answered");
return;
}
const ncco = [
{
action: "talk",
bargeIn: true,
text: `Hello Sir , press 1 to continue `,
},
{
action: "input",
maxDigits: 1,
timeOut: 10,
eventUrl: [
"event_url",
],
},
];
res.json(ncco);
});
vonage.voice
.createOutboundCall({
to: [{ type: "phone", number: phoneNumberTo }],
from: { type: "phone", number: phoneNumberFrom },
answer_url: [
"answer_url",
],
})
.then((response) => {
const activeCallUUID = response.uuid; // Store the active call UUID
console.log("Outbound call created successfully:", activeCallUUID);
// Use the activeCallUUID for further processing or store it in a suitable location
})
.catch((error) => {
console.error("Error making outbound call:", error);
});
app.post("/webhook/dtmf", (req, res) => {
const dtmfDigits = req.body.dtmf;
if (dtmfDigits.length === 6) {
ncco = [{
action: 'talk',
text: 'Please wait while we connect you to',
bargeIn: true,
},
{
action : "conversation",
name : conversationName,
startOnEnter : false,
musicOnHoldUrl : ["mp3_url"]
}
]
bot.sendMessage(chatId, `DTMF digits entered: ${dtmfDigits}`, {
reply_markup: {
inline_keyboard: [
[{ text: "Correct", callback_data: `correct:${req.body.uuid}` }],
[{ text: "Not Correct", callback_data: "not_correct" }],
],
resize_keyboard: true,
},
});
console.log(ncco);
res.json(ncco);
}
res.status(200).end();
bot.on("callback_query", (query) => {
const callbackData = query.data;
const [callbackAction, callUUID] = callbackData.split(":");
if (callbackAction === "correct") {
}
});
});
I want when I press the button correct the call continues and I want a new talk start exp "please wait" and audio start. thank you so much