How to get the incoming caller's phone number in Twilio Flask App? - twilio

I want to print/get the incoming caller number in Twilio Flask app. I was referring to the twilio-ivr-phone-tree for this. I tried print(request.args) in the welcome function i.e the first method which is invoked when I receive an incoming call. But it prints an empty ImmutableMultiDict([]).
Am I missing something? Any help is appreciated. Thanks in advance.
To -ve voters, post a comment for doing so. It helps to increase the quality of the question and make stack a better place.

The incoming call request information can be obtained in a Flask app using request.values
these are they keys of the diction returned:
atts = ('AccountSid',
'ApiVersion',
'CallSid',
'CallStatus',
'Called',
'CalledCity',
'CalledCountry',
'CalledState',
'CalledZip',
'Caller',
'CallerCity',
'CallerCountry',
'CallerState',
'CallerZip',
'Direction',
'From',
'FromCity',
'FromCountry',
'FromState',
'FromZip',
'To',
'ToCity',
'ToCountry',
'ToState',
'ToZip')

The main problem is the Twilio request has a form content type and the raw data will be consumed leading it to appear empty as described in this answer.
However request.get_data() can print the whole POST and you can easily find that the key From holds the caller's phone number.
So, to access it you need request.form['From'] and it fetches the caller's number to the local environment.

Related

Twilio Simulring Funlet Install

I'm trying to get [https://github.com/twilio-labs/function-templates/tree/main/funlet-simulring] to work. I'm trying to upgrade my IVR to have a whisper (announce who is calling to the called party before accepting the call) and a voicemail fallback so callers don't get my personal cell voicemail instead of the work line.
I'm trying to get the Funlet Simulring working. I'm getting an error at the "split" function (full error copied below).
I copied in the code here (https://github.com/twilio-labs/function-templates/blob/main/funlet-simulring/functions/funlet-simulring.protected.js) and two numbers to line 37:
phoneNumbers: [+1xxx,+1xxx],
I also have to environmental variables set:
TWILIO_VOICE_WEBHOOK_URL=/funlet-simulring and:
FUNLET_SIMULRING_PHONE_NUMBERS=+1xxx,+1xxx
I put some more context below, but my issue is if I "fix" the split error the number doesn't forward, but if I leave it as is I get a function error.
I've tried editing line 145 since "FUNLET_FINDME_PHONE_NUMBERS" seems to me to not be defined anywhere. But if I define it my just hard coding in my forwarding numbers, I can get the function to play, but it doesn't forward anywhere.
Error: {"message":"Cannot read property 'split' of undefined","name":"TypeError","stack":"TypeError: Cannot read property 'split' of undefined\n at getPhoneNumbers (/var/task/handlers/ZNxxx.js:145:37)\n at Object.exports.handler (/var/task/handlers/ZNxxx.js:387:29)\n at Object.exports.handler (/var/task/node_modules/runtime-handler/index.js:339:10)\n at Runtime.exports.handler (/var/task/runtime-handler.js:17:17)\n at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:74:25)"}

Asterisk. Get number of active calls in dialplan

I have production asterisk 16.4 with dialplan on LUA and two SIP providers. The first provider give me trunk with maximum 5 connections and the second provider give trunck with 20 connections. I prefer to use the first provider for outgoing calls because it is cheaper, but it have only 5 lines. So, when user makes an outgoing call, I want to check current number of active calls on the trunk of first provider, and if that number is 5 then route the call throught second provider.
The question is - How can I get in dialplan number of active calls? Is there some functions or core variables? I know that I can get list of active channels in CLI by command "core show channels verbose", but how can I get somthing like this in lua dialplan?
Thanks to #arheops for the clue. This is a working example on lua.
ext = extension:sub(1); -- Remove leading 9
local providerA = tonumber(channel['GROUP_COUNT(provA)']:get());
app.Verbose("Active channels on provider A = "..providerA);
if providerA < 5 then
channel['GROUP()']:set("provA");
app.Verbose("Outgoing call throught Provider A "..ext);
app.Dial("PJSIP/"..ext.."#trunc_providerA");
else
app.Verbose("Outgoing call throught Provider B "..ext);
app.Dial("PJSIP/"..ext.."#trunc_providerB");
end;
app.Hangup();
You can set GROUP for each channel and after that cont GROUP_COUNT in dialplan
https://www.voip-info.org/asterisk-func-group/

https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("ARSARS")&env=store://datatables.org/alltableswithkeys

I have been using the following URL for the past 3 years without issue. However, it has stopped returning results.
URL:
https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("ARSARS")&env=store://datatables.org/alltableswithkeys
Now returns the following:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="0" yahoo:created="2017-11-02T09:33:25Z" yahoo:lang="en-AU">
<results/>
</query><!-- total: 9 -->
Notice how there are no results, it simply has the tag "results".
I have tried on this many different computers and browsers. I have also tried changing the currency combinations, but no luck.
Can anybody spot what I am doing wrong?
Yes, it looks like Yahoo has discontinued their Currency Converter API service.
I found a different site : https://currencylayer.com/
They let you request currency rates (1 USD = 168 other currencies). If you make less than 1000 requests per month, it is free (if you need more, they have different subscriptions : https://currencylayer.com/product).
You just need to sign up and receive your own Access Code. Once you have that, then you simply make the call http://apilayer.net/api/live?access_key= and it will return JSON of the other currency rates.
They also have code examples in PHP, JavaScript, and Java at https://currencylayer.com/documentation
Found it very easy to get started using their API right away.
I think the API is down.
I am similarly receiving "results"=nullfor the query:
http://query.yahooapis.com/v1/public/yql?q=select+%2A+from+yahoo.finance.xchange+where+pair+in+%28%22GBPEUR%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
Setting diagnostics=true in the request yields:
`
[execution-start-time] => 7
[execution-stop-time] => 12
[execution-time] => 5
[http-status-code] => 999
[http-status-message] => Request denied
[content] => http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=snl1d1t1ab
`
If anyone knows more than me about what this might imply I'd be glad to hear it!
Yahoo is aware of this issue and their engineers are working on it:
ref: https://forums.yahoo.net/t5/Yahoo-Finance-help/http-download-finance-yahoo-com-d-quotes-csv-s-GOOG-amp-f/td-p/387096
Very sadly and quite outrageously Yahoo decided to stop this service without any warning.
See admin message here
So many services depend on it, it's like Google saying they would suddenly stop their maps API... At this point I am blocking yahoo in our DNS so no one in our company will ever use Yahoo again since they are not a reliable entity.

Twilio - Interrupt a Say Block

I have a Play block, that Says many .mp3 files (it reads an account balance and other information about an account.
The result is a a message that takes a while to listen to. The messages vary in length, depending what is said.
I'd like 'any' key to end playing the messages and skip back to the c#.
I tried using a Gather, but the timeout value either truncates the Say block, or waits for ages at the end (if no key pressed)
Any thought on how to achieve this?
The current flow is this:
<?xml version="1.0"?>
<Response>
<Play>/Voice/test/messages/CurrentlyYourPAYGBalanceIs_.mp3</Play>
<Play>/Voice/test/common/numbers/78.mp3</Play>
<Play>/Voice/test/common/currency/_pounds_.mp3</Play>
<Play>/Voice/test/common/misc/_and_.mp3</Play>
<Play>/Voice/test/common/numbers/91.mp3</Play>
<Play>/Voice/test/common/currency/Pence.mp3</Play>
<Play>/Voice/test/messages/_AndYouHavea_.mp3</Play>
<Play>/Voice/test/products/BD021.mp3</Play>
<Play>/Voice/test/common/misc/_with_.mp3</Play>
<Play>/Voice/test/common/numbers/95.mp3</Play>
<Play>/Voice/test/messages/_VoiceBalance.mp3</Play>
<Play>/Voice/test/common/misc/_and_.mp3</Play>
<Play>/Voice/test/common/numbers/2.mp3</Play>
<Play>/Voice/test/common/data/_gigabytes_.mp3</Play>
<Play>/Voice/test/common/numbers/200.mp3</Play>
<Play>/Voice/test/common/misc/_and_.mp3</Play>
<Play>/Voice/test/common/numbers/94.mp3</Play>
<Play>/Voice/test/common/data/_megabytes_.mp3</Play>
<Play>/Voice/test/common/misc/_remaining.mp3</Play>
<Play>/Voice/test/common/misc/Expiring_.mp3</Play>
<Play>/Voice/test/common/dates/31.mp3</Play>
<Play>/Voice/test/common/months/_of12_.mp3</Play>
<Play>/Voice/test/common/years/2016.mp3</Play>
</Response>
David, check out this question:
Twilio play pause/resume
Specifically:
The playback is interrupt-able as it is wrapped in Gather which points
to Pause action.
You can wrap your <Play> TwiML in a <Gather> and point to a URL containing the instructions you wish.

Omniture Saint.ImportCreateJob

This is a very specific Omniture API question. Thought I'd check here if anyone encountered this problem since Omniture forum was not of much help -
Sending the following parameters to Omniture API Explorer here - https://developer.omniture.com/en_US/get-started/api-explorer#Saint.ImportCreateJob seems to work fine.
{
"check_divisions":"1",
"description":"OSRA job description: MyReportID, Products, 51",
"email_address":"my#email.com",
"export_results":"0",
"header":["Field1", "Field2"],
"overwrite_conflicts":"1",
"relation_id":51,
"report_suite_array":["MyReportID"],
"c_view":"SomeReportName"
}
But the call fails in the actual code with a 'Bad Request'. It seems like c_view parameter is expecting a certain value. The only documentation for c_view is that it expects a report name. I've tried report names and other values with no luck. Would appreciate any pointers from Omniture API users.
Thanks.
try using the relevant value from the classification_view chart. I know this is what you need for using the get/save classifications methods (I have used those methods, but not the Saint.ImportCreateJob method).
c_value is not required, so unless you plan on using it, it does not need to be present. It is supposed to be a classification_view https://developer.omniture.com/en_US/documentation/omniture-administration/r-classification-view.
It takes some trial and error to get this api working.
Here is an example of a call I use that works using the REST api over Java:
Request:
{
"check_divisions":1,
"description":"Report Test 1",
"email_address":"cdegroot#adobe.com",
"export_results":"0",
"overwrite_conflicts":0,
"relation_id":65,
"report_suite_array":["cdgdev"],
"header":["Key","Survey","Survey^Question","Survey^Question^Response","Engagement Index","Survey > Question > Response"]
}
Response:
"3387166"
Kind Regards C.

Resources