How to trigger "input on call" widget on Twilio REST API - twilio

I am trying to setup an IVR where I have number for outlets nearby. So I will make an automate call and it will ask owner to press 1,2 in case of shop is open or close respectively.
I am not able to make a call over here.
curl -X POST https://studio.twilio.com/v2/Flows/F***********/Executions --data-urlencode "To=+9196******" --data-urlencode "From=+120*********" -u "AC****:8****"
This is how I am triggering. Also, Is it possible to validate the number in the flow and check if the number is cell phone then message would trigger and if it is landline then voicemail/call will trigger and get the respective input?

Related

How do I get the conversation SID using data from Messaging Monitor screen?

I have an old Conversation's Channel ACTIVE with my phone number, so the incoming messages are not entering the Studio's flow. I need the Conversation's Channel SID so I can close that channel using the API Explorer.
The only data I have is that the message was received using the Monitor>Messaging screen in Twilio Console.
Monitor Image description
But I don't find an API that I can use to get the SID I need with the data I have
Right now, I built a bash script to fetch all conversations and (when the script finishes) I will grep the whatsapp number to find the conversation SID.
#!/bin/bash
ACCOUNT_SID=ACXXXXXXXXXXXXXXXXX
AUTH_TOKEN=XXXXXXXXXXXXX
PAGE_SIZE=100
DOWNLOAD_PAGES=1000
CURRENT_PAGE=${DOWNLOAD_PAGES}
DOWNLOAD_DIR=downloaded_channels
rm -rf ${DOWNLOAD_DIR}
mkdir -p ${DOWNLOAD_DIR}
while (( ${CURRENT_PAGE} >= 0 )); do
echo "downloading Page ${CURRENT_PAGE}"
curl 'https://conversations.twilio.com/v1/Conversations' -u ${ACCOUNT_SID}:${AUTH_TOKEN} > ${DOWNLOAD_DIR}/page_${CURRENT_PAGE}.json
sleep 0.1
(( CURRENT_PAGE=$CURRENT_PAGE-1 ))
done
The problem with this approach is that I have thousands (if not millons) of conversations and Twilio's API allow result pages of 100 elements max. So if I'm not lucky to find my conversation in the first downloaded pages, I will be here forever.
Does anyone know a better approach for this?
If you're using the Conversations API, you can use the Participants Conversations API to search by your address on Twilio and get all conversation assigned to your number.
Follow the documentation of API: https://www.twilio.com/docs/conversations/api/participant-conversation-resource
Follow an example using the Twilio CLI:
twilio api:conversations:v1:participant-conversations:list --address "whatsapp:+myNumber" --properties conversationSid,conversationState --no-limit
If you're using the Programmable Chat, doesn't have an API to search by your phone, but you can search all and use a filter to get just the Channels with your number on attributes (The process can during a long time depending of the quantity of conversations in your account).
Follow an example using the Twilio CLI:
twilio api:chat:v2:services:channels:list --service-sid <service_sid> --properties sid,attributes --no-limit | grep myNumber
I hope that it can help you! :D
Twilio fanatic here.
According to the Conversation resource page, as you are using CURL you can specify the request parameters in the request URL, similar to how you would using Twilio's native API functions (read()).
From the Conversation Resource documentation (modified to include State and DateCreated parameters):
curl -X POST "https://conversations.twilio.com/v1/Conversations" \
--data-urlencode "State=active" \
--data-urlencode "DateCreated=>=YYYY-MM-DD" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Please be sure to urlencode the DateCreated parameter as it includes non-URL friendly symbols (>= to reference on or after- I am not sure if the written format is suitable for bash as-is).
You may use any of the 10 available Conversation parameters to specify which Conversations are returned. As stated, one or more lines or variable names may not be suited for your application as-is, but with a bit of finagling should produce the result you're looking for. For example, DateModified or looking for a custom value placed under attributes might suit your case better.
If this helps, please upvote. I am trying to get noticed by Twilio and get hired to fulfill my dream of working while RVing fulltime.

gerrit - query command with multiple numbers

How to query gerrit with multiple gerrit numbers? for example, I have two gerrit with number 1234 and 5678, I wish use one query url to list all gerrits!
Maybe something like below:
http://codereview.com/a/q={1234,5678}
This is helpful, I can share one link to others for multiple gerrits review!
Use the following URL in your browser:
http://codereview.com/q/1234+OR+5678
The following command gets the information you want using the REST API:
curl --user USER:PASS --request GET "http://codereview.com/a/changes/?q=1234+OR+5678"

Can Twilio IVR record a single answer?

I'm looking to build an integration with Twilio and here's a brief outline of what I want to do:
1) Prompt the caller with a numeric (verbal FTW) menu of options
- "Press 1 for X, 2 for Y"
2) Prompt the caller to leave a recording
- e.g., "Leave a message and press # or hang up"
3) Access a recording (mp3) of JUST the answer for #2
Thanks
Twilio developer evangelist here.
You can absolutely do that! In order to do so, you'll need to provide a series of URLs that respond with TwiML to tell Twilio what to do with the call.
Firstly, you'll need to set up a Twilio number so that an incoming call is directed to your first webhook URL. You'll need to do this in your Twilio console.
Then, your first webhook URL needs to produce the menu of options. This is typically called an IVR and we have a couple of tutorials that show you how to build one in depth here: IVR: Screening and Recording and IVR Phone tree (I've linked to the Ruby/Rails versions of the tutorials here, but there are other languages available, just check the tutorials page).
Essentially though, you need to use the <Say> and <Gather> verbs from TwiML to read out the options and respond to the results. For example:
<Response>
<Gather numDigits="1" action="/gather_results">
<Say voice="alice">Dial 1 to leave a message, Dial 2 to hangup</Say>
</Gather>
</Response>
The action attribute on the <Gather> element points to where the caller should be directed once they enter a digit. At that point you need to write something dynamic that extracts the Digits parameter from the request. If the number responds to the recording action then you can use the <Record> verb to record just that answer.
I've written the below as if it were using Sinatra and Ruby, but hopefully it shows how this would be used in any language.
def gather_results
if params["Digits"] == "1"
"<Response finishOnKey='#'>
<Say voice="alice">Leave a message and press # or hang up</Say>
<Record action="/record_results"></Record>
</Response>"
else
# Do something else
end
end
Finally, you need something to get the recording once it is complete. This final URL lives at the endpoint described in the action attribute for the <Record> verb. This URL will receive extra parameters that refer to the recording, including the URL of the recording file itself. You can write any code you like here, either just saving the URL of the recording or downloading the file itself.
Hope this helps, let me know if there's anything that isn't clear.

Twilio: Making conference name dynamic with REST apis

I am working on making conference calls from twilio client using REST apis.
I am using java helper libraries to call each participants and as they accept they are put to the same conference room. I am successful up to this. The code which returns the xml for conference, I have put in python following the code of server.py present in android sdk.
Currently in server.py I have hard coded the conference name, i.e anyone who tries for a conference will end up in same conference room.
So I want to make it dynamic. I want to pass the conference name from my java code to the url where server.py and the conference xml is present.
I have tried the following.
I tried adding one extra parameter to the call parameters as
callParams.put("To", user); // Replace with a valid phone number
callParams.put("ConfName", "kevin");
callParams.put("From", my_twilio_num); // Replace with a valid phone number in your account
callParams.put("Url", "https://dyno-name-conference.herokuapp.com/conference");
final Call call = callFactory.create(callParams);
where ConfName is my intended conference name. and I tried to retrieve it in server.py like
ConfName = request.values.get('ConfName')
response.dial(callerId=caller_id).conference(ConfName)
But the ConfName is not getting retrieved.
Is there a better approach for this.
I thought of passing an extra parameter along with the url as I see from the answer here. But I am not successful in that too.
May I know if there any correction in above approaches or a different approach for this..
Thanks in advance.
I managed to get it work.
I used the url as
call__Params.put("Url", "https://dyno-name-conference.herokuapp.com/conference?conf_name=kevin");
and in server.py I accessed it as
conf_name = request.values.get('conf_name')

Twilio call transfer from in-call

I'm not finding a definite answer from the Twilio docs on this. I'm trying to build a phone system that can place the other party on hold while in-call and only from the phone. Example: There are two agents working with me out in the field. I get a call on my mobile (away from a computer) and find that the other agent would need to speak to the person I'm on the phone with. I would like to be able to press something into the phone that would either directly transfer the other person to the agent, or place them in a queue. I could then call the other agent and he could retrieve the person from the queue. All of which would need to happen just from our phones.
I've found some documentation on this, but it seems to all require me to be at a computer, which wont be possible.
Is this even possible with Twilio?
Twilio evangelist here.
This sounds like it might be a good place to use some <Conference>s.
Lets define the actors in your scenario: Agent1, Agent2, Field.
Lets say that Field calls Agent1. Instead of connecting the two directly with a <Dial> you could <Dial> Field into a <Conference> (lets call it ConferenceA), then use the REST API to initiate an outbound call to Agent1. When they answer <Dial> them into the same <Conference>. The system will need to grab the CallSid's of both Agent1 and Field, as well as the Sid of the <Conference>, persist them in some type of storage to use later.
Using <Conference> in this scenario gives you more flexibility to manipulate each leg of the call independent of the other than you would have if you use <Dial> to connect Field and Agent1.
So now Agent2 calls Field. Agent2 would go through the same process, just in reverse. Agent2 would get dialed into a <Conference> (lets call it ConferenceB) and your system would use the REST API to call Field. When Field answers they get <Dial>ed into the same conference as Agent2. Again, the system will need to grab the CallSid's of both Agent2 and Field, as well as the Sid of the <Conference>, persist them in some type of storage to use later.
Now, Field needs a way to tell the system to connect Agent2 with Agent1. To do that you can utilize the <Dial>s hangupOnStar attribute in the TwiML you hand Twilio when you dial Field into the ConferenceB. The <Dial> verb would look something like:
<Dial hangupOnStar="true" action="[process_hangup_url]">
<Conference>ConferenceB</Conference>
</Dial>
hangupOnStar tells Twilio to disconnect the caller (Field) from whoever they <Dial>ed (the conference), but still makes a request to the URL defined in the <Dial> verbs action attribute. That is important because when Field needs to tell the system to redirect Agent2 into the ConferenceA with Agent1, and the request to the URL in s action attribute gives the system the opportunity to prompt Field to see if thats what he wants to do. So you might have Twilio execute some TwiML like this:
<Response>
<Gather action=[gather_handler]>
<Say>Press 1 to connect this caller to another<Say>
</Gather>
</Response>
If Field presses one, the system (who knows all of the CallSids for all of the parties involved here, and the conference sids), can use the REST API to redirect Agent2 out of the ConferenceB and into ConferenceA.
It makes for a bit more complicated of a system, but it should work for you.
Hope that helps
Redirect an incoming call to new url:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);
// Get an object from its sid. If you do not have a sid,
$call = $client
->calls("CAe1644a7eed5088b159577c5802d8be38")
->update(
array(
"url" => "your_url/test.xml",
"method" => "POST"
)
);
echo $call->to;
XML Code:
---------
<Response>
<Redirect method="POST">url goes here</Redirect>
</Response>

Resources