我已集成 Twilio 可编程语音。现在我正在尝试让客户端从浏览器进行调用,并使用 Twilio JS Client 接收对浏览器的调用。当我尝试调用电话时,它说。
message: "Capability token is not valid or missing."
我也搜索了互联网和 Twilio 文档,但没有任何帮助。这是我的代码。
查看
<button onclick="callCustomer('{{ '+xxxxxxxx' }}')" type="button" class="btn btn-primary btn-lg call-customer-button">
Call customer
</button>
Controller
public function newToken(Request $request) {
// Required for all Twilio access tokens
$twilioAccountSid = 'ACxxxxxxxxx';
$twilioApiKey = 'SKxxxxxxxxxxx';
$twilioApiSecret = 'xxxxxx';
$outgoingApplicationSid = 'APxxxxxxxxxxx';
$identity = "Jhon_Doe";
$token = new AccessToken(
$twilioAccountSid, $twilioApiKey, $twilioApiSecret, 3600, $identity
);
$voiceGrant = new VoiceGrant();
$voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);
$voiceGrant->setIncomingAllow(true);
$token->addGrant($voiceGrant);
return $token->toJWT();
}
JS
function callCustomer(phoneNumber) {
$.get("/token", {forPage: window.location.pathname}, function (data) {
console.log(data);
const device = new Twilio.Device();
device.setup(data);
var params = {"phoneNumber": phoneNumber};
device.connect(params);
});
}
我尝试从 jwt.io 调试工具调试我的 token ,它显示:
Invalid Signature.
我确信我错过了一些东西,但不知道是什么。任何帮助或提示将不胜感激。
最佳答案
我已经弄清楚了,只是发布答案以供将来引用。问题出在 twilio js 版本上。我已经包含了导致问题的旧版本。迄今为止的最新版本是版本:1.13。此版本中已弃用功能 token ,现在使用访问 token 。
关于jwt - 功能 token 无效或丢失 Twilio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65420708/