I seem to always be getting a "line busy" when using redirectCall. Can someone help me figure out if I'm doing something wrong? I was able to answer the call just fine and reject it, but redirecting is not working.
I've tried:
Here's Microsoft's documentation I'm referring to: https://learn.microsoft.com/en-us/azure/communication-services/how-tos/call-automation/actions-for-call-control?tabs=javascript#redirect-a-call
import { NextApiRequest, NextApiResponse } from 'next';
import { CallAutomationClient } from '@azure/communication-call-automation';
class SubscriptionValidationEventData {
validationUrl: string;
validationCode: string;
}
//const callbackUri = "redacted";
const client = new CallAutomationClient(process.env.COMMUNICATION_SERVICES_CONNECTION_STRING as string);
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.headers['aeg-event-type'] === 'SubscriptionValidation') {
try {
const eventData: SubscriptionValidationEventData = req.body[0].data;
console.log(`Got SubscriptionValidation event data, validationCode: ${eventData.validationCode}, validationUrl: ${eventData.validationUrl}`);
const responseData = {
validationResponse: eventData.validationCode,
};
return res.status(200).json(responseData);
} catch (error) {
console.error('Error handling SubscriptionValidation event:', error);
return res.status(500).json({ error: 'Internal server error.' });
}
}
if (req.body[0].eventType && req.body[0].eventType === 'Microsoft.Communication.IncomingCall') {
const incomingCallContext = req.body[0].data.incomingCallContext;
console.log('Heres the incoming number', req.body[0].data.from.phoneNumber.value)
console.log('Heres the incoming call context', incomingCallContext)
const callerIdNumber = { phoneNumber: req.body[0].data.from.phoneNumber.value };
const target = {
targetParticipant: { phoneNumber: "+1xxxxxxxxxx" },
sourceCallIdNumber: callerIdNumber,
};
await client.redirectCall(incomingCallContext, target);
res.status(200).json([]);
}
return res.status(404).json({ error: 'Not found.' });
}
I'm expecting it to ring another number, but it's getting "Line busy" every time.
I had Receive calls enabled, but not Make calls in the phone number in ACS.