Tropo has a scripting engine using which we can write code in scripting language for voice and sms applications. e.g. the python code to answer a call looks like,
answer()
say("thanks for calling")
transfer("tel:+1xxxxxxxxxx")
hangup()
Is there something similar available for Twilio. I see that they have Python wrapper over their SDK using which one can do something similar. But I need to find out if there is something similar that Twilio has.
Thanks,
gg
If you need to do anything dynamic (respond in different ways based on who is calling), you'll need to provide Twilio with a URL, and then respond with TwiML at that URL.
You can create TwiML with Python with the helper library: Creating TwiML with twilio-python
If you are responding to every call in the same way (eg a static reply), Twilio has Twimlets you can use to create small snippets of functionality, like say a message and then dial a new number. You can host Twimlets with Twilio, so you don't need your own server.
Related
I have a very simple question about gathering DTMF inputs from users via an outbound call made to them. I am describing the requirement below.
Main Requirement
I have a python script that makes outbound calls to a particular number. The person accepts the call. I say the information to them via the twiml configured. The person hears the info and presses a key on their phone. I want to capture that key input and just print it as an output using my script.
The problem
I am able to make the outbound call using the client.calls.create method described here. https://www.twilio.com/docs/voice/tutorials/how-to-make-outbound-phone-calls-python
But I am unable to gather the digits. The examples I have seen online are describing how to achieve gathering inputs with a running web application. I am NOT using this method.
I am looking to get this done via a simple script. I initiate the outgoing call from the Twilio number via the script. I don't intend to use any web applications or webhooks here.
I am putting the code below that works until making the call and reciting the options to the user.
How can I get this done? Is this possible? Many thanks.
import os
from twilio.rest import Client
from twilio.twiml.voice_response import Gather, VoiceResponse, Say
account_sid = os.environ['TWILIO_ACCOUNT_SID']='XXXXX'
auth_token = os.environ['TWILIO_AUTH_TOKEN']='YYYYY'
client = Client(account_sid, auth_token)
call = client.calls.create(
twiml='<?xml version="1.0" encoding="UTF-8"?><Response><Gather input="dtmf" timeout="5" numDigits="1"><Say>Please press 1 for sales</Say></Gather></Response>',
to='Destination_Number',
from_='My_Twilio_Number'
)
#TODO - How to Gather Digits from the user????
Twilio developer evangelist here.
There are many ways to interact with a phone call through Twilio, but when you are trying to take user input through <Gather> all of them require Twilio to be able to notify you of the digits that the user pressed. Since this is an asynchronous action, the basic method of doing so is via a webhook, an HTTP request, sent to a web application that you control.
If you do not want to host an application that responds to webhooks yourself, you could achieve this flow using Twilio Studio, which is a drag and drop editor for communications flows, or using Twilio Functions, which is a serverless environment where you can respond to incoming HTTP requests with JavaScript functions.
I am using twilio to manage our IVR, to handle SMS, and for a few other things. After a user calls and goes through the IVR (for example they press 2 for sales or they say they want extension 205) I need it to hand off to Asterisk.
Setting up the trunk isn't my issue. I need to somehow tag it so asterisk knows how to handle the call. If they chose ext 205 on twilio, I need asterisk to automatically ring ext 205.
I am using a minimal version of asterisk basically for sip registration and voicemail and the rest is done by twilio.
Does anyone know if there is a way to do this in code? Or is my best bet to create a different trunk for each extension. That seems like it would get messy.
Correct solution is make IVR on asterisk. This solution also will be MUCH less costly.
But if you really want... On twilio setup via SIP tag
https://www.twilio.com/docs/voice/twiml/sip
set url to sip:0000+exten#your_asterisk_ip
On asterisk setup trunk to twilio server or allowguest=yes and default context to 'goext'
After that goext context something like this
[goext]
exten => _0000XXX,1,Set(ext=${EXTEN:4})
same => n,Dial(SIP/${ext},,o)
0000 replace with some random code, that required for prevent bots calls when allowguest=yes.
I have written a simple Twilio Function to forward calls to one of my two cell phones numbers A and B. Occasionally I want to tell the function to stop forward to A and start forwarding to B, or vice versa.
Can I do this programmatically via the Twilio API? E.g. can environment variables, usually set in Functions -> Configure, be set via the Twilio API? Or can I update the Function's code itself via the Twilio API?
If not, must I resort to hosting my code on a 3rd party server, or is there another way to programmatically change what is essentially a global variable for a Twilio Function without manual intervention?
Twilio developer evangelist here.
Sadly there is no Functions API to update Functions in this way, yet.
However, may I suggest a workaround for this scenario. You can create two Twilio functions one which forwards to number A and the other which forwards to number B. You can then use the Incoming Phone Numbers resource to update your Twilio number's voice URL to point to the Function you need.
Let me know if that helps at all.
I have a Twilio softphone that I am implementing and the basics functions are working great.
Please I would need to know how to implement a multi line call feature.
I would like to allow a agent in my browser softphone to put a call on hold and dial a different number then resume any call on hold when needed.
I actually have
Thank You
I am using twilio right now by writing a python script and hosting that with ngrok. When I visit the webpage hosted and view the source, I just see TwiML. Is it possible to just write TwiML w/o code?
Twilio employee here.
Of course you can! If you want to, you can just link the URL to an xml file that you've written and stored on your server - no programmatic generation of the TwiML is required.
One of the simplest ways is to write some plain TwiML on TwiMLbin and just link to the public url for it.
Twilio is just looking for an XML string response to the request it sends - it doesn't care or understand how you generate it.