【问题标题】:Basic Case : System will call person A. If person A picks up the phone it will call person B and the 2 will be connected基本情况:系统会呼叫A。如果A拿起电话,它将呼叫B并且2将被连接
【发布时间】:2021-11-21 23:51:34
【问题描述】:

    


   const accountSid = 'ACf36...'
   const authToken = '094...'
   const client = require('twilio')(accountSid, authToken)
   const VoiceResponse = require('twilio').twiml.VoiceResponse;

   client = Client()

   twiml = VoiceResponse()
  twiml.dial('+912345674127')
  call = client.calls.create(
  from_ = '+14809078750',
  to = '+916395545354',
  twiml = str(twiml),
  )
  console.log(call)

我正在尝试使用此代码和 twilio 的拨号功能进行电话会议。

【问题讨论】:

  • 来自 Twilio 的文档:You can initiate an outbound call by POSTing to the Call resource, creating a new call. You can also initiate a call from an active call (e.g., forwarding to another number or dialing into a conference) by including TwiML’s <Dial> verb in your TwiML application. However, the only way to initiate a call directly from Twilio is with an API request. 参考:* twilio.com/docs/voice/api/call-resource * twilio.com/docs/voice/twiml/conference#examples-5

标签: node.js twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

首先,您的问题中似乎包含了您的 Account SID 和 Auth Token。这些凭据可以完全访问您的帐户,并且公开发布它们意味着遇到它们的任何人都可以使用它们来滥用您的帐户。以后请不要这样做,change your auth token using this process

现在,您发布的代码对于在通话中连接两个人来说并不遥远。 console.log 不会记录调用对象,因为client.calls.create 的结果是解析为调用的 Promise。另外,str 不是 JavaScript 函数。

尝试以下方法:

const twilio = require('twilio');
const client = twilio(accountSid, authToken);
const VoiceResponse = twilio.twiml.VoiceResponse;

const twiml = new VoiceResponse();
twiml.dial('+912345674127');

client.calls.create({
  from: '+14809078750',
  to: '+916395545354',
  twiml: twiml.toString()
})
  .then(call => {
    console.log(call);
  })
  .catch(error => {
    console.log(error);
  });

如果您想创建一个可以加入 2 人以上的电话会议,那么您还有一些工作要做。在电话会议中,会议充当人们加入的房间。因此,当一个人连接到会议时,您需要使用 API 生成一个新的呼出呼叫以将另一个人连接到会议。 how to create conference calls with Twilio 有一个教程,我推荐你去看看。

【讨论】:

  • 我使用了您提供的上述代码,但出现类型错误
  • twiml = twiml.toString(), ^ TypeError: 赋值给常量变量。
  • 啊,那段代码看起来像是 Python 和 JavaScript 的混合体。我现在已经更正了它,所以它现在应该适用于 JavaScript。我已经编辑了我的答案,再试一次:)
  • 非常感谢您的帮助。谢谢。
  • 不客气!如果答案有帮助,请将其标记为正确,以便其他人也可以看到它有用。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多