DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

Question

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?

Solution

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.

OTHER TIPS

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.

As I understand it, you want to have a live chat solution on your website that will allow your visitors to chat with specific agents on your end, one-on-one.

I'd suggest applying some sort of Javascript XMPP library onto your website. When the user indicates they would like to converse with an agent, establish a connection to the publicly-facing XMPP server.

From there, you have two options: direct chat or conferences rooms.

With a direct chat, your user would speak directly with an agent who would already be signed onto the system. From there, your agent can converse with the visitor as normal. This approach is simple and straightforward, but it is one-to-one. (You'd probably have to load-balance across multiple agents for significant traffic.)

With a conference room, your visitor can join a specific room dedicated to the topic where your agents can be moderators in the room. Visitors can ask questions and collaborate with your agents, or they could open a direct chat with an agent in the room.

XMPP is an extremely flexible protocol; it's really just a matter of figuring out what you want to achieve.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow