<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Trypticon: Tag actionmessenger</title>
    <link>http://trypticon.org/articles/tag/actionmessenger?tag=actionmessenger</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>If it ain't broke, break it.</description>
    <item>
      <title>Action Messenger 0.2.0</title>
      <description>&lt;p&gt;Today&amp;#8217;s new version of &lt;a href="http://trypticon.org/software/actionmessenger/"&gt;Action Messenger&lt;/a&gt; makes things slightly easier to read when sending messages:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def prod(user)
  recipient user.jid
  subject   'Prod'
  body      'You told me to give you a prod when I updated...'
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can send to multiple recipients too, just add them like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def spam
  recipients User.find_all.map { |u| u.jid }
  subject    'Buy chunky bacon'
  body       'Do I have a deal for you!'
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These changes have been in trunk for some time, however someone recently made me aware that the documentation doesn&amp;#8217;t describe basic things like where the config file should be.  This has been properly documented now, and hence the new version being pushed out.&lt;/p&gt;</description>
      <pubDate>Fri, 23 Mar 2007 20:04:00 +1100</pubDate>
      <guid isPermaLink="false">urn:uuid:390f7155-8edb-49de-9c2c-60068a08bc97</guid>
      <author>Trejkaz</author>
      <link>http://trypticon.org/articles/2007/03/23/action-messenger-0-2-0</link>
      <category>actionmessenger</category>
      <category>jabber</category>
      <category>software</category>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Directions for Action Messenger</title>
      <description>&lt;p&gt;Well, the first highly experimental release of &lt;a href="http://trypticon.org/software/actionmessenger/" title="Action Messenger"&gt;Action Messenger&lt;/a&gt; experienced a small amount of success, and a couple of people spotted some bugs which have been fixed in version 0.1.1.&lt;/p&gt;

&lt;p&gt;So now that everything works for small apps, how does it grow?  I do want to integrate into Typo,  and the default deployment for Typo uses FastCGI.  Whereas each FastCGI process is relatively long-lived, there are multiple instances, and they can&amp;#8217;t all be logged in at once [with the same resource.]&lt;/p&gt;&lt;p&gt;So I have a number of options for coping with having Action Messenger work from multiple Rails instances.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Have each instance login from a different resource.  This is the simplest approach, and the one which I&amp;#8217;m currently using on this site&amp;#8217;s Typo install: append the process ID onto the resource when logging in.  The main downside to this approach is that when I add presence support in, users who have added the bot would see all its multiple resources logged in at once.  Whereas this would start out fairly small (I use 5 instances on my Typo) for larger, more popular sites, you might end up with a few dozen bots online at the same time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have one instance of Rails nominate it as the master, and start a DRb server on a background thread.  The other instances would connect to the master when they need to send a message.  This would be the simplest approach for the end user, but seems difficult to implement.  Which server becomes the master?  Perhaps an instance simply tries to open a socket to the server, and if it fails, it tries to open a socket as the server.  In this fashion, there is always only one instance online, and when that instance goes offline (e.g. the process crashes) another one would pick it up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have the Rails app spawn a separate process to handle the server side of things, but otherwise do things exactly as #2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use something such as &lt;a href="http://opensvn.csie.org/ezra/rails/backgroundrb/" title="BackgrounDRb"&gt;BackgrounDRb&lt;/a&gt; to run the bot as one thread of a much more flexible server.  This approach is probably the most useful as things other than a Jabber bot might be run in this server, although at the moment I&amp;#8217;m not sure what.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write a simple, specialist Ruby bot, and require that bot to be started completely separately from Rails.  The Rails instances would then connect to the bot whenever they need something.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At the moment, #5 is my favourite option.  My main problem with this approach is &amp;#8211; how will the bot handle receiving messages?  Accessing the Rails models directly from the bot isn&amp;#8217;t the problem, the problem is coming up with an API just as clean as the current one.&lt;/p&gt;</description>
      <pubDate>Mon, 22 May 2006 22:16:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:86f30d27-e17a-403e-bb1a-08dee872330f</guid>
      <author>Trejkaz</author>
      <link>http://trypticon.org/articles/2006/05/22/directions-for-action-messenger</link>
      <category>software</category>
      <category>jabber</category>
      <category>rails</category>
      <category>ruby</category>
      <category>actionmessenger</category>
    </item>
    <item>
      <title>Jabbering with Action Messenger</title>
      <description>&lt;p&gt;Want to send instant messages from your Ruby on Rails app with the minimum amount of code and the maximum amount of testability?&lt;/p&gt;

&lt;p&gt;Then say hello to&amp;#8230; &lt;a href="http://trypticon.org/software/actionmessenger/" title="Action Messenger"&gt;Action Messenger&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Some time ago, the &lt;a href="http://typosphere.org/" title="TypoSphere"&gt;Typo&lt;/a&gt; weblog software introduced a new feature, where notifications of new articles or comments could be delivered via XMPP, or as it&amp;#8217;s more commonly known, Jabber.  The one catch with the feature was that it depended on the older Jabber4R library, which under certain versions of Ruby, simply failed to work.  Jabber4R has serious bugs in there which cause it to deadlock under any newer version of Ruby.&lt;/p&gt;

&lt;p&gt;I wanted to use the feature rather badly at the time, so I &lt;a href="http://typosphere.org/trac/ticket/582" title="Typo ticket 582: Jabber session doesn't login"&gt;patched it&lt;/a&gt; to use &lt;a href="http://home.gna.org/xmpp4r/" title="XMPP4R: a newer XMPP client for Ruby"&gt;XMPP4R&lt;/a&gt; instead.  The patch still hasn&amp;#8217;t been accepted, allegedly due to a &lt;a href="http://article.gmane.org/gmane.comp.web.typo.user/2343"&gt;lack of tests&lt;/a&gt;.  Granted, unit testing is big in the Rails world, but the original Jabber notification code didn&amp;#8217;t have unit tests either, so I just see this as an enormous hypocrisy where the developers don&amp;#8217;t write their own tests, and think that it&amp;#8217;s everyone else&amp;#8217;s responsibility to write the tests for them.&lt;/p&gt;

&lt;p&gt;So in any case because of this, it&amp;#8217;s likely that under the current state of affairs, the existing Jabber support in Typo will remain broken indefinitely.&lt;/p&gt;

&lt;p&gt;After all of that, I started thinking about unit testing the Jabber messaging part.  The main problem is that a Jabber communication library generally requires a network connection to operate.  Whereas this is usually avoided by using mock objects, XMPP4R exposes rather a lot of different classes, and mocking the entire library out is probably just a little unreasonable.&lt;/p&gt;

&lt;p&gt;So what you do is write a layer which has less things to mock out, and that&amp;#8217;s the basis of Action Messenger.  However, I couldn&amp;#8217;t stop at merely having this layer for mocking.  I had to go and make it possible to send a Jabber message with three trivial lines of code (two in the messenger layer, setting up the recipient and the body, and one in the controller to tell the messenger to send the message.)&lt;/p&gt;

&lt;p&gt;So that&amp;#8217;s what Action Messenger is.  There isn&amp;#8217;t much to it right now, but what&amp;#8217;s there is heavily unit tested, and has convenience built-in for making your own code which uses it, more testable.&lt;/p&gt;

&lt;p&gt;Enjoy, and as always, send complaints this way. :-)&lt;/p&gt;</description>
      <pubDate>Mon, 08 May 2006 23:24:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:25ed7f37-f3d3-40d1-bd85-0650db4141d9</guid>
      <author>Trejkaz</author>
      <link>http://trypticon.org/articles/2006/05/08/jabbering-with-action-messenger</link>
      <category>software</category>
      <category>jabber</category>
      <category>rails</category>
      <category>ruby</category>
      <category>actionmessenger</category>
    </item>
  </channel>
</rss>
