XMPPHP as live support chat

1.9k views Asked by At

My idea is to integrate a live support chat on a website. The users text is send with xmpphp to my jabber client with the jabberbot sender id and if I answer, the jabber bot, takes my answer and transfers the text to the user.

There is only one problem. How do I separate different users or different chats? I don't want all users to see the answer, but the user who asks. Is there a kind of unique chat id or another possibility, that I might just missed?

User => Website => Chatbot => me

I want to answer and send it back to the user, but how can I find out the correct user from my answer?

3

There are 3 answers

0
GreenRover On BEST ANSWER

Last time I have to solve this problem I used this architecture:

enter image description here

Entlarge image

The Webserver provides an JavaScript / jQuery or flash chat.

After chat is started, the client ask the server all 1 Second for new Messages.

Alternative for 1 Sec Polling

If that is to slow for you, have a look at websockets.

http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial

http://demo.cheyenne-server.org:8080/chat.html

But Websockets could no provided by php. There for you need to change php + apchache agaist node.js or java.

Plain HTTP PHP Methode

In PHP you will connect to the PsyBnc with is polling the messages from the supporter for you.

The PsyBnc is an IRC bot.

The reason why don't directly connect to XMPP or BitlBee is that those protocols don't like the flapping connect, disconnect from PHP. Because you can not keep the session alive, you need something that is made for often and short connects. This is the PsyBnc.

I would use something like this:

http://pear.php.net/package/Net_SmartIRC/download

<?php
session_start();

$message = $_GET['message'];
$client_name = $_GET['client_name'];

if (empty($_SESSION['chat_id'])) {
    $_SESSION['chat_id'] = md5(time(). mt_rand(0, 999999));
}

if (empty($_SESSION['supporter'])) {
    // how do you select the supporter? 
    // only choose a free?
    // We send first message to all supporter and the first who grapped got the chat (where only 3 gues)
}

$irc_host = "127.0.0.1";
$irc_port = 6667; // Port of PsyBnc
$irc_password = "password_from_psy_bnc";
$irc_user = "username_from_psy_bnc";

include_once('Net/SmartIRC.php');

class message_reader
{
    private $messages = array();

    public function receive_messages(&$irc, &$data)
    {
        // result is send to #smartirc-test (we don't want to spam #test)
        $this->messages[] = array(
            'from' => $data->nick, 
            'message' => $data->message,
        );  
    }

    public function get_messages() {
        return $this->messages;
    }
}

$bot = &new message_reader();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_DEBUG_ALL);
$irc->setUseSockets(TRUE);
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^' . $_SESSION['chat_id'], $bot, 'receive_messages');
$irc->connect($irc_host, $irc_port);
$irc->login($_SESSION['chat_id'], $client_name, 0, $irc_user, $irc_password);
$irc->join(array('#bitlbee'));
$irc->listen();
$irc->disconnect();

// Send new Message to supporter
if (!empty($message)) {
    $irc->message(SMARTIRC_TYPE_QUERY, $_SESSION['supporter'], $message);
}

echo json_encode(array('messages' => $bot->get_messages()));

Connect the support instant messanger to PHP

We have allready an IRC connection to the PsyBnc, now we need to send messages from IRC to ICQ, XMPP, GOOGLE TALK, MSN, YAHOO, AOI...

Here for is a nice solution named BitlBee. BitlBee offers an IRC Server with can transfer message from and to nearly all instant messager protocols. By aliasing those accounts. For example you need for your system only 1 Server account at google talk, icq ... and at all your supporter to the buddylist of those accounts. Now BitleBee will provide your boddylist as an irc chat.

0
Magnus On

Your requirements are rather confusing. As Joshua said, you don't need a Jabber bot for this. All you need is a Jabber server - which you should already have. What you do is, you create a volatile user account sessionid@*yourdomain.com* whenever the chat feature is used and then you can just reply to any incoming message like normal while your website client can fetch the messages meant for it whenever.

Alternatively you could create one user account - qa@yourdomain.com - and use XMPP resource identifiers for the routing part. XMPP allows for something like qa@yourdomain.com/*sessionid* and you should be able to tell your XMPP library to only query a specific resource. Most XMPP client software will also reply to a specific resource by default and open a new conversation when applicable. This method is less "clean" than the first, but it would work somewhat better if you can't arbitrarily create user accounts for some reason.

0
Robin On

I don't know what XMPP server you are using, but you could also try the Fastpath plugin and webchat for Openfire. Which is meant to provide a support team service over XMPP.

That being said, your question itself seems to imply nothing more than the standard chat feature of XMPP, which is between two users. It just means that the support person has a unique chat with each user asking a question. No other user will see that conversation.