簡體   English   中英

當我撥打我的 twilio 號碼時,twilio/voice-sdk 不收聽來電監聽器

[英]twilio/voice-sdk does not listen incoming call listener when I call on my twilio number

我在以下版本中使用以下堆棧

拉維 (9.11)
vue.js (2.x)
PHP (8.1.0) twilio/語音-sdk (2.1.1)
twilio/sdk (6.37)

我的應用程序的工作流程:
我正在使用任務路由器為語音呼叫建立一個入站聯絡中心,客戶從他/她的電話發起呼叫到我們的聯絡中心基本號碼(+1 873 --- 0331)
步驟1
當用戶撥打此號碼 (+1 873 --- 0331) 時,使用以下 IVR 代碼調用語音 webhook

public function webhookForContactCenterBaseNumber(Request $request)
    {
        $response = new VoiceResponse();
        $params = array();
        $params['action'] = secure_url('/api/webhook-for-contact-center-ivr');
        $params['numDigits'] = 1;
        $params['timeout'] = 10;
        $params['method'] = "POST";

        $gather = $response->gather($params);

        $gather->say('For Spanish, please press one.', ['language' => 'es']);
        $gather->say('For Enghlish,please press two.', ['language' => 'en']);

        return $response;
    }

第2步

When the user presses A digit(1/2) I create a task with workflow via the task router
 public function webhookForContactCenterIvr(Request $request)
    {
        $response = new VoiceResponse();
        $digits = $request['Digits'];
        $language = $digits == 1 ? 'es' : 'en';

        switch ($digits) {
            case 1 || 2:
                $response->enqueue(null, [
                    'waitUrl' => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.classical',
                    'workflowSid' => 'WW456fb07f4fdc4f55779dcb6bd90f9273'
                ])
                    ->task(json_encode([
                        'selected_language' => $language,
                    ]));
                break;
            default:
                $response->say("Sorry, Caller. You can only press 1 for spanish, or 2 for english.");
                break;
        }

        return $response;
    }

第三步

創建任務后,我使用標簽“空閑”從控制台手動設置目標代理,然后調用 webhook。 根據文檔,通過 Twilio 呼叫者 ID 在呼叫者和代理 Twilio 電話號碼之間創建了橋接呼叫

public function assigment(Request $request)
    {

        $assignment_instruction = [
            'instruction' => 'dequeue',
            'post_work_activity_sid' => 'WA92871fe67075e6556c02e92de6---924',
            'from' => '+1647---4676' // a verified phone number from your twilio account
        ];


        return $this->respond($assignment_instruction, ['Content-Type', 'application/json']);
    }

通話記錄:
在此處輸入圖像描述


第4步


namespace App\Http\Controllers\Api;

use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VoiceGrant;
use Illuminate\Http\Request;
use Twilio\Rest\Client;

class TwilioController extends ApiController
{

    // Required for all Twilio access tokens
    private $twilioAccountSid;
    private $twilioAccountAuthToken;
    private $twilioApiKey;
    private $twilioApiSecret;
    private $identity;


    public function __construct()
    {
        $this->twilioAccountSid = config('general.twilio_account_sid');
        $this->twilioAccountAuthToken = config('general.twilio_auth_token');

        $this->twilioApiKey = 'SK45e57c57f923e5c3c0903f48b70ba9de';
        $this->twilioApiSecret = 'uqDNnlnDZbWZCKBwlmMdlMIIonhh3X3K';
        // choose a random username for the connecting user
        $this->identity = 'daffdfwerweds';
    }

    public function getCallAccessToken()
    {
        $token = new AccessToken(
            $this->twilioAccountSid,
            $this->twilioApiKey,
            $this->twilioApiSecret,
            3600,
            $this->identity
        );

        // Create Voice grant
        $voiceGrant = new VoiceGrant();

        // Optional: add to allow incoming calls
        $voiceGrant->setIncomingAllow(true);

        // Add grant to token
        $token->addGrant($voiceGrant);

        return $this->respond([
            'status' => true,
            'message' => '',
            'data' => [
                'accessToken' => $token->toJWT()
            ]
        ]);
    }





    public function getTwilioKey($frindlyName)
    {

        $twilio = new Client($this->twilioAccountSid, $this->twilioAccountAuthToken);
        return $twilio->newKeys->create(["friendlyName" => $frindlyName]);
    }
    public function getKeys()
    {
        $twilio = new Client($this->twilioAccountSid, $this->twilioAccountAuthToken);
        $keys = $twilio->keys
            ->read(20);

        foreach ($keys as $record) {
            $twilio->keys($record->sid)
                ->delete();
        }
    }
    public function getAllCalls(Request $request)
    {
        $twilio = new Client($this->twilioAccountSid, $this->twilioAccountAuthToken);
        $calls = $twilio->calls
            ->read([], 20);

        foreach ($calls as $record) {
            // print($record->sid);
            $twilio->calls($record->sid)
                ->delete();
        }
    }
}

第 5 步我已經在 vue 中安裝了 twilio/voice-sdk 並使用以下代碼注冊了我的設備


    const accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzQ1ZTU3YzU3ZjkyM2U1YzNjMDkwM2Y0OGI3MGJhOWRlLTE2NTU3MzgxNjMiLCJpc3MiOiJTSzQ1ZTU3YzU3ZjkyM2U1YzNjMDkwM2Y0OGI3MGJhOWRlIiwic3ViIjoiQUMwMWExYTRmMDdjMGMwMDlhMmIyZTEyYmJkZWVhYjQ2NSIsImV4cCI6MTY1NTc0MTc2MywiZ3JhbnRzIjp7ImlkZW50aXR5IjoiZGFmZmRmd2Vyd2VkcyIsInZvaWNlIjp7ImluY29taW5nIjp7ImFsbG93Ijp0cnVlfX19fQ.4COIn-EQMQnD6alKUSOZPGIWG3jB5k17K418xCsSiZs"

    const device = new Device(accessToken, {
      logLevel: 1,
      // Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and
      // providing better audio quality in restrained network conditions.
      codecPreferences: ["opus", "pcmu"]
    });

    const handleSuccessfulRegistration = () => {
      console.log('The device is ready to receive incoming calls.')
    }

    device.register();
    device.on('registered', handleSuccessfulRegistration);


    device.on('error', (twilioError, call) => {
      console.log('An error has occurred: ', twilioError);
    });

    device.on('incoming', call => {
      console.log('call received-----------------')
    });

在 jwt.io 上驗證令牌

在此處輸入圖像描述




在控制台中測試設備注冊:
在此處輸入圖像描述

我遇到了同樣的問題,感謝您提供詳細信息,我仔細檢查了整個細節,這是解決該問題后的答案,

在步驟 #4 中,您正在創建呼叫訪問令牌,並且您正在添加工作人員/代理身份,您需要在 Twilio 控制台內添加一些針對工作人員的身份,在您的情況下,它應該是這樣的,在代碼中

$this->identity = 'daffdfwerweds';

在 task router/workspace/workers/open target work 下的 Twilio 控制台中

最重要的部分

{contact_uri":"client:daffdfwerweds"}

如果這個worker向你呼叫路由器,你的瀏覽器會通過SDK監聽來電。 就這樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM