npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chanakya

v3.3.4

Published

Bot Maker

Downloads

16

Readme

chanakya-core

Chanakya logo

Thanks Sachin Pol for the logo.

chanakya is a framework to author chat bots.

It consists of three parts :

  • core : the deployment agnostic bot maker.
  • platform : a set of plugin to which let you deploy your chat-bot in specific platform. Currently only facebook is supported.
  • nlp : a plugin to connect to a given nlp api to parse the text and trigger necessary response by the bot. Currently only wit.ai is supported.

Getting started

  1. Create a facebook page.
  2. Create a facebook web app.
  3. Go to your app settings and, under Product Settings, click "Add Product." Select "Messenger." For old version of developer console you should be able to click on messenger tab directly
  4. Get page access token as described here and keep a note of it.
  5. Clone chanakya-starter-kit.
  6. Open index.js and put your token.
  7. Run npm i
  8. Run ./ngrok http 3000
  9. Open another console and run node index.js
  10. Setup webhook as described here. In the callback url give the ngrok https url which will look like https://708f4702.ngrok.io. Remember to append /webhook. So the final url should look like https://708f4702.ngrok.io/webhook. Token should be the above token.
  11. Subcribe you app with the page as described here. Do not forget to replace your token.
  12. Phew no more steps ... head on to your facebook page, open message dialog and say hi. You should get 2 messages back.

Usage

Application bootstrap

We would need

index.js

var C = require('chanakya'),
  Cfb = require('chanakya-facebook');

var bot = C.bootstrap({
  mount: '<folder containing chankya artifacts>',
  expectation: '<entry expectation>',
  token: '<token>'
});

Cfb.init(bot);

Creating a response

chanakya.response takes 3 parameters

  • response name (String)
  • followup expectation state (String)
  • response creation method (Function). It have two parameters which get injected:
    • to contains the sender detail
    • validatorResult contains the result form the validator. You can use these two parameters to personalise or customize the response.
chanakya.response('fail', 'greetings', function (to, validatorResult) {
  return {
    text: `I am sorry ${to.first_name}, I am unable to understand what you mean.`
  };
});

Creating a expectation

chanakya.expectation also takes 3 parameters

  • expectation name (String)
  • validators list (Array) Although it's an array for now it will accept only one validator name
  • expectation rules (Function)

After the expectation receives a message from chat window is pass on the message to the validator isGreetings in this case and the result is injected into the 3rd paramter function, res in this case.

chanakya.expectation('greetings', ['isGreetings'], function (res) {
  switch (res) {
    case true:
      return {
        data: res,
        responses: ['fail', 'success']
      };
      break;
    case false:
      return ['fail'];
      break;
  }
});

Creating a validator

chanakya.validator also takes 3 parameters

  • validator name (String)
  • blank parameter (null)
  • Validation rules (Function)

Validator should always return a Promise. We are using Q to make a promise here.

core.validator('isGreetings', null, function (message) {
  return Q.fcall(function () {
    return message == 'hi';
  });
});

Contributing

License

The MIT License (MIT)

Copyright (c) 2016 Suman Paul

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.