olark('api.chat.onBeginConversation', function() {
	// Your callback function
});

Notes

Whenever a visitor or operator sends the first message, the given callback function will be triggered.

Show premium users in visitor list

Olark already sends some nice information to the operator when the chat first begins, but you can send your own information too. Here’s how you might highlight that a visitor to your site is a premium customer:

<script>
// Triggers when the first message has been sent
// Including automated messages from the Greeter or Targeted Chat rules
olark('api.chat.onBeginConversation', function() {

    // Get the data from your own server as to whether the visitor is a premium account
    if (currentVisitorIsPremium) {

        // Notifies the operator - the visitor does not see this
        olark('api.chat.sendNotificationToOperator', {
            body: "This is a premium customer"
        });

    }

});
</script>

Send an automatic response if an operator does not answer within X seconds

While we encourage you to be as human as possible during your interactions, and avoiding as much canned copy as you can, we do recognize the fact that sometimes something comes up and you cannot answer a visitor’s chat right away. This example will send a response to a visitor after 60 seconds if the operator does not reply:

<script>
var maxMilliseconds = 60*1000; // make sure the visitor doesn't receive a reply within 60 seconds
var replyTimer = null;

olark("api.chat.onMessageToOperator", function() {
    replyTimer = setTimeout(function() {
    replyTimer = null;
    olark("api.chat.sendMessageToVisitor", {
        body: "Sorry! I'm a little busy at the moment but will get back with you soon."
        });
    }, maxMilliseconds);
});

olark("api.chat.onMessageToVisitor", function() {
    if (replyTimer) {
        clearTimeout(replyTimer);
    }
});
</script>