Skip to content

Latest commit

 

History

History

xmpp_wikibot

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Wikibot example that can be run on Google Compute Engine

Open in Cloud Shell

This sample shows how to use the SleekXMPP client and Flask to build a simple chatbot that can be run on Google Compute Engine. The chatbot does two things:

  1. Sends messages to XMPP users via http get:

    • The server is running on port 5000
    • if running on virtual machine use: http://<MACHINE IP>:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>
    • If running locally use: http://localhost:5000/send_message?recipient=<RECIPIENT ADDRESS>&message=<MSG>
  2. Responds to incoming messages with a Wikipedia page on the topic:

    • Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using
    • It should respond with a Wikipedia page (when one exists)

Setup

Follow the instructions at the Compute Engine Quickstart Guide on how to create a project, create a virtual machine, and connect to your instance via SSH. Once you have done this, you may jump to Installing files and dependencies.

You should also download the Google Cloud SDK. It will allow you to access many of the features of Google Compute Engine via your local machine.

IMPORTANT You must enable tcp traffic on port 5000 to send messages to the XMPP server. This can be done by running the following SDK commands:

gcloud config set project <YOUR PROJECT NAME>

gcloud compute firewall-rules create wikibot-server-rule --allow tcp:5000 --source-ranges=0.0.0.0/0

Or you can create a new firewall rule via the UI in the Networks section of the Google Cloud Console.

Installing files and dependencies

First, install the wikibot.py and requirements.txt files onto your remote instance. See the guide on Transferring Files for more information on how to do this using the Mac file browser, scp, or the Google Cloud SDK.

Before running or deploying this application, you must install the dependencies using pip:

pip install -r requirements.txt

Running the sample

You'll need to have an XMPP account prior to actually running the sample. If you do not have one, you can easily create an account at one of the many XMPP servers such as xmpp.jp. Once you have an account, run the following command:

python wikibot.py -j '<YOUR XMPP USERNAME>' -p '<PASSWORD>'

Where the username (e.g., '[email protected]') and password for the account that you'd like to use for your chatbot are passed in as arguments.

Enter control-C to stop the server

Running on your local machine

You may also run the sample locally by simply copying wikibot.py to a project directory and installing all python dependencies there.