I'm implementing a two-way call functionality in ColdFusion using SignalWire's API, but the call gets triggered twice, and both participants cannot hear any audio.
ColdFusion API Request Code:
<cffunction name="signalWireTwoWayCalling" access="remote" returnformat="json">
<cfargument name="toNumber" type="string" required="false">
<cfset var response = {}>
<!--- SignalWire API credentials --->
<cfset spaceURL = ";>
<cfset projectID = "YOUR_PROJECT_ID">
<cfset authToken = "YOUR_AUTH_TOKEN">
<cfset fromNumber = "+1**********">
<cfset arguments.toNumber = "+1*********">
<!--- Construct the API URL --->
<cfset apiUrl = spaceURL & "/api/laml/2010-04-01/Accounts/" & projectID & "/Calls.json">
<!--- Webhook URL for call handling --->
<cfset callHandlerUrl = ".cfm?toNumber=" & arguments.toNumber>
<!--- Prepare the request body --->
<cfset requestBody = {
"To" = arguments.toNumber,
"From" = fromNumber,
"Url" = callHandlerUrl
}>
<cfset requestBodyJson = serializeJSON(requestBody)>
<cfhttp url="#apiUrl#" method="post" result="httpResponse">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="Authorization" value="Basic #toBase64(projectID & ':' & authToken)#">
<cfhttpparam type="body" value="#requestBodyJson#">
</cfhttp>
<cfset responseData = deserializeJSON(httpResponse.FileContent)>
<cfreturn responseData>
</cffunction>
Call Handling (callHandler.cfm
):
<cfprocessingdirective suppresswhitespace="yes">
<cfcontent type="text/xml">
<cfparam name="url.toNumber" default="+16507626368">
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number>#url.toNumber#</Number>
</Dial>
</Response>
</cfoutput>
</cfprocessingdirective>
Issue:
- Two calls are triggered instead of one.
- No audio is transmitted; both participants cannot hear each other.
Things Tried:
- Verified that the API response is successful.
- Confirmed that
callHandler.cfm
returns valid XML. - Tested different phone numbers, but the issue persists.
Questions:
- Am I incorrectly handling the
Dial
request incallHandler.cfm
? - Is there something missing in the way I initiate the call via
cfhttp
? - How can I ensure only one call is triggered and that participants can hear each other?
Would appreciate any guidance. Thanks!