Skip to content

Instantly share code, notes, and snippets.

@wcalvert
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wcalvert/c76da79644297d95d768 to your computer and use it in GitHub Desktop.
Save wcalvert/c76da79644297d95d768 to your computer and use it in GitHub Desktop.
# ------------------------------------------
# Instructions
# ------------------------------------------
# 0. As of 26 Feb 2015, I recommend installing the xmpppy module located here: https://github.com/ArchipelProject/xmpppy
# It seems to actively maintained and some bugs have been fixed.
# 1. Create a "dummy" or "automation" Gmail account.
# 2. Fill in the user and password variables below with the credentials from step 1.
# 3. Run this script in a terminal and leave it running until step 6 is completed.
# 3A. You will probably get a SASL error (or similar) the first time you try to run this script. If so:
# Log into your dummy GMail account, and an email should show up letting you "enable less-secure apps" in your preferences.
# It might take a minute for the change to take effect.
# 4. Log into your "main" Gmail account - NOT the one created in step 1.
# 5. Send a chat to your dummy account.
# 6. Now look in your terminal. This script should have printed out the "masked" address used by GChat.
# Note: This process seems to work regardless of if your main Gmail account is signed into the
# "old style chat" or Hangouts.
import xmpp
user = "your_dummy_account@gmail.com"
password = "your_password"
server = ("talk.google.com", 5223)
def message_handler(connect_object, message_node):
print "Message received from: {}".format(message_node.getFrom())
message = "This is an automation message"
connect_object.send(xmpp.Message(message_node.getFrom(), message, typ="chat"))
jid = xmpp.JID(user)
connection = xmpp.Client(jid.getDomain(), debug=[])
connection.connect(server)
result = connection.auth(jid.getNode(), password)
connection.RegisterHandler("message", message_handler)
connection.sendInitPresence()
while connection.Process(1):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment