Thursday, May 16, 2013

Using Twilio to answer phone calls


In a previous post, I wrote about how to use Twilio to send an SMS message. This time, I'm going to show you how you can use Twilio in conjunction with a web app to answer phone calls made to your Twilio phone number.

First, you will want to have a Twilio developer account. If you did not create one last time, go ahead and create one now.

The Twilio dashboard provides a place for you enter an address to send HTTP POST requests. Using the App.HandleSpecialURL event handler, you can send these requests to a web application running on a publicly available server.

To get started, you need to create a web application. In the App object, go to the HandleSpecialURL event handler. This event handler has one parameter: Request As WebRequest. You can use this parameter to handle the request sent by Twilio and to send information back to Twilio.

Twilio uses something they call TwiML (Twilio Markup Language), which is essentially XML with Twilio-specific commands.

In this case, the special command you want to use is the Say command. This command will speak the provided text to the person that called the number. It is wrapped in a Response, so some simple TwiML looks like this:

<Response>
  <Say>This call was answered by my web application!"</Say>
</Response>

Going back to the HandleSpecialURL event handler, you just need to return the TwiML as part of the request. This is done using the Print method:

If Request.Path = "twilio" Then
  // Use TwiML to say something
  Dim now As New Date
  Request.Print("<Response>" + EndOfLine)
  Request.Print("<Say>This call was answered by my web application!</Say>" + EndOfLine)
  Request.Print("<Say>The time is " + Now.LongTime + "</Say>" + EndOfLine)
  Request.Print("</Response>")
   
  Return True
End If

Notice that I have not created a web page. That's because this web app won't use one as its only purpose is to handle direct requests using HandleSpecial URL.

Give this app a name (TwilioCall), built it as a standalone app (or CGI if you prefer) for your deployment platform. 

Now you need to configure Twilio to use this web app.  Go back to your Twilio Dashboard and navigate to Dev Tools and select TWIML apps. Click "Create TWiML App" to create a new app.



This opens a screen to specify information about your web app:



In the "Friendly Name" field just give your app a name such as TwilioCall. In the Voice section, you specify the URL for your uploaded web app in the "Request URL" field. The URL of your app will be something like this:

http://www.example.com:8080/special/twilio

With all this in place, you can now call your Twilio phone number. Twilio will then send a request to your web app which will respond by sending back a request to speak some text and the current time.

You can find more information about TwiML here: https://www.twilio.com/docs/api/twiml

An example project demonstrating this will be included with Xojo and is also available here.

Wednesday, May 15, 2013

Calling a SOAP web service

SOAP web services, although not as common as they once were, are still readily available on the web. And they can be incredibly easy to use with your apps.

Here is a quick example of how you would use a SOAP web service to get the conversion rate between currencies using the SOAP web service described here:

http://www.webservicex.net/CurrencyConvertor.asmx

The above page describes the method call that is available to you and also provides information about the various currencies available for conversion.

Click the "ConversionRate" method to get more information on how you would call this. This opens a new page (scroll down) with a way to test the web service and a list of the various ways that it can be called.

In the SOAP 1.1 section, you can see that the function is called "ConversionRate" and that it takes two parameters: FromCurrency and ToCurrency, both of which are simply a string containing the currency code.

The last thing to determine is the actual URL to use. Often, web services use the "WSDL" query string to fetch the Web Service Description Language for the service. In the case of this web service, you will use this URL:

http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

With this information, you can use the SOAPMethod class to call the method.

To get started, create a new project and add to the default Window these controls:

  •  two TextFields to provide the from and to currency codes (FromCurrencyField and ToCurrencyField)
  • a PushButton to do the conversion (ConvertButton)
  • a TextField to display the results (ConversionRateField)

Now you can put this code in the Action event handler of the PushButton:


  Dim sm As New SOAPMethod("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL")
  
  Dim conversionRate As String
  conversionRate = sm.ConversionRate(FromCurrencyField.Text, ToCurrencyField.Text)
  
  ConversionRateField.Text = conversionRate


Run the app an enter two currency codes (USD and EUR) and then press the button to get the conversion rate (0.7761 as of today).
There are many public web services that are available for you to use with your apps. Here are two sources of many web services:

http://www.webservicex.net

http://www.xmethods.com

Keep in mind that like anything on the web, web services can go offline from time to time so be sure to check for an error condition or invalid result from any web service call.

You can download the sample project (which will be included with Xojo) here.

Tuesday, May 14, 2013

Connecting to Oracle and Microsoft SQL Server

Some of the most common questions I get from new users relate to using databases with Real Studio. We've got lots of tips and tricks on how to connect in our Documentation and videos too.  In addition to having it's own RealSQLDatabase for single user applications, Real Studio supports database server connectivity for Oracle, ODBC, Postgre, MySQL, Microsoft SQL (Windows only).

One thing to watch our for when connecting to Oracle or Microsoft SQL Server is to make sure that you are using 32 Bit versions of Oracle Instant Client or Native Client Installer for MSSQL instead of the 64 Bit versions. Real Studio currently build 32 Bit applications and cannot use the 64 Bit libraries.

Once Real Studio builds 64 Bit apps you will be able to use the 64 Bit libraries. You can read more about the schedule for 64 Bit in this post.


Friday, May 10, 2013

Using Twilio to send an SMS message



I've been asked from time to time if it is possible to send an SMS message from your application. SMS stands for Short Message Service and is also commonly referred to as a Text Message or just a Text. SMS messages can contain up to 160 characters. To send someone an SMS, you just need their mobile phone number.

So is it possible to send an SMS message from your apps? As is the case with most things, the answer is "Yes, if you know how". And often many of these things can be accomplished using a web service of some kind.

One of the easiest ways to interface with telephones, including SMS, is using a web service called Twilio.

With Twilio, you can do all kinds of things related to telephones, including making and receiving phone calls and text messages. Twilio is not a free service, but you can get a free developer account with a credit to test it out.

To start, create a free developer account at Twilio.com. I'll wait for you to come back...

Twilio has a lot of documentation on how to use their various services. To send an SMS message, you want to take a look at their SMS REST API which is here:


On this page you will see buttons with examples for a variety of languages. You can just click XML to see how to do this using XML and curl, which you can easily incorporate into your app.

When Xojo is released, it will include a sample project that demonstrates how to do this using just a few lines of a code and a handful of controls.

Sample Application

When you run the app, you enter your Twilio Account SID and AuthCode, your Twilio phone number, the phone number you want to send the SMS to and your message. You can get the Account SID and AuthCode on the main Dashboard page:

Twilio Dashboard Page

The app uses curl (from a Shell) to send the SMS so it will only work on OS X and Linux. The code is entirely contained (all 6 lines of it) in the Action event handler of SendButton.

This code takes what was entered in the window and creates the curl command (as described on the Twilio page) and then runs the command using a Shell. The XML results are displayed after the message is sent.

This is the message as it appears on my iPhone:
SMS Message appearing on iPhone

You can also download the sample project from here.







Tuesday, April 30, 2013

Coming Soon - New Pricing (Recap)

As we approach the June 4th Xojo ship date, we are receiving an increasing amount of questions about the new pricing.  It has been a while since we posted the information so here's a recap:


Starting with 2013 Release 1, the IDE itself will be free to use for developing, running, testing and debugging on any platform. When you need to create stand-alone builds of your apps, you buy a license. These are the available licenses and prices:

New Xojo Pricing
LicenseNew PurchaseRenewal
IDEFREEFREE
Desktop Deployment$300$150
Web Deployment$400$200
Console Deployment$100$50
DB Servers$300$150

Note: You can build for OS X, Windows and Linux for any license type. SQLite usage (RealSQLDatabase) does not require a DB Server license.

A new purchase or renewal gives you access to all updates for the next 12 months. As usual, you can continue to use versions that were released during your license period even after your license has expired.

Speaking of licenses, anyone who has or had a modern Real Studio license (2005 - present) will have their license automatically converted as follows:

Personal => Desktop
Professional => Desktop + Console + DB
Web => Web + DB
Enterprise => Desktop + Web + Console + DB (Xojo Pro)

If your license is current when 2013 R1 ships, you will be able to deploy with it immediately. If your license is expired, you can use the IDE for free, however you will not be able to deploy with it until you renew. Of course, you can continue to use any prior version of Real Studio as you always have. And as a prior license holder, you can choose to renew any of the converted licenses at the new renewal pricing.

After the license conversion, Personal users will be able to use ContainerControlsclass encryptionServerSocketSSLSocket (and its subclasses), Remote DebuggingAuto DiscoveryProfilingIDE Scripting and Build Automation. In addition, your new Desktop license will also allow you to deploy for Mac OS X, Windows and Linux. Professional users will be able to use Profiling, IDE Scripting and Build Automation.

New licenses can be used on up to two computers at one time, except with Xojo Pro (you can use three). 

You may renew at the current price before Xojo ships for up to two years.  Once Xojo ships the new pricing will go into effect.  If you have any specific questions about your license, please contact custserv@realsoftware.com.


Why native controls are important

9to5Mac is reporting that iOS 7 will sport a new user interface. It's said to be flatter and simpler. If this is true, it almost certainly means that controls will have a new look as well. This reminds me of when Apple shipped Mac OS X with its new Aqua interface. Every version of Windows has redefined the look and feel of most of the user interface. Ubuntu continues to improve the user interface of the popular Linux distro as well.

For some software developers, a change in the OS user interface is a problem. They are using a development tool that draws controls itself rather than going the extra mile required to use native controls. Native controls are drawn by the OS, not the application. When the app is moved from one OS to another (for example between iOS 6 and iOS 7 or between Windows XP and Windows 7), it takes on the native user interface because it's using native controls. Apps made with development tools that draw their own controls suddenly look out of place and strange.

This is why Real Studio has always used native controls ever since it was introduced in 1998. We want our user's applications to have a user interface that matches the OS. Most iOS development tools don't make the effort to use native controls. We do. We previewed our iOS development efforts at our annual user conference last week. We use all native controls for iOS because that's the level of effort our users have come to expect from us.

Monday, April 29, 2013

Best computer for cross-platform development

Today The Telegraph has a post about a study showing the MacBook Pro is the best computer for running Windows. I've heard this before and don't doubt it for a moment. Apple makes the best computers in terms of quality. They are certainly not the cheapest, but they are the best.

They are also the best for cross-platform development with Real Studio. Because you can run OS X, Windows and Linux all on one computer, what more could you ask for when it comes to convenience? At Real Software, most of us used to have at least two computers: one running OS X and the other running Windows and Linux. When Apple made the jump from PowerPC to x86, we got rid of half of our computers!

If you're developing a cross-platform solution with Real Studio that is going to include an OS X version, you'll need a Mac anyway, so why not just make it your primary computer even if your primary OS is Windows or Linux?

Here are two options for running Windows and Linux (and OS X) from a Mac:

1) Apple's Bootcamp: It's free and you can boot into Windows so you're getting the full power of the Mac running Windows, rather than sharing the processor with OS X. The downside is that you can't run both at the same time and setting it up to run Linux could prove challenging.

2) VM Ware/Parallels: Both of these software applications will allow you to run multiple OSs while running OS X. I use VM Ware and have Windows XP, Windows 7 and Ubuntu Linux available to me in addition to OS X. The downside is that when you are running one of these, you are also running OS X, so Windows or Linux can't use the full power of the computer. However, I have found that not to be much of an issue with newer Macs, as they have plenty of power. Just make sure your Mac has lots of RAM, as that's often the difference between the performance being great versus not so good.

Update: Microsoft provides most versions of Windows for testing for free download. They available in Parallels, VMWare, and VirtualBox formats.

Macs are more expensive than the average Windows PC. There's no doubt about that. But if you need a Mac, it might cost less to buy a nice one and use it as your only computer with the convenience of running OS X, Windows and Linux all from one machine.