|
GettingStarted
Getting started with the .NET Wave Robot API.
IntroductionThis isn't a detailed guide to the Wave Robot API - it's just enough to get you started. For more details, see the official Robot API documentation. All of this may well change - and in particular there should be fewer hoops to jump through in future. PrerequisitesTo use the .NET Wave Robot API you must have:
OverviewCurrently, the Wave sandbox only allows for robots hosted on AppEngine. AppEngine doesn't host .NET applications, making life a bit trickier. We need to set up a proxying application on AppEngine which forwards requests to an ASP.NET server. After that, we then need to set up the ASP.NET server to respond appropriately to the proxied Wave requests. This uses a custom HTTP handler, which for convenience we keep on the .ashx extension via a bit of proxy URL rewriting. Setting up the proxying applicationThe basis of the proxy is Downy. Ignore the fact that it has anything to do with Mercurial - it's a proxy, which is all we need. Follow these steps:
python "c:\Program Files\Google\google_appengine\appcfg.py" update . If you've got appropriate logging turned on at your ASP.NET website, you should now be able to see requests being made appropriately if you put the URL of your AppEngine application into your browser. Building the Wave Robot APIThis bit's easy. Check out the source (read-only is fine) into a new directory. Open the solution in Visual Studio and build it. Creating your robotWave will make requests to three different URLs, relative to the one you specified for REMOTE_ROBOT:
(The profile information is now available in the capabilities, and can be specified in an attribute, but Wave appears to ignore it at the time of this writing.) The robot base class handles both the capabilities document and the JSON RPC call, based on the query string. So, to get started:
You can leave the MyFirstRobot.ashx file itself alone, but edit the MyFirstRobot.ashx.cs file.
Here's a complete example based on the Java tutorial. using Google.Wave.Api;
namespace CSharpInDepth.Wave
{
/// <summary>
/// The Parity robot.
/// Like Parroty, but for .NET... so achieving parity with Java.
/// </summary>
public class Parity : EventDrivenRobotBase
{
protected override void OnWaveletSelfAdded(IEvent e)
{
IBlip blip = e.Wavelet.AppendBlip();
ITextView textView = blip.Document;
textView.Append("I'm alive and running in C#!");
}
protected override void OnWaveletParticipantsChanged(IEvent e)
{
IBlip blip = e.Wavelet.AppendBlip();
ITextView textView = blip.Document;
textView.Append("Hi, everybody from C#!");
}
}
}Basically the .NET API is based on the Java one (it's pretty much a direct port with a few name changes to make it more like a normal .NET API) so anything you read about the Java API is worth trying in .NET too. Testing your robotTo test your robot, you just need to invite it to a wave. Add it as a contact (e.g. demorobot@appspot.com) then create a new wave. When you invite it to the wave, it should respond with (for the demo code above):
Congratulations - if you've made it this far, I'd really appreciate it if you'd drop me an email (skeet@pobox.com) to let me know, including any suggestions for improving this little tutorial. |
The REMOTE_ROBOT url must be on port 80 otherwise it won't work.
I've tried running this under Mono and it seems to be running fine without any problems, no special configuration needed either. Just build it using Visual Studio and run it on the server.