Twilio - 将两个呼叫者放在同一个动态生成的会议室中会产生无限循环

时间:2015-01-05 21:09:10

标签: php twilio

我见过一些Twilio专家在使用Twilio的服务之前在这里回答其他问题所以我希望这能引起其中一个人的注意。 :)

基本上,我需要创建一个系统,使两个呼叫者可以连接(销售代理和客户),并具有管理员收听实时呼叫的能力。根据我对Twilio API的研究,我认为实现这一目标的唯一方法是让每个呼叫都成为电话会议,并允许管理员以“静音”模式加入该呼叫,从而只允许他们听取代理之间的呼叫。和客户。

我正在使用PHP进行开发,我相信我已经解决了90%的难题,但是我遇到了一个小细节问题。

我将在下面列出逻辑流程,以便您可以看到我正在尝试做的事情:

1)客户或销售代理拨打号码。

2)会议室动态生成,拨出的人被放入该房间。

3)我使用REST API向另一个号码发出呼叫请求,然后将它们引导到已经由第一个人等待生成的会议室。

我已完成步骤1和2并且正常工作,步骤3是问题发生的地方。当我使用API​​生成第二个呼叫以将另一个人带入会议室时,请求通过用于生成第一个呼叫的相同应用程序,从而创建无限循环来进行新呼叫并生成新房间。我在下面附上了我的代码,以帮助解释这个问题。

public function index()
{
   if (isset($_REQUEST['PhoneNumber'])) {
        // The agent is making a call (outgoing)
        $data['callerId']  = $this->users->getPhoneNumber($_REQUEST['Caller']);
        $userIdExplode = explode(':', $_REQUEST['Caller']);
        $data['userId'] = $userIdExplode[1];
        $callTarget = $this->security->xss_clean($_REQUEST['PhoneNumber']);
        $data['numberOrClient'] = "<Number>" . $callTarget . "</Number>";
        $data['phoneIsOnline']  = $this->users->isPhoneOnline($data['userId']);

        // Call log information
        $data['ani']  = $data['callerId'];
        $data['dnis'] = $callTarget;

    } elseif (isset($_REQUEST['To'])) { 

        // The agent is receiving a call (incoming)
        $callTarget = $this->security->xss_clean($_REQUEST['To']);
        $data['userId'] = $this->users->getIdByPhoneNumber($callTarget);
        $data['numberOrClient'] = "<Client>" . $data['userId'] . "</Client>";
        $data['phoneIsOnline']  = $this->users->isPhoneOnline($data['userId']);

        // Call log information
        $data['ani']  = $_REQUEST['From'];
        $data['dnis'] = $_REQUEST['To'];
    }

    // Log the new call and receive it's log ID
    $data['callLogId'] = $this->call->logNewCall($data['ani'], $data['dnis'], $data['userId']);

    // Load the TWIML (Twilio XML) to bring the caller into a conference room
    $this->load->view('twilio/connections_twiml', $data);

    // Bring the destination number into the same conference room as the origin number 
    $this->dialToConference($data['ani'], $data['dnis'], $data['callLogId']);
}

public function dialToConference($caller, $callee, $confNum) 
{
    // Twilio capability library (capable of incoming and outgoing calls)
    include APPPATH . 'libraries/twilio/Services/Twilio.php';

    // Twilio account codes required for the client
    $accountSid = $this->config->item('twilio_accountSid');
    $authToken  = $this->config->item('twilio_authToken');

    $client = new Services_Twilio($accountSid, $authToken);
    $call = $client->account->calls->create(
        $caller,
        $callee,
        BASE_URL . 'twilio/twilio_connections/loadConferenceTwiml?conferenceId=' . $confNum
    );
}

0 个答案:

没有答案