Here's my requirement:
I have a text ="Thank you for your response". I want to initiate a call with a user, and when the user picks up the call, i want the text message to be turned into a voice message.
Here's what i have so far:
I am initiating a twilio call:
twilioClient.calls.create(to=user_number, from_=twilio_number, \
url="https://testserver.com/call/")
In urls.py, i have /call/ that points to my django view module
In view, the module looks like:
def testTwilioCall(request):
return HttpResponse(open('/path/call.xml').read(), content_type='application/xml')
-call.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">Thank you for your response.</Say>
<Record maxLength="20" />
</Response>
Here's whats happening:
User gets a call, and the call says - "Sorry application error".
I am not sure what is going wrong. When i replace the url parameter with https://demo.twilio.com/welcome/voice/, it works.
I also double checked that the xml is being displayed fine from the browser.
Not sure where i am going wrong with rendering the xml.
PS: testserver is just a placeholder.
Related
Twilio newbie here.
I have a Twilio voice application that collects a bunch of data (international topup sales) - and there is a point where the actual process of purchasing the topup takes place.
This process can last anywhere from 10 to 30 seconds, where most of them are about 15 seconds. Sounds to me like I need to use the Twilio <ENQUEUE> tag (https://www.twilio.com/docs/voice/twiml/enqueue), but it does not work.
I am simply calling it like this (happens to be ColdFusion):
<Enqueue
waitUrl="processtopup.cfm"
method="POST"
action="topupdone.cfm">processTopup</Enqueue>
Within the processtopup.cfm file is the <PLAY> tag (which won't work because that is the page that takes more than 15 seconds.
Sorry - but I'm just confused on ho this should work. Thanks in advance!
Here is a possible solution. I've tested this and it works.
The main idea is to play some message/music in a loop until ColdFusion does the job, then, when ColdFusion is done, instruct the call to execute a different Twilio XML by making a POST request to Twilio's API call resource.
When a call comes in, and Twilio hits your endpoint, capture the call id, it will be used to switch the call to a different XML. The call id it's passed as FORM.CALLSID or URL.CALLSID depending on your webhook configuration at Twilio.
The call id looks something like CAdecbfa7e8e2a9d09336abcd57044cf74.
Pass the call id trough your flow (as url parameter should be fine) so it reaches processtopup.cfm.
Move the long running code from processtopup.cfm to let's say
processtopup-action.cfm
Code in processtopup.cfm should now return immediately XML for playing loop (or you can play some .mp3), I'm showing with a message:
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say loop="0">Please wait while we process your request...</Say>
</Response>
</cfoutput>
<cfhttp
url="http://www.yourwebsite.com/processtopup-action.cfm?callsid=#FORM.CALLSID#"
method="get"
timeout="1" />
The code for processtopup-action.cfm
<!--- // place your long running code here --->
<cfset accountSid = '{your account sid}' />
<cfset authToken = '{your auth token}' />
<cfhttp
url="https://api.twilio.com/2010-04-01/Accounts/#variables.accountSid#/Calls/#URL.CALLSID#.json"
method="POST"
username="#variables.accountSid#"
password="#variables.authToken#"
result="http_result">
<cfhttpparam
name="Url"
value="http://www.yourwebsite.com/finish.cfm"
type="formfield" />
</cfhttp>
Code for finish.cfm
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This is the data you're looking for.</Say>
<Say>Thank you. Goodbye!</Say>
<Hangup />
</Response>
</cfoutput>
Of course, you can pass other parameters as you need.
Again, the main idea is that processtopup-action.cfm, after executing your long running code, makes a POST request to Twilio's API and instructs the call to switch to execute new TwiML located at http://www.yourwebsite.com/finish.cfm
Docs:
Call Redirection via the Twilio REST API
(https://www.twilio.com/blog/2009/09/call-queueing-putting-callers-on-hold-calll-redirect-new-url-new-feature.html)
Modifying Live Calls
(https://www.twilio.com/docs/voice/modify-live-calls)
Our SOAP web service provider insist on removing empty field tags from the request because it breaks the service. Is that right practice?
See below example of request. StockID is empty tag. Should it break the SOAP service?
I would like to know best practice around empty tags in request
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
<m:StockID/>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
This Depends on how the rest of the system is programmed. There are 3 ways of sending StockID:
Empty tag
Tag removed
Tag With nil="true"
What is probably happening for the first item above is that the program is deserializing the tag as an empty string, and then crashing since there is no Stock id = "".
In the 2 last items above it would deserialize as NULL and then not try and find a Stock id = NULL.
I'm learning how to send and receive a SOAP call. I have the required parameters available with me like username , password and the URL of the WSDL/WebService.I lso know a sample SOAP reply that I'm expecting which is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:infoLookupResponse xmlns:ns1="urn:vtsPhoneNumberLookup">
<phoneNumber xsi:type="xsd:string">4444444444</phoneNumber>
<Type xsi:type="xsd:string">Landline</Type>
<OCN xsi:type="xsd:string">2222</OCN>
<OVERALLOCN xsi:type="xsd:string">2103</OVERALLOCN>
<COMPANY xsi:type="xsd:string">ABC Inc</COMPANY>
<DBA xsi:type="xsd:string">ABC Inc</DBA>
<CommonName xsi:type="xsd:string">ABC</CommonName>
<HOLDINGCOMPANY xsi:type="xsd:string">ABC Communications Inc</HOLDINGCOMPANY>
<MANAGEMENT xsi:type="xsd:string"></MANAGEMENT>
<SMS xsi:type="xsd:string"></SMS>
</ns1:infoLookupResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I have gone through online stuff and based on my understanding, in order to send the SOAP request, I need to have a raw XML of the same format that I'm
expecting ( as mentioned above). The condition in my case is that a user will be submitting a phone number using an HTML Page and that will be sent as a SOAP
request expecting the aforementioned reply from the server.
In the above case, a user would have submitted 4444444444 as a phone number. So,I understand that I need to create raw XML type of phoneNumber and my questions is, do I need to create raw XML for Type,OCN,OVERALLOCN,COMPANY,DBA,CommonName,HOLDINGCOMPANY,MANAGEMENT and SMS as well?
Please let me know if there is anything wrong with what I have understood so far. Also, let me know if you would like me to paste some specific part of WSDL which will help you in answering/understanding my question.
I'm working on a little project for school. This project asks me to show that I'm capable of using various processing techniques of XML. Now, in my project I work with the Sedna database manager in which I keep user records and I would like to update some of these user records through XQuery (I use the PHP API to send the queries to the database through the PHP Api provided by the Sedna Developers team).
Imagine I have the following database content for the user records:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="admin" admin="true">
<email>admin#admin.com</email>
<password>123456789</password>
<firstname>The</firstname>
<lastname>Stig</lastname>
<gender>male</gender>
<subscriptions>
</subscriptions>
</user>
<user id="prosper" admin="false">
<email>prosper#localhost.com</email>
<password>123456789</password>
<firstname>Strange</firstname>
<lastname>Figure</lastname>
<gender>male</gender>
<subscriptions>
</subscriptions>
</user>
</users>
Now, I my intention here is to update, for example, prosper's userrecord. In this record I would like to, for example, change his firstname and email, but keeping the rest unchanged.
I have tried to use the following query, but after sending the query, it changes the document order of the userrecord for some reason I don't understand (I think it inserts the attributes nodes of the user record as childnodes).
This is the query I use to update the user:
UPDATE replace $user in doc("users")//user[#id="prosper"]
with
<user>{($user/#*)}
<email>strange.figure#localhost.com</email>
{($user/node()[password])}
<firstname>Familiar</firstname>
<lastname>Figure</lastname>
<gender>male</gender>
{($user/node()[subscriptions])}</user>
Now, the problem this query gives me, is that when I try to ask the user's information after the update, I rely on the same order of child nodes have from before the update, but this query changes the order.
Is there someone skilled enough to help me with this problem?
I thank you for your time.
Jan, if you want to get password node you should change your XPath (your current expression {($user/node()[password])} is not what you think):
{$user/password}
the same true for subscriptions:
{$user/subscriptions}
It can be written as one expression with predicate:
{$user/node()[local-name(.) = ('password', 'subscriptions')]}
I have a database with an xml document in it, and I want to display a transformed xml on my xforms page, when the submission is sent (I'm using orbeon forms).
My solution is, that on the submission my servlet gets the xml from the database, writes it into a file, xslt transforms the xml tree (when and how should I do the transformation?), but I don't know, how to display this file on the xforms page. Maybe the replace="instance" attribute in can help, but i don't know how.
Thanks!
Now, after Alessandro's advice, Im trying to use this xpl thing, but it doesn't work.
In the model:
<xforms:insert nodeset="instance('inst2')"
origin="xxforms:call-xpl('oxf:/resources/pipeline.xpl', 'data',
instance('inst1'), 'data')"/>
in pipeline.xpl:
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<p:param type="input" name="data"/>
<p:param type="output" name="data"/>
<p:processor name="oxf:xslt">
<p:input name="data" href="#data"/>
<p:input name="config" href="transform.xsl"/>
<p:output name="data" ref="data"/>
</p:processor>
My instance, that I want to transform is "complaint-instance", the transformed instance called "trf-instance", the pipeline.xpl file is in the same directory with my xforms page. My styesheet called customerToOperator.xsl. What's wrong in my code?
I just noticed, the note: "If you are using separate deployment, the service and XSLT transformation must be present in the Orbeon WAR file, instead of within your application."
Ehm... Where should I put these files?
my app in details:
a) an xforms page, with 2 instances:
<instance id='inst1'>
<name>
<lastname/>
<firstname/>
</name>
</instance>
<instance id='inst2'>
<fname>
<fullname/>
</fname>
</instance>
I got 2 input fields, referenced on name/lastname and name/firstname.
I have an xforms:insert node, described above, and an xforms:submission node:
<xforms:submission
id="save-submission"
ref="instance('inst2')"
action="/my-servlet"
method="post"
replace="none">
I added 2 files to orbeon/WEB-INF/resources, the pipeline.xpl, (described above) and transform.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fname>
<fullname>
<xsl:value-of select="name/firstname"/>
<xsl:value-of select="name/lastname"/>
</fullname>
</fname>
</xsl:template>
</xsl:stylesheet>
And I have a servlet, which writes the posted instance on the console (now it writes inst2 on the console, but without the user input data, only the nodes...)
A really need to fix this...
Thanks again!
To get the XML from a database (relational or not) and apply a transformation, instead of writing my own servlet, I would use an XPL pipeline, and map this pipeline to a URL through the page flow. Now you have a service that answers to an HTTP request and returns XML. To call the service from XForms, you use an <xforms:submission replace="instance">. You end up with the XML in an instance, and you can display it with something like: <xforms:output value="saxon:serialize(instance(), 'xml')"/>.
In all cases (including separate deployment), the pipeline and XSLT file must be in the "resources". Usually, this means the WEB-INF/resources of the Orbeon's web app. But you can also do more fancy things by setting up the Orbeon resource manager to also use other directories on disk.