twilio功能是否涵盖twilio电话会议应用程序的基本用例?
在过去的12个月里,我的团队一直在使用这种基本的电话会议逻辑,并且非常喜欢使用按次付费的基本电话会议系统 我想把它转移到twilio功能中,这样我们的应用程序就可以不碍事了。毕竟,我们的应用程序需要做任何事情,这有点奇怪 我的代码有两个web回调函数:twilio功能是否涵盖twilio电话会议应用程序的基本用例?,twilio,Twilio,在过去的12个月里,我的团队一直在使用这种基本的电话会议逻辑,并且非常喜欢使用按次付费的基本电话会议系统 我想把它转移到twilio功能中,这样我们的应用程序就可以不碍事了。毕竟,我们的应用程序需要做任何事情,这有点奇怪 我的代码有两个web回调函数: # frozen_string_literal: true module Api class ConferencesController < WebhooksController TWILIO_API_HOST = 'htt
# frozen_string_literal: true
module Api
class ConferencesController < WebhooksController
TWILIO_API_HOST = 'https://api.twilio.com'
before_action :set_client_and_number, only: [:start_call_record, :broadcast_send, :fetch_recordings, :conference]
# GET /conference
def conference
@conference_number = @twilio_number
end
# POST /join
def join
response = Twilio::TwiML::VoiceResponse.new
gather = Twilio::TwiML::Gather.new(action: 'connect')
gather.say("Please Enter The Three Digit Conference Number", voice: 'female')
response.append(gather)
render xml: response.to_s
end
def connect
code = params['Digits']
digits = code.to_s.each_char.to_a
pronounceable_code = digits.join(" ")
response = Twilio::TwiML::VoiceResponse.new
response.say("You entered #{pronounceable_code}. You will now join the conference.", voice: 'female')
dial = Twilio::TwiML::Dial.new
dial.conference(code)
response.append(dial)
render xml: response.to_s
end
private
def set_client_and_number
@client = Twilio::REST::Client.new(ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN'])
@twilio_number = ENV['TWILIO_NUMBER']
end
end
end
#冻结的字符串文字:true
模块Api
类ConferencesController
JOIN
收集一个会议室并连接实际上将您连接到会议。我已经下载了发送到服务器的两个XML文档,并将它们放入存储桶中 这里是Twilio开发者福音传道者
您完全可以将这两个方法编写为。不过,您需要将代码从Ruby转换为Node.js
下面是一个快速(未经测试)的翻译,应该可以帮助您开始
您的初始端点,/加入原始代码:
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
const gather = twiml.gather({
action: '/connect'
});
gather.say({ voice: 'female' }, 'Please Enter The Three Digit Conference Number');
callback(null, twiml);
}
您的/连接端点:
exports.handler = function(context, event, callback) {
const code = event.Digits;
const pronounceableCode = code.toString().split('').join(' ');
const twiml = new Twilio.twiml.VoiceResponse();
twiml.say({ voice: 'female' }, `You entered ${pronounceableCode}. You will now join the conference.`);
const dial = twiml.dial();
dial.conference(code);
callback(null, twiml);
}
确保在创建函数时注意使用的URL路径
如果有任何帮助,请告诉我。看起来不错。回调响应应该像ruby api响应那样返回XML吗?没关系!我刚刚发现documentationTwilio函数将检测twiml对象,然后将其序列化为XML,并使用Twilio函数自动设置内容类型:text/XML
,一旦所有处理(包括异步工作)完成,您将使用返回内容调用回调
函数。如果是Twilio.twiml.VoiceResponse
或MessagingResponse
的实例,则会将内容类型设置为text/xml
,并将对象转换为其字符串/xml表示形式。回调函数有两个参数,第一个是如果有错误,第二个是内容。哦,还有一件事。您的第一个端点实际上只是静态XML,所以您可以作为一个端点来完成。这将节省函数的任何调用成本。