如何使用twilio Node.js添加经过验证的来电显示

时间:2017-08-09 01:02:21

标签: node.js twilio

嘿伙计们我正在尝试使用Twilio并将经过验证的号码添加到我的列表中。到目前为止,它只是我自己的,但我正在尝试使用它的文档说:

var accountSid = 'AC2394ac048859f6b48e7cdf630c29e631';
var authToken = "your_auth_token";
var Client = require('twilio').RestClient

var client = new Client(accountSid, authToken);


client.outgoingCallerIds.create({
    friendlyName: "My Home Phone Number",
    phoneNumber: "+14158675309"
}, function(err, callerId) {
if(err){
    console.error(err);
  } else {
    console.log(callerId.sid);
  }
});

添加它们,但我得到的只是这个错误说:

ReferenceError: client is not defined
client.outgoingCallerIds.list({ phoneNumber: "+14158675309" }, function(err, data) {

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

我不确定你在Twilio模块上调用RestClient的位置,但如果你可以分享,我会尝试清除它。

您可以直接将您的帐户详细信息传递给模块本身,而不是致电RestClient。要list your outgoing caller IDs,您可以执行以下操作:

const accountSid = 'your_account_';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.outgoingCallerIds.list({ phoneNumber: '+14158675309' }, function(callerId) {
  console.log(callerId.phoneNumber)
});

让我知道这是否有帮助。

修改

创建新的拨出呼叫者ID

要通过API验证新的传出呼叫者ID,您需要做两件事,让API请求创建新的传出呼叫者ID,然后显示接收呼叫的用户必须输入的结果代码。电话验证。

你是这样做的:

const accountSid = 'your_account_sid';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.outgoingCallerIds
  .create({
    phoneNumber: '+14158675309',
  })
  .then(function(callerId) {
    // somehow display the validation code
    console.log(callerId.validationCode);
  });
相关问题