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?
source share