Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

botsito

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botsito

Mentor bot

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Botsito extension

Extending botsito is pretty straight forward. Within the scripts/students directory, create a new file. In the file, declare a named function. Let's use a for the purposes of example.

function a() {

}

In order to interact with botsito, our function will receive it as a parameter.

function a(botsito) {

}

Having botsito within our function scope allows us to interact with it. The following methods are available:

botsito.logger.info

Logs to the console. Helpful for debugging.

Takes in a single parameter. The value of what is gonna be logged.

Returns undefined.

function a(botsito) {
  botsito.logger.info('function "a" is being loaded');
}

botsito.logger.error

Logs to the console. It's used when we want to inform ourselves that something went wrong.

Takes in a single parameter. The value of what is gonna be logged.

Returns undefined.

function a(botsito) {
  botsito.logger.error(new Error('omg something went wrong'));
}

botsito.brain.get

Looks for a previously stored value in botsito.

It takes a single parameter. The key used to fetch the value;

Returns the value previously stored.

function a(botsito) {
  var b = botsito.brain.get('my key');
  if (!b) {
    return botsito.logger.error(new Error('b is undefined!'));
  }
}

botsito.brain.set

Stores a value within botsito.

Takes two parameters. First parameter is the key for which you will look for it later via botsito.brain.get. The second parameter is the value you wish botsito to store.

function a(botsito) {
  botsito.brain.set('my key', 'my valueeee');
  var b = botsito.brain.get('my key');
  if (!b) {
    return botsito.logger.error(new Error('b is undefined!'));
  }

  botsito.logger.info(b);
}

botsito.listen

Interface in which botsito receives messages and acts upon them.

Takes two parameters. Both are functions.

First parameter function receives a single parameter called msg. It holds properties like text (the message posted) and user (the poster of the message). In this function you will determine if you will act upon the msg received. This function must return true or false.

Second parameter function receives a single parameter called response. It holds the method reply which allows us to write to the channel. This is where you will put the bulk of your logic will live. This function will only be called if the first parameter function returned true.

function a(botsito) {

  function validator(msg) {
    var willReply = false;
    if (msg.text.indexOf('pi time') !== -1) {
      willReply = true;
    }
    return willReply;
  }

  function postBack(response) {
    return response.reply('PI TIMEEEEE');
  }

  botsito.listen(validator, postBack);
}

This function will listen for messages that include the phrase pi time and will reply with PI TIMEEEEE to the channel.

The response object also contains additional information inside the envelope property. Try logging this property out to see what you learn.

Exposing the function

Once you are satisfied with your function, we need to make it readable. To do so, add the following line at the end of your file:

module.exports = a;

That's it! Now your function is ready to join botsito.

FAQs

Package last updated on 14 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc