AccessGrid.org

Jabber

Venues use Jabber for instant messaging between AG users. Non-user entities like devices and services could be equipped with a Jabber responder, too. Imagine instrumentation that sends reports to a dedicated Venue (e.g., Fusion), or a multi-stage compute job that reports progress to a Venue (and directly to the person who submitted it, of course).

JabberSend.py

# This script creates a jabber client, connects to a chat room,
# sends a message, and disconnects. Applications could use this
# to send text to an Access Grid venue.

import sys
import logging
import getpass

from AccessGrid.Jabber.JabberClient import JabberClient,log
from AccessGrid import Log

jabberId = sys.argv[1]
message = ' '.join(sys.argv[2:])
jabberPwd = getpass.getpass('Password:')

# set up jabber server stuff
# note: modify these to suit the server and chatroom
jabberHost = 'jabber.mcs.anl.gov'
jabberPort = 5223
room = 'Argonne-National-Laboratory(vv3.mcs.anl.gov)'
conferenceHost = 'conference.mcs.anl.gov'

# set up logging to avoid underlying modules spewing to screen
log = Log.GetLogger(Log.Bajjer)
log.setLevel(Log.WARN)
Log.GetLogger('JabberClient').setLevel(Log.WARN)

# create the jabber client and connect
jabber = JabberClient()
jabber.Connect(jabberHost, jabberPort)

# set user info and login
name = jabberId
jabber.SetUserInfo(name,jabberId, jabberPwd, 'resource')
jabber.Login()

# join chat room, send message, and exit
jabber.SetChatRoom(room, conferenceHost)
jabber.SendPresence('available')
jabber.SendMessage(message)
jabber.SendPresence('unavailable')

try:
jabber._stream.unRegister()
except:
# silence error from bajjer
pass

Execution

This example takes the jabber username on the command line, followed by the words of the message you want to send. The script takes all the trailing words and composes a single message from them. It will prompt for the password when run.

python JabberSend.py jabberId All the words of the message you want to send

Suggested Further Work

  • Modify JabberSend.py to take a Venue URL, retrieve the Jabber room details, and send the message
  • Build Jabber bots to report items of interest to Venue chats
  • Build a web-based Jabber client using the AccessGrid JabberClient module (or using Bajjer directly) to enable mobile clients and web users to Jabber into Venues

login or register to post comments