I have a basic call forward using Twilio's verb, but am running into trouble with voicemail. Instead of the receiving user's personal voicemail, I want to reroute to a Twimlet that records the voicemail and emails it. With my current code, I'm altering the 'timeout' parameter between 3-10 seconds with mixed results. Sometimes the Twimlet voicemail picks up first, and sometimes the call gets picked up then the Twimlet fires off on a live call. Is there some way to detect a voicemail is about to pick up and redirect to the twimlet with consistency?
post '/number/forward/:sid' do
#number = Number.find_by_twilio_sid(params[:sid])
#forward = Number.find_by_parent_id(#number.id)
if #forward.extension == nil
Twilio::TwiML.build do |r|
r.Dial #forward.number, :callerId => #number.number, :timeout => '7', :action => "http://twimlets.com/voicemail?Email=email%40gmail.com&Message=Thank%20you%20for%20calling%2C%20please%20leave%20a%20message.&T", :method => "GET"
end
end
end
Twilio developer evangelist here.
Whilst we do have experimental answering machine detection in the REST API, there is no affordance for that within TwiML. There was another question/answer on SO that answers this better. Please see: Use IfMachine in TwiML when using <Dial>
Related
I've successfully configured Twilio on console as well as in my Salesoforce web application to send SMS to a given(authorized) mobile number. However I'm unable to find the proper way to find
How my clients can reply to the SMSs they receive
How I can retrieve their replies via API to my web application
I felt something called TwiML is related to this but not much clear the process. Can some body guide if you have done some similar implementation?
You can find the answer for how your human clients/customers/users can reply here:
https://www.twilio.com/docs/sms/quickstart/python#install-flask-and-set-up-your-development-environment
Rather than "client", I will use the word "user" to mean client / customer / user / human.
Let me explain what these instructions tell you by example:
The instructions will tell you how to make a bot that can send a human user a text such as "Hi, How Are You?". Then the user can respond with e.g. "I need an espresso.".
Then the bot will detect that that user has sent a response and can reply with a canned answer such as "Oh, okay.".
The instructions are pretty involved, impossible to summarize here, and fairly well written (I just followed them successfully).
However, those instructions are not clear on how to make the bot actually process what the user says, for example respond conditionally based on whether the user says 'yes' or 'no'.
If you want to actually process the contents of the user's message (exemplified as detecting whether they replied 'yes', 'no', or something else, then you can take the run.py they have at the end of their tutorial and modify is like so:
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
import sys
app = Flask(__name__)
#app.route("/sms", methods=['GET', 'POST'])
def sms_ahoy_reply():
"""Respond to incoming messages with a friendly SMS."""
# Start our response
resp = MessagingResponse()
message_body = request.form['Body']
message_body = message_body.strip()
if message_body == "yes":
resp.message("You said yes.")
elif message_body == "no":
resp.message("You said no.")
else:
resp.message("You said neither yes nor no.")
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
I'm basically following the tutorial on https://www.sinch.com/docs/video/javascript/#groupcalling.
I'm able to get things working, however I am unable to end the call. Right now I have 2 browser tabs pretending to be different users joining the same group chat. "onGroupLocalMediaAdded" and "onGroupRemoteCallAdded" do get called, and I can display things fine. But I can't figure out how a user can leave the group chat and ultimately trigger a call to "onGroupRemoteCallRemoved"
The Call class has a "hangup" method, but GroupCall does not.
any ideas?
Use call conference, it will be with a media server, callgroup will try to set up media to each client and will most likely impact your callquality.
http://download.sinch.com.s3.amazonaws.com/docs/javascript/latest/reference/classes/CallClient.html#method_callConference
I think I figured it out. Group Calling is really peer to peer calling. So hanging up means iterating through each call object you received from a peer and calling hangup.
My terminate connection function now contains:
this.remoteCallsMap.forEach( (call) => {
call.hangup();
});
I'm going to play around with call conference as mentioned in the other responses, but figured I'd post the answer in case anyone else plays around with call group and can't figure out how to end the call.
I have used the Google API Ruby client example repo on Github as a starting point for my calendar app.
It works well and usually without issues. Lately, however, I noticed that my app in production does not fetch all events. I present events in a table after a few calendars have been requested through the ruby client. On my initial call there are just the dates which I generate with my app, no data is fetched from the calendars at all. Upon second request some calendars will return data and reloading the app a couple more times all calendars will return events.
So to me it seems like there is some caching going on. If data is not returned quick enough an empty response is sent back to me. Requesting again sends some data and the more I request the more data is returned.
Maybe there is something wrong with my setup which is not perfect I assume:
get '/' do
#fetch all calendars
result = api_client.execute(:api_method => calendar_api.calendar_list.list,
:authorization => user_credentials)
cals = result.data.items.map do |i|
#skip id calendar does not belong to owner or is the "private" primary one
next if i.primary || i.accessRole != "owner"
i.summary
end
cals.compact!
#save all users mentioned in calendars in a set
events_list = result.data.items.map do |i|
#skip calendar if primary or not owned by user (cannot be changed anyway)
next if i.primary || i.accessRole != "owner"
r = api_client.execute(:api_method => calendar_api.events.list,
:parameters => {'calendarId' => i.id},
:timeMax => DateTime.now.next_month,
:timeMin => DateTime.now.beginning_of_month)
#capture all calendars and their events and map it to an Array
r.data.items.delete_if { |item| item.status == "cancelled" }
end
#remove skipped entries (=nil)
events_list.compact!
slim :home, :locals => { :title => Konfig::TITLE, :events_list => events_list, :cals => cals}
end
BTW: :timeMax and :timeMin are not working as expected either but that's a different question I suppose.
Code does not seem to be the issue here.
I would guess one of the following is happening
You are being rate limited? (Unlikely to hit limits with a smaple app but stil easy to check with response codes)
Loading is taking more than 2 seconds (default net http response timeout is 2 seconds and default faraday setup is with net:http)
What would I do in this situation. I would the following before deciding on next steps
Print the response object error codes and http headers in the api client gem from its response object. I would be looking for what is the caching header in response and what is the status code.
If you have ngrep on your production machine, just let it print and show the entire http request response instead of printing it in the gem.
If the response takes more than 2 seconds, increase timeout settings for net::http and check.
I am trying to implement Superfeedr subscriptions using PubSubHubbub and Ruby on Rails. The problem is, the subscriptions are never confirmed, even though my callback prints out the hub.challenge string, which it successfully receives.
def push
feed = Feed.find(params[:id])
if feed.present?
if params['hub.mode'].present? and params['hub.verify_token'] == feed.secret
feed.update_attribute(:is_active, (params['hub.mode'] == 'subscribe'))
render text: params['hub.challenge']
return
elsif params['hub.secret'] == feed.secret
parse(feed, request.raw_post)
end
end
render nothing: true
end
It sets feed.is_active = true, but Superfeedr Analytics shows no sign of subscription.
I am using 1 dyno Heroku hosting and async verification method.
The first thing you should check is the HTTP status code and the response BODY of your subscription request. I expect the code to be 422 to indicate that subscription was failed, but the body will help us know exactly what is going on.
Also, do you see the verification request in the logs?
A common issue with heroku is that if you use hub.verify=sync, you will need 2 dynos, because you have to concurrent requests in this case...
Okay it's a simple task. After I render html to the client I want to execute a db call with information from the request.
I am using sinatra because it's a lightweight microframework, but really i up for anything in ruby, if it's faster/easier(Rack?). I just want to get the url and redirect the client somewhere else based on the url.
So how does one go about with rack/sinatra a real after_filter. And by after_filter I mean after response is sent to the client. Or is that just not dooable without threads?
I forked sinatra and added after filters, but there is no way to flush the response, even send_data which is suppose to stream files(which is obviously for binary) waits for the after_filters.
I've seen this question: Multipart-response-in-ruby but the answer is for rails. And i am not sure if it really flushes the response to the client and then allows for processing afterwards.
Rack::Callbacks has some before and after callbacks but even those look like they would run before the response is ever sent to the client here's Rack::Callbacks implementation(added comment):
def call(env)
#before.each {|c| c.call(env) }
response = #app.call(env)
#after.each {|c| c.call(env) }
response
#i am guessing when this method returns then the response is sent to the client.
end
So i know I could call a background task through the shell with rake. But it would be nice not to have too... Also there is NeverBlock but is that good for executing a separate process without delaying the response or would it still make the app wait as whole(i think it would)?
I know this is a lot, but in short it's simple after_filter that really runs after the response is sent in ruby/sinatra/rack.
Thanks for reading or answering my question! :-)
Modified run_later port to rails to do the trick the file is available here:
http://github.com/pmamediagroup/sinatra_run_later/tree/master