API Version: Development

Chat Echo Bot in Node.js


This is the same example as the other chat echo bot example except that it is run inside the Node.js environment. This makes sense because it doesn't have a logical User Interface.
var IPCortex = require('ipcortex-pabx');

  username: '<username>',
  password: '<password>'
  function() {
    console.log('Login successful');
    /* Get the API to start collecting data */
      function() {
        console.log('Live data feed started');
        /* Enable the chat subsystem */
          /* Provide a callback for new rooms */
          function (ourRoom) {
            /* Add an update listener to each new room */
            ourRoom.addListener('update', function (room) {
              /* Inspect new messages and echo ... */
              room.messages.forEach(function (message) {
                console.log(message.cN + ' has decreed: ' + message.msg);
                /* ... except my own messages */
                if (!message.own)
                room.post('Apparently you decreed: ' + message.msg);
      function() {
        console.log('Live data feed failed');
  function() {
    console.log('Login failed');
This is the complete application!
To try it out, run the following commands:
npm init
npm install --save ipcortex/node-api
node node_modules/ipcortex-pabx/updateAPI.js http://pabx.hostname
Then save the code above in the root folder of your npm project and run it with node (e.g. node index.js). You should receive all the appropriate success messages.
Test this in the same way as the browser-hosted version.
NOTE: if you are using self-signed certificates with your IPCortex Communication System and receiving errors then set the NODE_TLS_REJECT_UNAUTHORIZED environment variable to 0. However, please don't use this in anything near a production system as this is essentially turning off security.