Friday, 3 June 2016

How to check MongoDB is running with linux shell script?


#!/bin/bash

if pgrep mongod >>/dev/null ;then
    echo "Mongo DB Server is Running"
else
    echo "Mongo DB Server is not Running"
fi


Explanation: pgrep is signal process, it looks through running process and list the process id' s that matches the name of the process.

Monday, 30 May 2016

How to create skype bot in NodeJS


Prerequisites
  1. Microsoft Application Id, Secret.  Click here  to get Microsoft Application Id, Secret 
  2. Node JS, NPM Package Manager.
  3. Public Hosting Service IP/ Domain with supporting NodeJS Applications.
  4. Skype Bot Id   Click here to get Skype Bot Id.
  5. node   --version   v4.4.4, npm  -version   2.15.1

Step1: Creating the Empty NodeJS Project.
  1. Create a Directory SkypeBot.  
  2. cd to SkypeBot. 
  3. Create an empty NodeJS Project with   'npm init'.
Step2: Download Require NodeJS Libraries.
  1. npm  install restify --save
  2. npm install botbuilder --save
const restify = require('restify');
const skype = require('skype-sdk');
const builder = require('botbuilder');

Note: skype-sdk is not available in npm package manager or you will get empty directory while downloading from npm package manager. download it from here.

Step3: Create and Initialize the Skype BotService with Default Configurations.

const botService = new skype.BotService({
    messaging: {
        botId: "28:f53d6e20-1e46-4cee-884d-***************",
        serverUrl : "https://apis.skype.com",
        requestTimeout : 15000,
        appId: 'f53d6e20-1e46-4cee-884d-************',
        appSecret: 'vFkWqyob2Tvdc**********'
    }
});


Step4: Create REST API with Restify Server.
const server = restify.createServer();

Step5: Create Skype Event Handler's. 

botService.on('contactAdded', (bot, data) => {
    bot.reply(`Hello ${data.fromDisplayName}!`, true);
});

botService.on('personalMessage', (bot, data) => {
    bot.reply(`Hey ${data.from}. Thank you for your message: "${data.content}".`, true);
});

Step6: Create Skype POST Method API Call, Skype webhook will trigger with POST method and passing with bot Object & data. 

try{
server.post('/v1/chat', skype.messagingHandler(botService));
}catch(err){
console.log(err)
}

Step7: Create a Server listener

server.listen(process.env.PORT || 1328, function () {
    console.log('%s listening to %s', "skype bot", "https://bot.zerooneprograms.com/skype/");
    //console.log(bot);
});


For Working Sample Click Download here.


Reference:
  1. http://docs.botframework.com
  2. https://developer.microsoft.com/en-us/skype/bots/docs/tutorials/simple-nodejs
  3. http://docs.pandorabots.com/deployments/browser-integration/https://playground.pandorabots.com/en/bot/test/info/#
  4. http://docs.pandorabots.com/libraries/aiml-standard-library/
  5. http://docs.pandorabots.com/
  6. https://playground.pandorabots.com/en/tutorial/
  7. https://code.google.com/archive/p/program-ab/
  8. http://www.alicebot.org/aimlbots.htmlhttp://www.tutorialspoint.com/aiml/aiml_star_tag.htmhttp://stackoverflow.com/questions/9706769/any-tutorials-for-developing-chatbots/9707402#9707402
  9. http://docs.botframework.com/builder/node/guides/examples/#navtitle
  10. http://www.programmableweb.com/category/bots/frameworks
  11. https://docs.google.com/document/d/1wNT25hJRyupcG51aO89UcQEiG-HkXRXusukADpFnDs4/pub
  12. https://code.google.com/archive/p/aiml-en-us-foundation-alice/downloads