H dog
09/03/2024, 3:18 AMVapi
09/03/2024, 3:19 AMVapi
09/03/2024, 3:19 AMH dog
09/03/2024, 3:35 AMChowderr
09/03/2024, 3:40 AMH dog
09/03/2024, 3:41 AMH dog
09/03/2024, 3:41 AMChowderr
09/03/2024, 3:42 AMH dog
09/03/2024, 3:42 AMH dog
09/03/2024, 3:43 AMH dog
09/03/2024, 3:43 AMChowderr
09/03/2024, 3:44 AMShubham Bajaj
09/03/2024, 7:47 PMH dog
09/04/2024, 5:50 AMShubham Bajaj
09/04/2024, 3:06 PMts
export default async function DeleteHandler(req: Request, res: NextApiResponse) {
if (req.method === "POST") {
try {
const body = await req.json();
const { callSid, accountSid, authToken } = body
if (!callSid) {
throw new Error('No callSid provided')
}
const basicAuthToken = Buffer.from(`${accountSid}:${authToken}`).toString('base64')
const response = await fetch(`https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Calls/${callSid}.xml`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${basicAuthToken}`,
},
// body: 'Twiml=<?xml version="1.0" encoding="UTF-8"?><Response><Hangup/></Response>',
body: new URLSearchParams({ Status: 'completed' }),
})
if (!response.ok) {
throw Error(
`Couldn't Hang Up Twilio Call. Status: ${response.status}`
);
}
return NextResponse.json(
{ message: "Succesfully hangup outbound call" },
{ status: 200 }
);
} catch (error: any) {
return NextResponse.json(
{
message: "Failed to hangup outbound call",
error: error?.message,
},
{ status: 500 }
);
}
} else {
res.setHeader('Allow', ['POST']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}