Make Phone Calls from Web Pages



Make Phone Calls from Web Pages

You might have seen how you can click a link to dial your phone from your wireless operator's 411 service portal page. But how does this work? Well, the process is really easy, with a special WAP interface known as WTAI.

One of the coolest features in WML is its support for telephony functions known as the Wireless Telephony Applications Interface (WTAI). A Nokia WML browser allows users to make phone calls, send touch tones, and update the phone's Contacts list directly from a web page! Since the mobile phone is still primarily a voice communications tool, the ability to integrate the telephone experience with the web-browsing experience proves to be very useful. You can do that with either specially formatted URLs or WML-Script function calls.

Make a Phone Call

You can "link" to any telephone number via a specially formatted URL from your web page. Once you click that URL, the phone prompts you to make a call to the specified phone number. The URL can be embedded in a <go> or a <a> element in your WML, XHTML MP, or plain HTML pages. The following example shows an XHTML MP page with a phone call link:

            <html>
                 <head>
                      <title>User Feedback</title>
                 </head>


                 <body>
                      <center>
                           <h3>User Feedback</h3>
                      </center>


                      <p> 
                              If you have any problem with our services, please feel free to 
                              <a href="wtai://wp/mc;+15555551234">give us a call!</a> 
                              Thank you very much.
                      </p>
                    </body>
                  </html>

The number +15555551234 after the wtai://wp/mc; string in the URL specifies the phone number. You can use any phone number format that your phone and wireless operator can understand.

Figure shows that when you click the link and confirm the message, a call to the specified number is initiated. Once the call is connected, the phone goes back to the browser and you can continue browsing while staying on the phone. The small phone icon at the top-right corner of the last screen indicates that a voice call is in progress. Although the screen-shots are taken from a Series 60 device, the process is similar on Series 40 devices. On a Series 40 device, you are given an additional choice to quit the browser before the call is initiated.

Making a call from the web page


If you are browsing over a GPRS connection, the connection is suspended while the phone call is active.


Decide Whom to Call

In the previous example, the phone number is hardcoded into the URL. This is not very convenient in many scenarios. For instance, you might want a drop-down list of local numbers to choose from, or you might want to be able to enter your own target numbers. With a little help from WML variables, you can easily make the call link dynamic. The following example shows a WML text entry box. You can enter any phone number in the box and then click the link below it to make the call (see Figure).

Making a call to any user-specified number


           <wml> 
                <card id="Call" title="Phone Number:">
   <p> 
                Enter phone number:
                <input type="text" name="phoneno"/>
           </p>
           <p> 
                <a href="wtai://wp/mc;$(phoneno)">Call</a> 
            </p> 
          </card> 
        </wml> 

In the example, the phoneno WML variable captures your input in the text box. Then its value, $(phoneno), is embedded in the phone call URL as the phone number. If you enter an incorrectly formatted phone number (e.g., alphabetic letters with numbers), the browser will throw an error when you try to make the call.

Capture the Call Status

With the help of WML variables, you can also programmatically capture the status of calls made from any URL. The general form of the WTAI "make call" (i.e., mc) URL is as follows:

       wtai://wp/mc;[phone number]![variable name]

The WML variable following the ! stores the call status code. Figure lists the possible status codes and their meanings.

The status codes after the "make call" operation

Status code

Description

0

Success

-1

Unspecified error

-105

The other party is busy

-106

The network is not available

-107

The called party did not answer


In the following example, the user enters a number and makes the call. After the call is completed (or failed), the "Last call status" link at the bottom of the page opens a WML card showing the status of the last call.

            <wml>
                 <card id="Call" title="Phone Number:">


                    <onevent type="onenterforward"> 
                        <refresh> 
                             <setvar name="callstatus" value="No call has been made"/> 
                        </refresh> 
                    </onevent>


                    <p>Enter phone number: <input type="text" name="phoneno"/></p>
          <p><a href="wtai://wp/mc;$(phoneno)!callstatus">Call</a></p>
                    <br/><br/>
                    <center>
   
                       <p><a href="#Status">Last call status</a></p>
                    </center>
                   </card>


                   <card id="Status" title="Status:">
                        <p>The last call is to number: $(phoneno)</p>
                        <p>Its status is: $(callstatus)</p>
                     </card>
                    </wml>

At the beginning of the card (page), I used a setvar element to initialize the WML variable. Figure shows that the call cannot be completed, along with the corresponding status code.

Checking the status of a failed call


Make Calls from WMLScript

The WTAI not only defines URL schemes for making phone calls, but it also defines public functions you can invoke in WMLScripts. WMLScript requires the WAP gateway (or precompilation), so it is not as easy to use as plain URL links. On the other hand, WMLScript allows you specific logical conditions for making calls, and it makes it easier to handle the call status return value. For more information on WMLScript programming, check out W3Schools' WMLScript tutorial at http://www.w3schools.com/wmlscript/default.asp. The following WMLScript statement makes a phone call to number 5551234 and stores the return value in the flag variable:

var flag = WTAPublic.makeCall ("5551234");

If the call is successful, the return value in flag is an empty string. If the phone number is not formatted correctly, the flag value is invalid. If the call fails, the return value is one of the error codes in Figure


The makeCall function call blocks, and it will not return until the call is finished. Hence, your browser might freeze when you are making a call via WMLScript.

Other Telephony Functions

Besides initiating voice calls, WTAI public library URLs and WMLScript functions can also send touch tones and manipulate the phone Contacts list.

5.1 Send a DTMF tone.

During an active voice call, if you click the following link, the phone will send touch tones (a.k.a. DTMF tones) for the keys 1#23*456 over the voice line:

          <a href="wtai://wp/sd;1#23*456">Send tone</a>

This can be very useful for interacting with automated answering services, which ask you to press keys to navigate menus. You can also capture the return status of the operation in a WML variable. The following is the complete syntax of the "send DTMF" URL link. Figure lists the possible values of the status variable.

         wtai://wp/sd;[tone sequence]![variable name]

The status codes after the "send DTMF" operation

Status code

Description

0

Success

-1

Unspecified error

-108

There is no active voice connection


The corresponding WMLScript function for sending DTMF tones is as follows:

     var flag = WTAPublic.sendDTMF ("1#23*456");

5.2 Add a phone book entry.

On your web site's Contact Us page, you probably want to provide an easy way for visitors to add your contact number into their Contacts list without quitting the browser. The Add Phone Book Entry WTAI URL allows you to do just that. The following link prompts a user to add the phone number +18001234567 as ABC Corp in their phone Contacts list (see Figure):

        <a href="wtai://wp/ap;+18001234567;ABC Corp">
             Add our contact number
        </a>

Adding a Contacts list entry from a web site


The complete syntax of the WTAI URL allows you to use a WML variable to capture the return status value of the operation. Figure lists the possible return values.

wtai://wp/ap;[phone number];[contact name]![variable name]

The status codes after the Add Phone Book Entry operation

Status code

Description

0

Success

-1

Unspecified error

-100

The contact name parameter is too long or unacceptable

-101

The phone number is invalid

-102

The phone number is too long

-103

The phone entry cannot be written

-104

The phone book is full


The corresponding function in WMLScript is addPBEntry:

var flag = WTAPublic.addPBEntry ("+18001234567", "ABC Corp");

So far, I have covered the WTAI public library URLs and functions, which all Nokia devices support. Some phones might support extended WTAI libraries, which provide functions for call management, SMS texting, and more Contacts list operations. You need to check your phone manual and the Forum Nokia web site (http://forum.nokia.com) to find out exactly what WTAI calls are supported on your device.