Django XMPP Live Chat System

I need to implement an XMPP based live-chat system in Django. After a lot of flagellation and ideas from a colleague, we came up with this.


Method using the bot:

  • When a visitor visits a site. The XMPP client, which in this case is Strophe.JS, starts an XMPP-over-BOSH connection with the XMPP server and connects to a room called <visitor_id>@conference.demo.com . There is currently no one else in the room.
  • Visitor makes analytics request with user visitor id in Django
  • The Django view stores the visitor identifier in a table called ActiveUsers . This table contains a new field, also called status . It sets status to INACTIVE .
  • This model sends a signal using the save method.
  • This signal is received by a bot that connects to the XMPP server and joins the room <visitor_id>@conference.demo.com . Now we have a user and a bot in the room.
  • Users who support the site are logged into their web interface.
  • They have JS code that allows you to check the Django site for a long time to check ActiveUsers . It extracts rows from the table and displays it. (I was thinking about using django-pubsub for this)
  • When a visitor enters a message, he goes through XMPP-over-BOSH to the XMPP server, the bot jabber in the room sees this message and updates the status of the entry in the ActiveUsers table to ACTIVE .
  • As said: The people who support the site have JS that continues to poll this table. It starts flashing to indicate that the user is chatting now.
  • Support staff can now double-click this line, which at the same time starts the XMPP-over-BOSH connection with the guest room. He knows the room is <visitor_id>@conference.demo.com .
  • The bot, upon seeing that a fellow person has joined the room, updates the ActiveUsers entry to show CHATTING . This ensures that the room can be no more than the attendants, i.e. Busy room.
  • Bot logs messages in Django table
  • When both users see that both users left the room, it deletes the entry.

ejabberd or openfire will be an XMPP server. Apache is a web server running mod_wsgi to serve Django and mod_proxy to proxy XMPP-over-BOSh requests to the XMPP server.

Does that sound so good? Any suggestions? I am worried about booting a Django system.

(It's a long time. Sorry, this.)


Method using Presence Stanzas:

On the client side, I use the Strophe JS library, which supports presence, and I have added callback methods. I can use ejabberd or openfire as my XMPP server. Many visitors to the XMPP server are some of sites A and some of sites B, but they are all connected to the same XMPP server. When a visitor visits the site, they connect to the XMPP server as <visitor_id>_<site_id>@demo.com , and each of them registers in a room called <visitor_id>@conference.demo.com . Sales / Support staff are also connected to the XMPP terminal as <supportsale_id>_<site_id>@demo.com . However, they are not connected to any chat room. They have no visitors on their list.

A good way to show that a user has connected to a site is to convey the presence stanza to people involved in sales / support. Only visitors and sales / support specialists from the same site communicate with each other and why I have <site_id> in the username to indicate which site this person belongs to.

It seems that you cannot sign up for stanzas for the user if you do not have it on your list. (Pretty logical). Is it possible to automatically add each new user of a site connecting to the system to the list of sellers / users of support for this site? Would it not automatically signal presence for sellers / people of support? How can I implement this - any help?

+4
source share
3 answers

I wrote just that. It is called Seshat and uses a mediation bot between the site and the Jabber server (I use ejabberd). This is in beta now, mainly because it has not been thoroughly tested outside of my company.

Note: while README specifically mentions Pyramid's web infrastructure, the main system will work just as well as with a Django, TurboGears or command line system. It's just that I am just an example code example showing how to integrate it with Pyramid.

Seshat is actively developing. If you have any wishes, let me know. :-)

+2
source

I think that it is better to use presence lines to "signal" any (in) activity. What needs to be stored in the database is only the constant data necessary for further analysis. Otherwise, I think you will have a great time coding the application :).

EDIT:

 function onConnect(status) { if (status == Strophe.Status.CONNECTED) { var joined = false; var participants = {}; $('#events').html('<text class="textmainleft">XMPP connection established. Ready to rock n roll!</text>'); connection.send($pres().c('priority').t('-1')); connection.addHandler(notifyUser, null, 'message', 'groupchat', null, null); connection.send($pres({to: ' groupchatroom@conference.demo.com /' + nickname}).c('x', {xmlns: 'http://jabber.org/protocol/muc'})); } else if (status == Strophe.Status.AUTHFAIL) { $(location).attr('href', AUTHFAIL_URL); } else if (status == Strophe.Status.CONNFAIL) { $(location).attr('href', AUTHFAIL_URL); } } $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.connect(jid, password, onConnect); }); 

notifyUser is another function (just an onConnect link) that would process received message stanzas.

+1
source

I'm not sure if you need to use MUC to implement this. Your bot could save its own pubsub node to which it is subscribed. When a new user starts typing it, he can send a notification to the pubsub node, which the bot will then see. From there, the bot could notify the support person via XMPP, thereby eliminating the need for lengthy polling of the database table. The support user can then start a standard chat session with the end user. In addition, their presence can be set to "na" to indicate that they are in a session with the user.

+1
source

All Articles