Jadi saya punya kode berikut:

<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '../vendor/autoload.php'; // Loads the library
use Twilio\Jwt\TaskRouter\WorkerCapability;

// Your Account Sid and Auth Token from twilio.com/user/account
$accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

$capability = new WorkerCapability($accountSid, $authToken, $workspaceSid);
$capability->allowFetchSubresources();
$capability->allowActivityUpdates();
$capability->allowReservationUpdates();
$token = $capability->generateToken();
// By default, tokens are good for one hour.
// Override this default timeout by specifiying a new value (in seconds).
// For example, to generate a token good for 8 hours:
$token = $capability->generateToken(28800);  // 60 * 60 * 8
?>
<script type="text/javascript" src="//media.twiliocdn.com/taskrouter/js/v1.20/taskrouter.min.js"></script>
<script>
    var workspace = new Twilio.TaskRouter.Workspace("<?= $token ?>");
</script>

Kode PHP menghasilkan token dengan baik tetapi JS menghasilkan kesalahan berikut:

WebSocket connection to '...' failed: Error during WebSocket handshake: Unexpected response code: 403

Ada ide ada apa dengan itu?

Terima kasih!

1
neubert 28 Mei 2020, 23:40

1 menjawab

Jawaban Terbaik

Anda sedang menyiapkan WorkerCapability di JWT Anda tetapi mencoba menggunakannya dengan objek SDK Workspace. Saya yakin Anda harus menggunakan token WorkspaceCapability jika Anda ingin membuat instance objek Workspace dari SDK.

2
Blaise Swanwick 1 Juni 2020, 19:41