JavaScript API
The Channel.me JavaScript Chat API is a lightweight interface that is available after adding site_connect.js to your website.
A Quick Overview
The Channel.me JavaScript Chat API provides a lightweight publish/subscribe transport mechanism which you can use to interact with the chat system and enhance the experience for your customers. After loading, the page contains an extremely lightweight message broker which allows one to route Messages from publishers to multiple subscribers.
Messages are published to Topics. All subscribers to a Topic will get the message. A Topic is a string, much like a file-path. For example "truck/001/temperature". A subscriber can directly subscribe to a Topic, or use wildcards '+' and '#'. '+' matches exactly one word between the slashes, and '#' can be used at the end of a pattern to match all sub-topics.
Examples::
truck/0001/temperature- Matches the temperature publications oftruck0001.truck/+/temperature- Matches thetemperaturepublications of all trucks.+/+/temperature- Matches thetemperaturepublications of all vehicles.truck/0001/#- Matches all publishes oftruck0001on all its sub-topics.
Publish/Subscribe in Channel.me
After loading //channel.me/site_connect.js it is possible to subscribe and publish Topics on your local page.
site_connect.subscribe(topic, message_func, acknowledge_func)Subscribe totopic, when a message arrives which matches topic, themessage_funccallback will be called. Theacknowledge_funccallback will be called when the subscription is ready. This is needed because subscribing to topics on the site-connect frame is asynchronous. Callingsubscribereturns subscription id.site_connect.unsubscribe(subscription_id)Unsubscribe from the specifiedsubscription_id.site_connect.publish(topic, msg)Publish amsgundertopic.
Host Page
All topics on the host page begin with the '~/' character. Messages published under this topic are not transferred to the site-connect frame and remain local.
~/site_connect/readyThe site-connect frame is ready. Note that the site connect frame can be loaded independently of the host page.
Site-Connect Frame
The site connect scripts loads a separate frame which serves as a connection to the channel.me servers. When a customer agent starts a co-browse or chat session this frame is used to display the interface. Components can be loaded on demand during the lifetime of the host-page. During its lifetime messages can be published. Subscribers can subscribe to these messages by subscribing to the following set of topics.
Site-Connect Topics
~/site_connect/readyThe site connect is ready to go and has a customer contact code.~/site_connect/retryOccasionally, when the channel.me server is too busy the frame is returned without a code. The page is trying to get a new customer contact code.~/site_connect/errorThe page gave up trying to get a new customer contact code.~/site_connect/new_codeThe site connect frame gets a new customer contact code. This can happen after a co-browse session.
Co-browsing Topics
~pagesession/cobrowsing/startA co-browsing session is started.~pagesession/cobrowsing/stopA co-browsing session is stopped.
Site-Connect Frame Handling Topics
~pagesession/show_frameShow the site-connect frame. This is done when a chat requested is opened, or another component like the proactive chat request should be made visible.~pagesession/minimize_frameMinimize the site-connect frame. This is triggered when the user minimises the chat component.~pagesession/hide_frameCompletely hide the site-connect frame. This is done when the chat session is stopped.
Chat Button Topics
~/site_connect/chat_button/:button_id:/enabledThe chat button with id:button_id:is enabled. This means there is an agent available to receive an incoming chat message.~/site_connect/chat_button/:button_id:/disabledThe chat button with id:button_id:is disabled. This means there is no agent available to receive an incoming chat message.~pagesession/chat/triggerThe user clicked on a chat button. The message contains the id of the button.~pagesession/proactive/triggerThe proactive chat was triggered.
Javascript API
Stopping a Cobrowse Session.
site_connect.stop_session()
It is possible to stop an ongoing cobrowse session by enforcing a stop. This function signals the communication frame, and stops sending page updates to the channel.me server. The cobrowsing session will stop and the agent is notified. When the session is stopped the ~pagesession/cobrowsing/stop message is published via the publish subscribe api.