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

gitple-bot

v0.0.7

Published

Gitple bot integration ---------------------------

Downloads

95

Readme

Gitple bot integration

Chatbot deploy architecture

Bot Cluster for High availability & Load Balancing

Chatbot cluster architecture

  • Prerequisite
    • At least two nodes for high availability & Load Balancing.
  • Health Check
    • All nodes in the bot cluster check for alive through the health ckeck.
  • Leader Election
    • Leader nodes are elected through health checks.
    • The rest of the nodes are worker nodes.
  • Job Manager
    • The leader node distributes the job to worker nodes.

Prerequisite

Step 1) Visit workspace.gitple.io and create account.

Step 2) Download config.json file at Workspace Bots Management

Note that Pro pricing plan is required.

config.json file to be filled after above steps.

{
  "BOT_ID": "_your_bot_id_",
  "BOT_GATEWAY_SECRET": "_your_bot_secret_",
  "APP_CODE": "_your_app_code_"
}

Installation

npm install gitple-bot --save

How to Use

This example send 'Hello World' to user on bot start command.

let gitple = require('gitple-bot');

let botMgrConfig = require('./config.json'); // bot manager config
let botMgr = new gitple.BotManager(botMgrConfig);
botMgr.on('start', (botConfig, done) => {
  let myBot = new gitple.Bot(botMgr, botConfig); // start your bot instance
  myBot.sendMessage('Hello World!'); // do your stuff
  myBot.on('message', (message) => {
    myBot.sendMessage('echo message - ' + message);
  });
  return done();
});
botMgr.on('end', (botId, done) => {
  let myBot = botMgr.getBot(botId);
  myBot.finalize(); // finalize your bot instance
  return done();
});

This is more complex scenario. User can select a botton for bot command, otherwise user input is echo back.

Note that message format for UI components is here : message format

botMgr.on('start', (botConfig, cb) => {
  let myBot = new gitple.Bot(botMgr, botConfig);
  let myMessage = {
    t: 'Welcome to my bot!',  // title
    a: [                      // buttons
      { p: 'button', t: 'End talk!', c: '/quit' },
      { p: 'button', t: 'Human please', c: '/transfer' }
    ]
  };

  // After key-in indication for one second, user get welcom message on a bot startup.
  myBot.sendKeyInEvent();
  setTimeout(() => { myBot.sendMessage(myMessage); }, 1 * 1000);

  myBot.on('message', (message) => {
    if (message === '/quit') {
      myBot.sendCommand('botEnd');          // request to end my bot
    } else if (message === '/transfer') {
      myBot.sendCommand('transferToAgent'); // request to transfer to agent
    } else {
      // After key-in indication for one second, user get echo back message.
      myMessage.t = 'echo message - ' + message;
      myBot.sendKeyInEvent();
      setTimeout(() => { myBot.sendMessage(myMessage);  }, 1 * 1000);
    }
  });
  return cb();
});

How to add your bot link to FAQ answer.

You can put the following html code into your FAQ answer after replacing your bot id with _ID_:

<div>This is My Bot <br><button class="msg-format-btn" data-cmd='{ "t": "assignBot", "p": { "id": _ID_ } }'> My Bot </button></div>

Documentation

Please see the documentation here.

Example

  • hello world example here.
  • the simple example here.
  • the Dialogflow example here.

Message format

  • plain text messages(markdown-aware) or json format

  • json object format

{
  t: number; // create time in ms
  e: { // event
    keyIn: 's'|'t'   // "s" - key-in start, "t" - key-in stop
    read: number // message read event with time in ms
  };
  c: any;    // response command to send to the server
  m: string; // message text or html
  m: [       // object type message
    {
      t: string;         // text
      l: {               // link
        u: {url};        // url
        m: {mime type};  // type image/png, text/json ...
        n: string        // filename
      },
      s: { // slider
        n: // object max count in one slide
        p: // preview: page count of slide to display
        a: [
          interaction object
        ]
      },
      a: [ // interaction object
        {
          p: 'text'; // text template
          t: string; // text
          e: string; // echo back text, use as 't' value if 'e' doesn't exist, no echo back if 'e' is null
          c: any; // response command value to send to the server when user selection, use as 'e' value if 'c' doesn't exist
        };
        {
          p: 'image'; // image template
          u: string;  // image url
          t: string;  // title
          e: string;  // echo back text, use as 't' value if 'e' doesn't exist, no echo back if 'e' is null
          c: any; // response command value to send to the server when user selection, use 'e' value if 'c' doesn't exist
          l: { // link on press
            a: string; // url to open at new window, not open if 'l.a' is null
          };
        };
        {
          p: 'button'; // button template
          t: string;   // button text
          e: string; // echo back text, use as 't' value if 'e' doesn't exist, no echo back if 'e' is null
          c: any; // response command value to send to the server when user selection, use as 'e' value if 'c' doesn't exist
          l: { // link on press
            a: string; // url to open at new window
            u: string; // url to call by http get method
          };
        };
        {
          p: 'list'; // selecting list template
          t: string; // title text,
          e: string; // echo back text, use as 't' value if 'e' doesn't exist, no echo back if 'e' is null
          c: any; // response command value to send to the server when user selection, use as 'e' value if 'c' doesn't exist
        };
        {
          p: 'form';   // selecting form template
          f: 'select'; // form type
          r: boolean;  // required
          t: string;   // label text
          k: string;   // response value
          v: string;   // [optional] value
          d: string;   // [optional] default value
          o: [         // [optional]
            {
              v: string; // value
              t: string; // option text
            }
          ];
        };
        {
          p: 'form';   // selecting form template
          f: 'input';  // form type
          r: boolean;  // required
          t: string;   // label text
          k: string;   // response key
          v: string;   // [optional] response value
          d: string;   // [optional] default value
        };
        {
          p: 'form';     // selecting form template
          f: 'textarea'; // form type
          r: boolean;    // required
          t: string;     // label text
          k: string;     // response key
          ln: number;    // rows for 'textarea'
          v: string;     // [optional] response value
          d: string;     // [optional] default value
        }
      ]
    }
  ]
}

License

Copyright 2017 Gitple Inc.