[英]How to use Twilio Proxy in Node.js
I've been trying for 3 days to properly setup a backend that will connect two phones anonymously for voice calling, with the help of Twilio.在 Twilio 的帮助下,我已经尝试了 3 天来正确设置一个后端,该后端将匿名连接两部手机进行语音通话。 This is what I'm trying to do:
这就是我想要做的:
I've watched the live coding example and it doesn't work, at all.我看过现场编码示例,但它根本不起作用。
$ irb $ irb
require 'twilio-ruby' client = Twilio::REST::Client('...', '...') client.service.create(friendly_name: 'Test 1 ') NoMethodError: undefined method `service' for #
require 'twilio-ruby' client = Twilio::REST::Client('...', '...') client.service.create(friendly_name: 'Test 1 ') NoMethodError: undefined method `service' for #
Ok ok, the video is from 2 years ago, it's fair that the SDK changed.好吧好吧,视频是2年前的,SDK改了是公平的。 So I followed the interactive tutorial that is available in the website, this one.
所以我遵循了网站上提供的交互式教程,这个教程。
Before continuing... there is a dedicated page about the new Proxy feature, and in one of the sections there is the following image:在继续之前......有一个关于新代理功能的专用页面,在其中一个部分中有下图:
This is clearly Python, so here I go... I've installed the Python SDK, started a REPL and tried to follow the code... it doesn't work.这显然是 Python,所以我开始了……我已经安装了 Python SDK,启动了 REPL 并尝试遵循代码……它不起作用。 Damn Twilio, update your things!
该死的 Twilio,更新你的东西! (Or am I the stupid here?)...
(还是我是这里的傻瓜?)...
Anyway... let's jump into the node.js tutorial , I'm sure at least the interative tutorial is working (so I thought).无论如何...让我们进入node.js 教程,我确定至少交互式教程正在运行(所以我想)。
So, I went to my console and created a service there, then I wrote the code:所以,我去了我的控制台并在那里创建了一个服务,然后我写了代码:
import twilio from 'twilio'
const client = twilio('accountSid', 'authToken')
async function test() {
// create session
const session = await client.proxy.services('<MY_SERVICE>')
.sessions
.create({uniqueName: 'MyFirstSession'})
// add participant 1 to session
client.proxy.services('<MY_SERVICE>')
.sessions(session.sid)
.participants
.create({ friendlyName: 'Me', identifier: '<my_number>'})
// add participant 2 to session
client.proxy.services('<MY_SERVICE>')
.sessions(session.sid)
.participants
.create({ friendlyName: 'Me 2', identifier: '<my_number_2>'})
}
test()
Then what?然后呢?
The docs say:文档说:
If your Twilio Phone Numbers are voice capable, you're now ready for a proxied voice conversation. Following the names from the previous steps, get Alice to make a call to her Proxy Identifier number. Twilio's Proxy service will then make a call from Bob's Proxy Number to his real number and connect the two calls.
It doesn't work... I've tried to call to the proxy identifier number, and it doesn't work.它不起作用......我试图调用代理标识符号,但它不起作用。
I'm not sure what to do anymore, I've tried to reach out to them, nobody replies...我不知道该怎么办了,我试图与他们联系,但没有人回复......
I looked at the "node.js tutorial" and I can see how that can be confusing.我查看了“node.js 教程”,我可以看到它是如何令人困惑的。
Here is what you can do to get this working and get a better understanding of how it works:您可以采取以下措施来使其工作并更好地了解其工作原理:
Prerequisites:先决条件:
Step 2.第2步。
Step 3.第 3 步。
Step 4.第四步。
Step 5.第 5 步。
This is the step where you add the participants, which is about your two phone numbers.这是您添加参与者的步骤,这是关于您的两个电话号码。 This part can't be done on the Twilio's console as far as I know.
据我所知,这部分无法在 Twilio 的控制台上完成。 I did it running Node.js code.
我在运行 Node.js 代码时做到了。
You need to have Node.js installed on your computer ( https://nodejs.org/en/ ), then:您需要在您的计算机上安装 Node.js ( https://nodejs.org/en/ ),然后:
npm init --yes
npm init --yes
npm install twilio
npm install twilio
index.js
index.js
here is the code for index.js这是 index.js 的代码
const accountSid = 'ACxxxxx...'; const authToken = 'xxxxx...'; const client = require('twilio')(accountSid, authToken); client.proxy.services('KSxxxxx...') .sessions('KCxxxxx...') .participants .create({ friendlyName: 'Alice', identifier: '+19997775555' }) .then(participant => console.log(participant.proxyIdentifier));
In the code above, replace the values for在上面的代码中,替换值
accountSid
// your Twilio account sid accountSid
// 你的 Twilio 账户 sidauthToken
// your Twilio auth token authToken
// 您的 Twilio 身份验证令牌KSxxxxx...
// the service id KSxxxxx...
// 服务idKCxxxxx...
// the session id KCxxxxx...
// 会话 ID+19997775555
// your first phone number +19997775555
// 您的第一个电话号码Next run this code to add the first participant, in the Terminal run node index.js
接下来运行此代码以添加第一个参与者,在终端运行
node index.js
Last thing is to add the second participant, in the code above change the Alice
to let's say Bob
and also replace your first phone number
with your second phone number, then run node index.js
again.最后一件事是添加第二个参与者,在上面的代码中,将
Alice
更改为Bob
,并将your first phone number
替换为您的第二个电话号码,然后再次运行node index.js
。
After you added the second participant, you're ready.添加第二个参与者后,您就准备好了。 Now you can try to call or text your Twilio phone number (which acts as a proxy) from any of your numbers (phones) and the other of your numbers (phones) will receive a text or ring.
现在,您可以尝试从您的任何号码(电话)拨打您的 Twilio 电话号码(充当代理)或发送短信,而您的其他号码(电话)将收到短信或铃声。
Good Luck!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.