XmppFlask is considered to be simple (it might be not there yet, but we are constantly working no it).
So let’s begin with “hello world” app.
Note
We use PyPy interpreter to run things, but you may want to use standard CPython instead.
Go to http://pypy.org , download latest pypy, unpack it somewhere and make
sudo ln -s /absolute/path/to/pypy/bin/pypy /usr/local/bin/pypy
Now create a virtual environment for you application. First install latest virtualenv to do that:
sudo easy_install --upgrade virtualenv
Then create an environment:
mkdir ~/v
virtualenv -p /usr/local/bin/pypy ~/v/ping-env
Now go ahead and activate that environment:
source ~/v/ping-env/bin/activate
From now on you can install things and they will only harm your virtual environment.
Right now the simplest way is just to clone the source repository
hg clone https://k_bx@bitbucket.org/k_bx/xmppflask
cd xmppflask
python setup.py install
cd to your project’s folder (like ~/workspace/pingpong and write file called pingpong.py
# -*- coding: utf-8 -*-
from xmppflask import XmppFlask
app = XmppFlask(__name__)
@app.route(u'ping')
def ping():
return u'pong'
This small app responses “pong” to every “ping” message it gets. Now we need to run that somehow.
If you have setuptools package installed the simplest way to run your XMPPWSGI app would be using xmppflask console script. The other way to run your app is python path/to/xmppflask/run.py - xmppflask is just handy shortcut.
xmppflask --jid xmppflask@example.com \
--password isecretlyusedjango ./pingpong.py:app
Note
You need to already have xmppflask@example.com jabber account with that strange password.
Warning
Passing JID and his password as command line arguments may be not very secure idea. As alternative solution, you could set them via XMPPFLASK_JID and XMPPFLASK_PASSWORD environment variables. Also you may skip this arguments - they will be asked to be promted from tty.
Now run that and you should see something like this:
(xmpp)kost@kost-narwhal:~/workspace/pingpong$ xmppflask \
--jid xmppflask@example.com --password isecretlyusedjango ./pingpong.py:app
INFO:root:connecting...
INFO:root:done.
WARNING:root:Unable to estabilish secure connection - TLS failed!
INFO:root:> bot started!
Now go ahead and write something to our bot. Pidgin can be your friend!
Great! Now you can go to Overview page and see what else is there.