lib/fluent/plugin/out_twilio.rb in fluent-plugin-twilio-0.1.0 vs lib/fluent/plugin/out_twilio.rb in fluent-plugin-twilio-0.1.1

- old
+ new

@@ -9,10 +9,11 @@ config_param :account_sid, :string config_param :auth_token, :string, secret: true config_param :from_number, :string, default: '' config_param :default_number, :string, default: '' config_param :default_voice, :string, default: 'woman' + config_param :default_message, :string, default: nil config_param :language, :string, default: 'ja-jp' VOICE_MAP = ['man', 'woman'] def configure(conf) @@ -22,26 +23,27 @@ def process(tag, es) es.each do |time,record| number = record['number'].nil? ? @default_number : record['number'] @voice = VOICE_MAP.include?(record['voice']) ? record['voice'] : @default_voice - call(number, record['message']) + message = record['message'] || @default_message + call(number, message) end end def call(number, message) - response = Twilio::TwiML::Response.new do |r| - r.Say message, voice: @voice, language: @language + response = Twilio::TwiML::VoiceResponse.new do |r| + r.say(message, voice: @voice, language: @language) end - xml = response.text.sub(/<[^>]+?>/, '') + xml = response.to_s.sub(/<[^>]+?>/, '') url = "http://twimlets.com/echo?Twiml=#{URI.escape(xml)}" log.info "twilio: generateing twiml: #{xml}" client = Twilio::REST::Client.new(@account_sid, @auth_token) - account = client.account + account = client.api.account number.gsub(' ', '').split(',').each do |to_number| begin - account.calls.create({from: @from_number, to: to_number, url: url}) + account.calls.create(from: @from_number, to: to_number, url: url) rescue => e log.error "twilio: Error: #{e.message}" end end end