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

keyword-bot

v0.1.6

Published

A simple responder bot. Listens for a keyword, then responds as you would like

Downloads

4

Readme

Keyword Bot

Summary and Configuration

This bot responds to up to ten keywords with a simple response. For instance, you can set up this bot to respond to 'hours', 'location' and 'specials'. To configure the bot, fill in a setting with the keyword and the response separated by a colon. As an example, to setup a keyword for hours, fill this in on one of the keyword prompts:

KEYWORD_1: 'hours: We are open every day from 9 to five'

Things to keep in mind:

  • Use only one colon (:) for each keyword, or you'll confuse the bot
  • You can put any keyword in any of the ten settings. Only the order
  • in which we report the choices matters to what you use.

Installation

This bot can be installed on any GreenBot server through the web UI, or by through the command line at the greenbot-core root with a a 'npm install keyword-bot'

This bot requires a ruby installation, 2.0 or older

Annoated Bot Code

Full source in git repo

Convenience functions for separating the setting into the keyword and the response. For instance, KEYWORD_1 may be set to 'hours:We are open every day' The keyword function takes whatever is before ':' and defines that as a keyword, in this case 'hours'. The response function would take that same keyword string and define that as the response to the keyword (hours, in this case) as 'We are open every day'

def keyword(str)
  str.split(':').first.strip.downcase
end

def response(str)
  str.split(':').last
end

The first message we receive in from the user is also the keyword that the user wanted. It is held in the environment variable INITIAL_MSG. In order for this bot to work properly, it should either be set as the default bot (so it will get every keyword), or every keyword that is listed here should also be configured in the network handles to point to this bot.

initial_msg = ENV['INITIAL_MSG'].strip.downcase

Iterate over all of the settings given to the script, and seperate them out into the keyword and the response. Not all settings will be defined.

keywords = {}

%w( KEYWORD_1 KEYWORD_2 KEYWORD_3 KEYWORD_4 KEYWORD_5 KEYWORD_6 KEYWORD_7
    KEYWORD_8 KEYWORD_9).each do |p|

For each of the settings, check to see that it isn't empty, And that it includes the prompt separator (:)

  setting = ENV[p]
  next if setting.nil? || setting.empty?
  next unless setting.include?(':')

Fill in the hash with the keyword as the key, and the rest of the string as the response to that keyword.

  keywords[keyword(setting)] = response(setting)
end

if keywords.keys.include? initial_msg

the message that somebody texted in matches one of our keywords. Send back the matching response.

  puts keywords[initial_msg]
else

the message that somebody texted does not match any of our keywords. Send back the valid choices.

  puts "Please choose from: #{keywords.keys.join(',')}"
end