using twilio am making conference room. I successfully created the conference between two users. But i can't able to get conference sid from twilio. Can any one please help me in that.
twiml1 = Twilio::TwiML::Response.new do |r|
r.Say "You have joined the conference."
r.Dial do |d|
d.Conference "#{conference_title}",
waitUrl: " ",
muted: "false",
startConferenceOnEnter: "true",
endConferenceOnExit: "true",
maxParticipants: 5,
end
end
This is how am connecting connecting conference in between two user.
Twilio developer evangelist here.
You don't get the parameters for the Conference SID at this point because you could well be creating the conference with the return of this TwiML. Instead, there are a couple of other ways to get the SID.
Conference events
With the statusCallback attribute on the <Conference> element you can set a URL to receive various events as webhooks regarding the conference (pick those events with the statusCallbackEvent attribute). You could listen for the start event and you will receive the Conference SID as a parameter in the webhook request.
Checking the REST API
Otherwise, you can make an API call to the REST API Conference resource.
You can search for your conference by the name you give it. For example, you can search for the conference called "MyRoom" using the following Ruby (if you have the twilio-ruby gem installed):
#client = Twilio::REST::Client.new YOUR_ACCOUNT_SID, YOUR_AUTH_TOKEN
# Loop over conferences and print out the SID for each one
#client.account.conferences.list({
:status => "in-progress",
:friendly_name => "MyRoom"}).each do |conference|
puts conference.sid
end
Let me know if that helps at all.
[edit]
An example of the statusCallback in Rails.
First I'm going to adjust the TwiML you used initially:
twiml1 = Twilio::TwiML::Response.new do |r|
r.Say "You have joined the conference."
r.Dial do |d|
d.Conference "#{conference_title}",
waitUrl: " ",
muted: "false",
startConferenceOnEnter: "true",
endConferenceOnExit: "true",
maxParticipants: 5,
statusCallback: "/conferences/callback",
statusCallbackEvent: "start"
end
end
I've added the statusCallback attribute with a path to an action in your Rails application (you can use whatever path you want, I just made this up for now). I also added the statusCallbackEvent attribute with the value "start". There are other events available, but to get the SID, the start event will do.
Now we need an action to receive that callback.
class ConferencesController < ApplicationController
def callback
# Do something with the conference SID.
Rails.logger.info(params["ConferenceSid"])
render :nothing => true
end
end
You'll need to point a POST route at that controller action too, but I'll leave that up to you to sort out.
Related
I would like to enable the listener to press * key to ask for unmuting during a conference call, with the moderator able to unmute him/her from a console.
I have a controller with the following :
def conference_connect
#room_name = flash[:room_name]
#room_id = flash[:event_id]
case params['Digits']
when "1" # listener
#muted = "true"
when "3" # moderator
#moderator = "true"
end
response = Twilio::TwiML::VoiceResponse.new
response.say(voice: 'alice', language: 'en-US', message: 'You are in, press * at anytime to ask a question')
dial = Twilio::TwiML::Dial.new(hangupOnStar: true)
dial.conference(#room_name,
wait_url: "http://twimlets.com/holdmusic?xxxxxxx&",
muted: #muted || "false",
start_conference_on_enter: #moderator || "false",
end_conference_on_exit: #moderator || "false",
)
gather = Twilio::TwiML::Gather.new(action: '/redirectIntoConference?name= ' + #room_name, digits: 1)
response.append(dial)
end
I have the following error :
No template found for TwilioController#conference_connect, rendering head :no_content
I would like to send a message to the moderator (or update some params) to notify him that a listener has a question to ask.
Twilio developer evangelist here.
You have a couple of issues here. Firstly, your error is because you are not returning the TwiML you built in your controller action and Rails is looking for a template instead.
At the end of the action call render like this:
response.append(dial)
render xml: response.to_xml
end
As for requesting to speak on * you are halfway there. Firstly, the <Gather> is not going to help you, so get rid of the line:
gather = Twilio::TwiML::Gather.new(action: '/redirectIntoConference?name= ' + #room_name, digits: 1)
Instead, you have hangupOnStar set to true in your <Dial> this will disconnect the user from the conference (which sounds bad, but is what you want for this). You just need to setup what happens to the user after they hangup.
In this case, you want to make the request to the moderator and then have them rejoin the conference. You do this with an action parameter on the <Dial> that points to a URL that will be requested when the caller leaves the conference.
Within this action you need to somehow alert your moderator (I'm not sure how you're planning that) and then return TwiML to enter the caller back into the conference. Don't forget to set the conference up in the same way, with hangupOnStar and an action.
Ulitmately your action should look a bit like this:
def conference_connect
#room_name = flash[:room_name]
#room_id = flash[:event_id]
case params['Digits']
when "1" # listener
#muted = "true"
when "3" # moderator
#moderator = "true"
end
response = Twilio::TwiML::VoiceResponse.new
response.say(voice: 'alice', language: 'en-US', message: 'You are in, press * at anytime to ask a question')
dial = Twilio::TwiML::Dial.new(hangupOnStar: true, action: '/redirectIntoConference?name= ' + #room_name)
dial.conference(#room_name,
wait_url: "http://twimlets.com/holdmusic?xxxxxxx&",
muted: #muted || "false",
start_conference_on_enter: #moderator || "false",
end_conference_on_exit: #moderator || "false",
)
response.append(dial)
render xml: response.to_xml
end
Let me know if that helps at all.
I want the code below to hangup if I don't get a valid response within 5 seconds after the "last chance" message. I've set :timeout to 11. The call should end in 10 seconds, (excluding the time to ask the questions). The 1st question is asked and waits 5 seconds before asking the 2nd. I want the call to hangup after the 2nd g.pause. I've tried r.hangup in the main block and g.hangup in the gather block. Neither of those worked for me. How should it be done?
def digits
twiml_response = Twilio::TwiML::Response.new do |r|
r.Gather numDigits: '1', timeout: 11, action: communications_menu_path do |g|
g.Say "Please press one to continue", voice: 'alice', language: 'an-AU'
g.Pause length: 5
g.Say "Last chance. I didn't get any response. Please press one to continue.", voice: 'alice', language: 'an-AU'
g.Pause length: 5
end
end
render :xml => twiml_response.to_xml
end
Twilio developer evangelist here.
When your <Gather> times out it will still make the request to your action attribute. However, the Digits parameter to that request will be empty.
So, instead of hanging up in this part of the TwiML, during your next TwiML (under communications_menu_path) you should check if the Digits parameter is present but empty and then hang up. Something like:
def communications_menu
if params["Digits"] && params["Digits"].blank?
render :xml => Twilio::TwiML::Response.new { |r| r.Hangup }.to_xml
else
# the rest of the TwiML
end
end
Let me know if that helps at all.
I'm currently trying to connect two users via twillio and am masking their identities. I am doing this by having:
User A dials my Twillio # ---> hits my app URL endpoint --> dials User B and has the call ID show up as my Twillio #
When trying this, the TwiML is being rendered with the dialed/forwarded number always blank. Even when I hardcode it, Twillio never forward the call anywhere.
def make_twillio_call_PSTN
incoming_number = params[:From]
#strip +1 from number
incoming_number = incoming_number.byte_slice(2,10)
response = Twilio::TwiML::Response.new do |r|
r.Dial callerId: MY_TWILIO_MOBILE do |d|
d.Number MY_NUMBER
end
render xml: response.to_xml
end
end
I am using this gem for payments in paypal https://github.com/tc/paypal_adaptive
I am very confused and disoriented with this gem. It has a poorly documented and is difficult for me to understand how to get the data from paypal on ipn response.
I hope this question will help more people having the same problem.
My steps are:
1º I send request to paypal from my orders_controller.rb with method preaproval_payment.
def preapproval_payment
preapproval_request = PaypalAdaptive::Request.new
data = {
"returnUrl" => response_paypal_user_orders_url(current_user),
"cancelUrl"=> cancel_payment_gift_url(#gift),
"requestEnvelope" => {"errorLanguage" => "en_US"},
"senderEmail" => "gift_1342711309_per#gmail.com",
"startingDate" => Time.now,
"endingDate" => Time.now + (60*60*24) * 30,
"currencyCode"=>"USD",
"maxAmountPerPayment" => "#gift.price",
"ipnNotificationUrl" => ipn_notification_url,
"ip" => request.remote_ip
}
preapproval_response = preapproval_request.preapproval(data)
puts data
if preapproval_response.success?
redirect_to preapproval_response.preapproval_paypal_payment_url
else
redirect_to gift_url(#gift), alert: t(".something_was_wrong")
end
end
2º These are the data of my request in my log console from command puts data :
{"returnUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders/response_paypal", "cancelUrl"=>"http://localhost:3000/en/gifts/gift-1/cancel_payment", "requestEnvelope"=>{"errorLanguage"=>"en_US"}, "senderEmail"=>"gift_1342711309_per#gmail.com", "startingDate"=>2012-07-29 13:05:49 +0200, "endingDate"=>2012-08-28 13:05:49 +0200, "currencyCode"=>"USD", "maxAmountPerPayment"=>9, "ipnNotificationUrl"=>"http://localhost:3000/ipn_notification?locale=en", "ip"=>"127.0.0.1"}
3º I redirect to paypal page, and I make the payment on paypal successfully :D.
4º When payment is completed successfully, I am directed to:
http://localhost:3000/en/u/maserranocaceres/orders/response_paypal
I have response_paypal action in orders_controller.rb. It is GET action and my code for this action is:
def response_paypal
respond_to do |format|
format.html { redirect_to user_orders_url(current_user), :alert => "works fine return url"}
end
end
Up to this point everything works fine.
Now what I need is to get the data I received from paypal and save my database a new order if payment is successfully processed.
5º For this purpose I make a file in lib/paypal_ipn.rb and I add to this file the content from https://github.com/tc/paypal_adaptive/blob/master/templates/paypal_ipn.rb
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
class PaypalIpn
def self.call(env)
if env["PATH_INFO"] =~ /^\/paypal_ipn/
request = Rack::Request.new(env)
params = request.params
ipn = PaypalAdaptive::IpnNotification.new
ipn.send_back(env['rack.request.form_vars'])
if ipn.verified?
#mark transaction as completed in your DB
output = "Verified."
else
output = "Not Verified."
end
[200, {"Content-Type" => "text/html"}, [output]]
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
end
end
end
In my routes.rb I add:
match "/ipn_notification" => PaypalIpn
My 2 problems are:
a) I do not see that after making the payment this file to be fired and I can not see in my console data I get from paypal.
b) I want to send to paypal in my request, the id of object #gift for being able to recover later in paypal_ipn.rb and to save my database.
What am I doing wrong and how I can solve these problems?
Thank you
I haven't used that gem, but I've used PayPal IPN before. Here are some things you should check:
Do you have your PayPal account set up to use IPN? You must enable this setting on the account for this to work.
Have you verified that when you pass ipn_notification_url during the payment process, that it matches your "/ipn_notification" route?
For this to work, PayPal must be able to communicate directly with the server that is running this app. This means that typically, unless you have a custom setup on your local machine with dynamic DNS or something, that you will need to actually deploy this code to a server in order for PayPal to be able to communicate with your app. In other words, if this is running on http://localhost:3000, this will not work.
To answer your second question, how to recover #gift in order to record the fact it was paid in your database, I'm not entirely sure how to do it with this gem, but I'll tell you how I do it using ActiveMerchant - it is probably quite similar.
In your payment request to PayPal, you can pass in an invoice number. I believe the field is just called "invoice". Here you would pass the ID of the gift.
When PayPal notifies your app via IPN that the order was paid for, it will pass the invoice number back to you. Retrieve the #gift using this invoice number and then you can do what you need with it.
Here are the relevant parts of my working PayPal code, using the ActiveMerchant gem: https://gist.github.com/3198178
Good luck!
Has anyone had success in resubscribing an email address after being unsubscribed via the Campaign Monitor API.
I ask as i want to keep a list of Active User's email addresses in my CM Active List. When they are suspended they get removed, when they join or pay their fees before getting deleted they are (re)subscribed.
Looking at the Rails API docs:
# File lib/campaign_monitor.rb, line 241
def remove_subscriber(email)
response = #cm_client.Subscriber_Unsubscribe("ListID" => #id, "Email" => email)
Result.new(response["Message"], response["Code"].to_i)
end
# File lib/campaign_monitor.rb, line 445
def unsubscribe(list_id)
response = #cm_client.Subscriber_Unsubscribe("ListID" => list_id, "Email" => #email_address)
Result.new(response["Message"], response["Code"].to_i)
end
On the CM website to move an email in the subscriber list to the active list you need to confirm you have permission to resubscribe them, can anyone say for sure that this applies to the API too?
I've just found the Subscriber.AddAndResubscribe method, undocumented in http://campaignmonitor.rubyforge.org/