I was happy when I got my google wave sandbox’s invite and had promised you to write more about its development. Did not get chance to discover more about it, but just implemented a simple robot. This is referenced from the google api doc for wave and this robot shoots back a new blip or a thread to your wave conversation, once you add / remove it or other participants to your wave.
Currently the robots or scripts are supported from Google App Engine only, but with due course of time, google promises to support all other platforms as well. So without wasting time, lets get started :
- You need to download Python 2.5.x or above, if you do not have it on your system. After installing Python, download and install Google App Engine(GAE) SDK, which is responsible for uploading your scripts to the relevant application on GAE.
- You need to register an application with Google App Engine.
- Now you have to download or checkout (if you have SVN support) Google wave robot’s python client library. I am developing this on windows platform and hence I downloaded the zipped file and extracted it in a folder. Make sure the named of the folder which contains these zipped file is same as in the script file, because this from where all the events and other functionality is imported. I have kept the folder name as waveapi.
- After that we need to create a app.yaml which is more like the configuration file of the application and holds information like you application name etc. The content of this file is :
application: realinwave version: 1 runtime: python api_version: 1 handlers: - url: /_wave/.* script: realinwave.py - url: /assets static_dir: assets
- Once you have created the app.yaml , its time to create the script file the one which you specified in the app.yaml, for me its the same as my application name i.e. realinwave.py, but its not mandatory to have the same file name as of application. In he script file, put the following code :
from waveapi import events from waveapi import model from waveapi import robot def OnParticipantsChanged(properties, context): """Invoked when any participants have been added/removed.""" added = properties['participantsAdded'] for p in added: Notify(context) def OnRobotAdded(properties, context): """Invoked when the robot has been added.""" root_wavelet = context.GetRootWavelet() root_wavelet.CreateBlip().GetDocument().SetText("Smells good to get my senses back!!") def Notify(context): root_wavelet = context.GetRootWavelet() root_wavelet.CreateBlip().GetDocument().SetText("Hi from Digimantra.com") if __name__ == '__main__': myRobot = robot.Robot('realinwave', image_url='http://www.digimantra.com/digimantra_ad_125_125.png', version='1', profile_url='http://realinwave.appspot.com/') myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged) myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) myRobot.Run()
Explanation of the realinwave.py
First of all we include the necessary library files in the first 3 lines. This is where you have to change the name of the folder if you did not keep it as waveapi, when you extracted the files in the second step explained above.
As a convention the main is executed and using the myRobot object the two events WAVELET_PARTICIPANTS_CHANGED & WAVELET_SELF_ADDED are registered with the OnParticipantsChanged & OnRobotAdded function respectively.
You can provide the icon’s URL in the image_url to see your own icon when the Robot is added in the contacts.
These functions are then used to notify the wave whenever a participant of the wave is changed or a wave is loaded or opened. The functions are easily understandable and for more information, you can visit the google api docs.
Uploading to the app engine and poking the robot
Now that you have everything right on its place, its time to upload your script files to your application on Google App Engine. The default path where GAE’s SDK get installed is C:\Program Files\Google\google_appengine . So open a command line window and browse to the GAE install path, and write the following command to upload you application.
appcfg.py update <path_to_script_directory>
where <path_to_script_directory> is where you have the folder waveapi and the two files app.yaml, realinwave.py. It will ask for email and password which should be same as the one you provided to register your application at GAE.
Once your files are uploaded, you may now open your wave sandbox and add a new contact with the email address email@example.com, in the above example you can try adding firstname.lastname@example.org. Once you have added the new contact, create a new wave and add this newly created contact to that wave, the robot is invoked and you will see the message which you specified in the Notify function inside your script file.
That should get you started with the Google Wave Sandbox, explore the wide world yourself, and leave comments or ideas here.
Stay Digified !!