This is a simple script demonstrating how to create a basic XMPP bot in Ruby.
The bot will authenticate to Gtalk, automatically accept any incoming “add contact” requests, and echo received messages back to the user — totally useless, but functional.
I've also included a little script to daemonize the bot using the Ruby Daemons gem.
./bot/gtalk-bot.rb and set your username and password - this could easily be abstracted out into a config file if desired.
If you wish to enable logging, open
./im.rb and change
Running the bot as a daemon is pretty straightforward:
ruby im.rb start # starts the bot ruby im.rb restart # restarts the bot ruby im.rb stop # stop the bot
To run the bot as a background process using Screen:
screen -dmS myGtalkBot ruby ./bot/gtalk-bot.rb
Or simply run the script from the command line (good for testing):
ruby ./bot/gtalk-bot.rb & # start the bot in the background