Skip to content

Instantly share code, notes, and snippets.

@tskrynnyk
Created December 30, 2010 02:00
Show Gist options
  • Save tskrynnyk/759358 to your computer and use it in GitHub Desktop.
Save tskrynnyk/759358 to your computer and use it in GitHub Desktop.
Command-line utility for sending jabber messages.
#!/usr/bin/python
# xsend: command-line utility for sending jabber messages
# http://xmpppy.sourceforge.net/
#
import sys,os,xmpp,time
if len(sys.argv) < 2:
print "Syntax: xsend JID msg"
sys.exit(0)
tojid = sys.argv[1]
#msg = ' '.join(sys.argv[2:])
data = sys.stdin.readlines()
msg = ' '.join(data)
username = 'user@domain.tld/resource'
password = 'yourpassword'
jid=xmpp.protocol.JID(username)
cl=xmpp.Client(jid.getDomain(),debug=[])
con=cl.connect()
if not con:
sys.exit()
auth=cl.auth(jid.getNode(),password,resource=jid.getResource())
if not auth:
sys.exit()
#cl.SendInitPresence(requestRoster=0) # you may need to uncomment this for old server
id=cl.send(xmpp.protocol.Message(tojid, msg))
time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending
#cl.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment