question

geoffsm avatar image
geoffsm asked

Can not answer incoming call because it is outbound? PHP API

Abbreviated php webhook code below. API is V2.7.1 PHP is version 7. In the call.initiated event, it verifies that direction = incoming, retrieves the call object, and attempts to answer the call. call.answer() throws "(Code 90102) Can not issue an answer command on an outbound call".

The same logic flow is given as one of the python examples. What is it I don't know?

if ($event=='call.initiated') { $direction = $payload['direction']; if ($direction=="incoming") { $to = $payload['to']; if ($to==$TelnyxVoxNumber1) { $connectionId = $payload["connection_id"]; $callControlId = $payload["call_control_id"]; $call = \Telnyx\Call::retrieve($callControlId); error_log("Group5VoiceHook.php CALL: " . print_r($call, true)); $call->answer(); $call->transfer(['id' => $connectionId, 'to' => $transferNumber]); }
} }

call-controlwebhooksphp
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

geoffsm avatar image
geoffsm answered

OK, I got this figured out. Ignore the message, it maybe makes sense internally, but not in context.

A number can be connected to an Application or to a SIP profile. In both cases you will receive the same web hooks. But you can only issue an answer command (any command) to a number that is connected to an Application.

1 comment
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

klane@telnyx.com avatar image klane@telnyx.com ♦♦ commented ·

Thanks for sharing the solution! As a way of showing our appreciation I have added $10 credit to your Telnyx account.

0 Likes 0 ·
geoffsm avatar image
geoffsm answered

Not an answer, just tided up the code sample

   if ($event=='call.initiated') { 
     $direction = $payload['direction']; 
     if ($direction=='incoming') { 
       $to = $payload['to']; 
       if ($to==$TelnyxVoxNumber1) {           
         $connectionId = $payload['connection_id']; 
         $callControlId = $payload['call_control_id']; 
         $call = \Telnyx\Call::retrieve($callControlId);  
         error_log("Group5VoiceHook.php CALL: " . print_r($call, true)); 
         $call->answer(); 
         $call->transfer(['id' => $connectionId, 'to' => $transferNumber]); 
         }
       } 
     }
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Manage Your Content