在过去的12个月中,我的团队一直在使用这种基本的电话会议逻辑,并且非常享受拥有按使用量付费的基本电话会议系统。
https://www.twilio.com/docs/voice/tutorials/how-to-create-conference-calls-ruby
我想将其移至twilio函数中,以便我们的应用程序可以不受干扰。毕竟,我们的应用需要执行任何操作
我的代码具有2个Web回调函数:
# 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
加入gathers
个会议室,而CONNECT实际上将您连接到会议。我已经下载了两个发送到服务器的XML文档,并将它们放入存储桶中。
答案 0 :(得分:1)
这里是Twilio开发人员的传播者。
您绝对可以将这两种方法编写为Twilio Functions。不过,您需要将代码从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);
}
您的/ connect端点:
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路径。
让我知道是否有帮助。