Advertisment

Write a Robot for Google Wave

author-image
PCQ Bureau
New Update

In this article we will write a Robot which will send an

E-mail to a prede fined E-mail address whenever a new blip is created in a Wave.

Using this extension, you can notify yourself or others about recent activities

in Google Wave, even when you are not logged into it.  To deploy and test the

Robot, you will need access to a Google Wave Preview account. If you don't have

it already, you can request for one at https://services.google.com/fb/forms/wavesignup/.

Google has been sending more invitations than be-fore. So it is likely that you

may get one, sooner than later. We will be writing the code for the Robot using

Eclipse IDE in Fe-dora Linux 12 (released on November17th) Robots can be written

in Python as well as Java. In this article we use Java and deploy the Robot onto

Google App Engine.To deploy the Robot to the Google App En-gine services, first

you will need to create an application identifier at the Google App Engine's

website. Fire up a web browser say Firefox. Login using yourGoogle/GMail account

at: http://app en-gine. google.com/. Click on the button “Create an

Application”. Type in a unique application identifier for example, bli-palert.

Type in an Application Title, say, “Sends E-Mail on a New Blip” and click on

Save. Assuming that you have a running Fedora 12 installation, click on

System>Administration>Add/Remove Soft-ware menu. In the search box, type eclipse

and click on find. From amongst the list of packages displayed, select Fedora

Eclipse and click on Apply.

Advertisment

Direct Hit!

Applies To: Web developers



USP: Learn about this extensible and
scalable communications platform from Google



Primary Link: wave.google.com


Keywords: Google Wave

Follow the onscreen instructions. Once installed, launch

Eclipse from Applications>Programming>Eclipse menu. When prompted, select the

workspace as prescribed by Eclipse -/home/shekhar/workspace in my case.

Once Eclipse is launched, click on Help>Install New

Software.  On the subsequent window titled “Available Software”, click on blue

link 'Available Software Sites'. Look for the URL http://download.eclipse.org/releases/galileo

in the list of Software Sites. Select and click on Enable. Click on OK. Back on

the “Available Soft-ware” Window, type the URL http://dl.google. com/eclipse/

plugin/3.5in the field labeled “Work with:” . Click on Add. This will show

Plugin and SDKs in the bottom pane. Check the boxes against them and click on

Next. Follow the on-screen instructions. This will install the Google Wave

plugins for Eclipse and SDK. When prompted, restart Eclipse.

Advertisment

In Eclipse, click on File>New> Project. Expand Google in

the New Project window, select Web Application Project and click on Next. For

the Project Name type Wave Email Alert. Type incom.it4enterprise.wave (for

example) forthe Package. Click on Finish. Download all the .jar files from the

URL  http://code.google.com/p/wave-ro-bot-java-client/downloads/list and copy

the files to /home/shekhar/ work-space/Wave Email Alert/war/WEB-INF/lib/ .

Replace /home/shekhar with your home directory. In the Eclipse's proj-ect

explorer, navigate to war>WEB-INF>lib. Right click and click on Refresh.Next,

click on Project>Properties (on thetop menu). Select Java Build Path. Click

onAdd Jars. Navigate to Wave EmailAlert/war/WEB-INF/lib/ and select the JARs

(that you downloaded and copied).Click on OK. First we write a Java class which

will send an E-mail message. Note that this class does not use Google Waveor

Robot API. It is the typical code for sending E-mails from any Java application.

package com.it4enterprise.wave;... }

In the above code replacefoo@gmail.com with the Google/GMail

E-mail address that you used to login into the Google App Engine. Replacefoo@foo.com

with the E-Mail address on which you want to receive the alerts.

Advertisment
Google Wave is a web based, e-mail client like interface

where you can see multiple Waves (discussions) which are threaded, and on

the right you can see your contacts and Blips (messages) of participants in

a particular Wave .

In the Eclipse's project explorer, expand the Wave Email

Alert> src. Right click on com.it4enterprise.wave and select New>Class. Type in

Emailer for the Name of the class. Write the above code in the class file.

The Robot's codeGoogle



Wave Robots are nothing but Java Servlet which implement the proces-sEvents( )
method of AbstractRobot-Servlet class, from the Google Wave API class. Following

is the code for a Robot which will use the Emailer class (seeabove) to send an

E-mail whenever a newBlip is created.

Advertisment

package com.it4enterprise.wave;... }

}

The above code uses the Emailer class to send an E-mail as

follows, with the subject as “Wave Updated”:

A new blip has been added to the wave - Blip in theWave>. Click to view the Wave Parsing through the code, the

line:

Advertisment

Wavelet wavelet = bundle.getWavelet();

gives a reference to the Wave and the line:

if (e.getType() == Event-Type.WAVELET_BLIP_CREATED)

Advertisment

Checks whether the event corresponds to creation of a new

Blip. Subsequently we get a reference to the root Blip— the first Blip in the

wave and send its text in the E-mail along with the URL of the Wave. Note the

snippet:

wavelet.getWaveId().replace("+","%252B")

Here we get the Wave ID and replacethe + so as to construct

a browser friendlyURL.

appcfg.py update

Configure the Robot



In Eclipse's project explorer, replacethe contents of the file web.xml underwar>WEB-INF>lib

with the following:

encoding="utf-8"?> ...

Next, create a new folder called _waveunder war (right

click on war and selectNew>Folder). Right click on _wave, selectNew>File and

enter the file name as capa-bilities.xml. Type the following in the file:

encoding="utf-8"?> ...

This states that our Robot will handle the event called

WAVELET_BLIP_ CRE-ATED — the event which is fired when anew Blip is created. It

also states the version of the Robot. Note that whenever you make any change to

the code of the Robot you must update the version (say from 1to 2 or 3) for the

Google Wave to refresh the code; else it will use the older cached code.

Deploy to App Engine



Back in the Eclipse's project explorer,navigate to war>WEB-INF and open

thefile appengine-web.xml and change the line:



to

blipalert

Replace blipalert with the App En-gine's application

identifier in your case.

To upload and deploy your Robot tothe App Engine, click on

the icon “DeployApp Engine Project” on the toolbar. On thepop-up window type in

your Google/Gmail login and password — the sameones with which you logged into

App En-gine and created the application identifier.

See how it works



Login to your Google Wave Previewaccount at http://wave.google.com. Clickon

the + icon at the bottom of the Con-tacts pane (on bottom left). For addresstype

in blipalert@appspot.com. Substitute blipalert in the address with your

application identifier. Click on Submit. Next create a new Wave or open an

existing Wave. Click on the + icon (on the top) toadd a user. On the “Add

Participants” pop-up search and select the address bli-palert@appspot.com. Hence

forth whenever a new Blip is created in thisWave you will receive an E-mail.

Conclusion



A simple Robot to get you started withWave extensions development. Note that

we have used Java Mail API in the code to send E-mails. This means, while

developing new Robots you can use existing JavaAPIs and libraries to impart

functionality and to integrate Robots with other applications — for example: use

a Java REST library to make the Robot talk to Twitter.

The Robot API itself is simple. How about changing the code

of the Robot to send the text of the newly created Blip in the E-mail. Hint: use

the Eclipse's type ahead (intellisense) or refer to the Robot API at

http://wave-robot-java-client.googlecode.com/svn/trunk/doc/index.html.

Shekhar Govindarajan, IT4Enterprise

Advertisment