# keyword-bot

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

Latest version **0.1.6** (published 2016-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install keyword-bot
pnpm add keyword-bot
yarn add keyword-bot
bun add keyword-bot
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2016-04-28 |
| First published | 2016-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Thomas Howe |
| Maintainers | howethomas |
| Keywords | green-bot, greenbot, bot, bashbot |

## Links

- npm: https://www.npmjs.com/package/keyword-bot
- Repository: https://github.com/green-bot/keyword-bot
- Issues: https://github.com/green-bot/keyword-bot/issues
- npm.io page: https://npm.io/package/keyword-bot

## Recent versions

- 0.1.6 (latest) — 2016-04-28
- 0.1.5 — 2016-04-28
- 0.1.4 — 2016-04-28
- 0.1.3 — 2016-04-28
- 0.1.2 — 2016-04-28
- 0.1.1 — 2016-04-28

## 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


```

---
_Source: https://npm.io/package/keyword-bot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
