HowTo: Make a robot create a new Wave (Python)

6 views
Skip to first unread message

Daniel Faust

unread,
Oct 10, 2009, 3:24:34 AM10/10/09
to Google Wave API
Hi,

I myself had trouble with this issue and saw that it was asked for
several times. I found the solution and want to share it, so here it
goes:

def OnBlipSubmitted(properties, context):
doc = context.GetBlipById(properties['blipId']).GetDocument()
text = doc.GetText()
if text.find('/createWave') == 0:
_newWave = robot_abstract.NewWave(context,
context.GetRootWavelet().GetParticipants())
_newWave.SetTitle("New Wave's Title")
_newRootBlipId = _newWave.GetRootBlipId()
_newRootBlip = context.GetBlipById(_newRootBlipId)
_newDocument = _newRootBlip.GetDocument()
_newDocument.AppendText("This is an additional Text")

Daniel Faust

unread,
Oct 10, 2009, 3:25:30 AM10/10/09
to Google Wave API
Oh, right, and you need to add
__ from waveapi import robot_abstract __
to your file

Ernie Turner

unread,
Oct 14, 2009, 12:52:36 AM10/14/09
to Google Wave API
Thank you! This is exactly what I was trying to do, and your code work
great. A follow up question though. Do you know if it's possible to do
this without having a beginning wave to begin with? That is, is it
possible to create the 'context' variable just from the API? I've read
a few other posts about this and I haven't found anyone saying it was
possible.

Again, thanks for the sample code.

On Oct 10, 1:25 am, Daniel Faust <soundlin...@gmail.com> wrote:
> Oh, right, and you need to add
> __ from waveapi import robot_abstract __
> to your file
>
> On Oct 10, 9:24 am, Daniel Faust <soundlin...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I myself had trouble with this issue and saw that it was asked for
> > several times. I found the solution and want to share it, so here it
> > goes:
>
> > def OnBlipSubmitted(properties, context):
> >   doc = context.GetBlipById(properties['blipId']).GetDocument()
> >   text = doc.GetText()
> >   if text.find('/createWave') == 0:
> >     _newWave       = robot_abstract.NewWave(context,
> > context.GetRootWavelet().GetParticipants())
> >     _newWave.SetTitle("NewWave'sTitle")

heitzig-j

unread,
Oct 23, 2009, 12:48:37 PM10/23/09
to Google Wave API
Is this also possible in Java? The corresponding classes AbstractRobot
or AbstractRobotServlet do not seem to have a similar method like
NewWave in python...

Austin Chau (Google employee)

unread,
Oct 23, 2009, 4:15:39 PM10/23/09
to google-...@googlegroups.com
Yes you can do that in Java.  The two client libraries mirror each other with respect to the underlying wire protocol.  To create new wave in Java you use this method from Wavelet - 

public Wavelet createWavelet(List<String> participants, String dataDocumentWriteBack);

Austin

yariv.snapir

unread,
Oct 25, 2009, 3:45:27 AM10/25/09
to Google Wave API
Thanks. this helps!
I believe that we can establish that both in python and java we can
create a new **wavelet** but not a new standalone wave. IMHO, creating
a new wave would not be a task of a robot since a robot must be IN a
wave to actually run.
This should be part of the client (embed) API so that hosting
applications would be able to create new waves and manage this waves
in the context of the app...

Regards

Yariv

On Oct 23, 10:15 pm, "Austin Chau (Google employee)"

dLux

unread,
Oct 25, 2009, 7:55:12 AM10/25/09
to Google Wave API
I disagree. I really would like my robot to create new waves for the
wave user. Of course somehow the wave user has to authorize the robot
to do that, but I have many use cases in my mind where robots has to
create waves.

Balázs

yariv.snapir

unread,
Oct 25, 2009, 9:25:36 AM10/25/09
to Google Wave API
I think you can usea new wavelet as an actual new wave...
Anyway, once I create a new wavelet - I would like my robot to get the
new wavelet/wave id so I can use this id to embed the wave in my
application's UI. How can I get this ID? (I tried both
newWavelet.getWaveletId() and newWavelet.getWaveId() - neither
produced the type of ID I need... (I got 'TBD0.8622343911850655' where
the ID needed looks more like: 'w+iFA2MNGuP'... I wonder what is the
code used by the embeddy robot to create this ID (it seems its hidden
somewhere in the embeddy gadget).

Regards

Yariv

On Oct 25, 1:55 pm, dLux <d...@dlux.hu> wrote:
> I disagree. I really would like myrobottocreatenewwaves for thewaveuser. Of course somehow thewaveuser has to authorize therobot
> to do that, but I have many use cases in my mind where robots has tocreatewaves.
>
> Balázs
>
> On Oct 25, 8:45 am, "yariv.snapir" <yariv.sna...@gmail.com> wrote:
>
>
>
> > Thanks. this helps!
> > I believe that we can establish that both inpythonand java we can
> >createanew**wavelet** but not anewstandalonewave. IMHO, creating
> > anewwavewould not be a task of arobotsince arobotmust be IN a
> >waveto actually run.
> > This should be part of the client (embed) API so that hosting
> > applications would be able tocreatenewwaves and manage this waves
> > in the context of the app...
>
> > Regards
>
> > Yariv
>
> > On Oct 23, 10:15 pm, "Austin Chau (Google employee)"
>
> > <api.aus...@google.com> wrote:
> > > Yes you can do that in Java.  The two client libraries mirror each other
> > > with respect to the underlying wire protocol.  Tocreatenewwavein Java

David Nesting

unread,
Oct 25, 2009, 11:29:49 AM10/25/09
to google-...@googlegroups.com
On Sun, Oct 25, 2009 at 6:25 AM, yariv.snapir <yariv....@gmail.com> wrote:
produced the type of ID I need... (I got 'TBD0.8622343911850655' where
the ID needed looks more like: 'w+iFA2MNGuP'... I wonder what is the\

The methods you use to respond to an event notification do not have immediate results.  The operations are all batched up and sent back to the server when you're done handling the event.  So, until that happens, all of the IDs generated as you create new blips/wavelets are "TBD".  I don't believe there's a way for you to get these IDs after the fact, unless you left yourself some signal or annotation, and used some Yet To Be Developed API to iterate over the wave again (after the conclusion of handling your event) to find your signal and identify the content you added.

David

dLux

unread,
Oct 26, 2009, 2:58:39 PM10/26/09
to Google Wave API
Just an idea to try, I'm not sure it works: add your robot to the
wavelet, and then you'll get back a SELF_ADDED event. Then you'll have
the ID. You can relay information with data documents of the main
blip. Let me know if it works. (I'll probably need it soon also :) ).

On Oct 25, 4:29 pm, David Nesting <da...@fastolfe.net> wrote:

Peter Svedberg

unread,
Oct 26, 2009, 4:42:06 PM10/26/09
to Google Wave API
Hi all,

Yes you will get the ids with a self added event, but you don't get a
self added event when you create a wavelet(wave) with a robot.

Here's how to create a wave with a robot in java (assuming you have a
handle on the current wavelet):
Wavelet newWave = wavelet.createWavelet(wavelet.getParticipants(),
"");

After you submit the operations you will get an unsolicitied
DOCUMENT_CHANGED event. I say unsolicited as you don't have to specify
it in the capabilities.xml file.

Look for the event in the servlet:
for (Event e : bundle.getEvents()) {
switch (e.getType()) {
...
case DOCUMENT_CHANGED:
processNewIds();
break;
...
}
}

public void processNewIds() {
if (wavelet.hasDataDocument("_new_ids_")) {
String newIds = wavelet.getDataDocument("_new_ids_");
// do whatever with the new ids
}
}

newIds looks like this:
:wavesandbox.com!w+Sxz7uLZkCxk wavesandbox.com!conv+root b+Sxz7uLZkCxl
\n
strip the colon and split on " " and you have waveId, waveletId and
rootBlipId

If we had specified a name for the writeback instead of the empty
string it would have shown up before the colon.

If you set the default logging level to INFO you'll see the event and
the new ids data document in app engine's Logs view.

Hope this helps
-Peter

yariv.snapir

unread,
Oct 27, 2009, 5:28:39 AM10/27/09
to Google Wave API
Indeed it helped!

Do you know of a way I can pass these IDs from the robot's code to the
embed JS API (event listeners perhaps) - I need a way to save the ID
of the newly created wave in my application...

Thanks

On Oct 26, 10:42 pm, Peter Svedberg <peter.o.s.svedb...@gmail.com>
wrote:

Shawn Smith

unread,
Dec 8, 2009, 12:21:54 AM12/8/09
to Google Wave API
Attempting to use this code and I don't seem to be receiving the
unsolicited call back? Is this still working for others?

On Oct 27, 1:28 am, "yariv.snapir" <yariv.sna...@gmail.com> wrote:
> Indeed it helped!
>
> Do you know of a way I can pass these IDs from the robot's code to the
> embed JS API (event listeners perhaps) - I need a way to save the ID
> of the newly created wave in my application...
>
> Thanks
>
> On Oct 26, 10:42 pm, Peter Svedberg <peter.o.s.svedb...@gmail.com>
> wrote:
>
>
>
> > Hi all,
>
> > Yes you will get the ids with a self added event, but you don't get a
> > self added event when youcreateawavelet(wave) with a robot.
>
> > Here's how tocreatea wave with a robot in java (assuming you have a
> > handle on the currentwavelet):
> >WaveletnewWave =wavelet.createWavelet(wavelet.getParticipants(),
> > "");
>
> > After you submit the operations you will get an unsolicitied
> > DOCUMENT_CHANGED event. I say unsolicited as you don't have to specify
> > it in the capabilities.xml file.
>
> > Look for the event in the servlet:
> >     for (Event e : bundle.getEvents()) {
> >       switch (e.getType()) {
> >        ...
> >        case DOCUMENT_CHANGED:
> >         processNewIds();
> >         break;
> >       ...
> >       }
> >     }
>
> >   public void processNewIds() {
> >     if (wavelet.hasDataDocument("_new_ids_")) {
> >       String newIds =wavelet.getDataDocument("_new_ids_");
> >       // do whatever with the new ids
> >     }
> >   }
>
> > newIds looks like this:
> > :wavesandbox.com!w+Sxz7uLZkCxk wavesandbox.com!conv+root b+Sxz7uLZkCxl
> > \n
> > strip the colon and split on " " and you have waveId, waveletId and
> > rootBlipId
>
> > If we had specified a name for the writeback instead of the empty
> > string it would have shown up before the colon.
>
> > If you set the default logging level to INFO you'll see the event and
> > the new ids data document in app engine's Logs view.
>
> > Hope this helps
> > -Peter
>
> > On Oct 26, 7:58 pm, dLux <d...@dlux.hu> wrote:
>
> > > Just an idea to try, I'm not sure it works: add your robot to the
> > >wavelet, and then you'll get back a SELF_ADDED event. Then you'll have
> > > the ID. You can relay information with data documents of the main
> > > blip. Let me know if it works. (I'll probably need it soon also :) ).
>
> > > On Oct 25, 4:29 pm, David Nesting <da...@fastolfe.net> wrote:
>
> > > > On Sun, Oct 25, 2009 at 6:25 AM,yariv.snapir <yariv.sna...@gmail.com>wrote:
>
> > > > > produced the type of ID I need... (I got 'TBD0.8622343911850655' where
> > > > > the ID needed looks more like: 'w+iFA2MNGuP'... I wonder what is the\
>
> > > > The methods you use to respond to an event notification do not have
> > > > immediate results.  The operations are all batched up and sent back to the
> > > > server when you're done handling the event.  So, until that happens, all of
> > > > the IDs generated as youcreatenew blips/wavelets are "TBD".  I don't

Shawn Smith

unread,
Dec 8, 2009, 12:25:44 AM12/8/09
to Google Wave API
The DOCUMENT_CHANGED event now appears to require setup in the
capabilities.xml file. I added it and that fixed up my issues.

S.

On Oct 26, 12:42 pm, Peter Svedberg <peter.o.s.svedb...@gmail.com>
wrote:
> Hi all,
>
> Yes you will get the ids with a self added event, but you don't get a
> self added event when youcreateawavelet(wave) with a robot.
>
> Here's how tocreatea wave with a robot in java (assuming you have a
> handle on the currentwavelet):WaveletnewWave =wavelet.createWavelet(wavelet.getParticipants(),
> "");
>
> After you submit the operations you will get an unsolicitied
> DOCUMENT_CHANGED event. I say unsolicited as you don't have to specify
> it in the capabilities.xml file.
>
> Look for the event in the servlet:
>     for (Event e : bundle.getEvents()) {
>       switch (e.getType()) {
>        ...
>        case DOCUMENT_CHANGED:
>         processNewIds();
>         break;
>       ...
>       }
>     }
>
>   public void processNewIds() {
>     if (wavelet.hasDataDocument("_new_ids_")) {
>       String newIds =wavelet.getDataDocument("_new_ids_");
>       // do whatever with the new ids
>     }
>   }
>
> newIds looks like this:
> :wavesandbox.com!w+Sxz7uLZkCxk wavesandbox.com!conv+root b+Sxz7uLZkCxl
> \n
> strip the colon and split on " " and you have waveId, waveletId and
> rootBlipId
>
> If we had specified a name for the writeback instead of the empty
> string it would have shown up before the colon.
>
> If you set the default logging level to INFO you'll see the event and
> the new ids data document in app engine's Logs view.
>
> Hope this helps
> -Peter
>
> On Oct 26, 7:58 pm, dLux <d...@dlux.hu> wrote:
>
>
>
> > Just an idea to try, I'm not sure it works: add your robot to the
> >wavelet, and then you'll get back a SELF_ADDED event. Then you'll have
> > the ID. You can relay information with data documents of the main
> > blip. Let me know if it works. (I'll probably need it soon also :) ).
>
> > On Oct 25, 4:29 pm, David Nesting <da...@fastolfe.net> wrote:
>
> > > On Sun, Oct 25, 2009 at 6:25 AM, yariv.snapir <yariv.sna...@gmail.com>wrote:
>
> > > > produced the type of ID I need... (I got 'TBD0.8622343911850655' where
> > > > the ID needed looks more like: 'w+iFA2MNGuP'... I wonder what is the\
>
> > > The methods you use to respond to an event notification do not have
> > > immediate results.  The operations are all batched up and sent back to the
> > > server when you're done handling the event.  So, until that happens, all of
> > > the IDs generated as youcreatenew blips/wavelets are "TBD".  I don't
Reply all
Reply to author
Forward
0 new messages