-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
190 lines (136 loc) · 7.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<head>
<title>Keyword Bot</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul class="sections">
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<h1 id="keyword-bot">Keyword Bot</h1>
<h1 id="summary-and-configuration">Summary and Configuration</h1>
<p>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:</p>
<p>KEYWORD_1: ‘hours: We are open every day from 9 to five’</p>
<h2 id="things-to-keep-in-mind-">Things to keep in mind:</h2>
<ul>
<li>Use only one colon (:) for each keyword, or you’ll confuse the bot</li>
<li>You can put any keyword in any of the ten settings. Only the order</li>
<li>in which we report the choices matters to what you use.</li>
</ul>
<h1 id="installation">Installation</h1>
<p>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’</p>
<p>This bot requires a ruby installation, 2.0 or older</p>
<h1 id="annoated-bot-code">Annoated Bot Code</h1>
<h2 id="full-source-in-git-repo">Full source in git repo</h2>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<p>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’</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">keyword</span><span class="hljs-params">(str)</span></span>
str.split(<span class="hljs-string">':'</span>).first.strip.downcase
<span class="hljs-keyword">end</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">response</span><span class="hljs-params">(str)</span></span>
str.split(<span class="hljs-string">':'</span>).last
<span class="hljs-keyword">end</span></pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>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.</p>
</div>
<div class="content"><div class='highlight'><pre>initial_msg = ENV[<span class="hljs-string">'INITIAL_MSG'</span>].strip.downcase</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>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.</p>
</div>
<div class="content"><div class='highlight'><pre>keywords = {}
<span class="hljs-string">%w( KEYWORD_1 KEYWORD_2 KEYWORD_3 KEYWORD_4 KEYWORD_5 KEYWORD_6 KEYWORD_7
KEYWORD_8 KEYWORD_9)</span>.each <span class="hljs-keyword">do</span> |p|</pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<p>For each of the settings, check to see that it isn’t empty,
And that it includes the prompt separator (:)</p>
</div>
<div class="content"><div class='highlight'><pre> setting = ENV[p]
<span class="hljs-keyword">next</span> <span class="hljs-keyword">if</span> setting.<span class="hljs-keyword">nil</span>? || setting.empty?
<span class="hljs-keyword">next</span> <span class="hljs-keyword">unless</span> setting.<span class="hljs-keyword">include</span>?(<span class="hljs-string">':'</span>)</pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<p>Fill in the hash with the keyword as the key, and the rest of the string
as the response to that keyword.</p>
</div>
<div class="content"><div class='highlight'><pre> keywords[keyword(setting)] = response(setting)
<span class="hljs-keyword">end</span>
<span class="hljs-keyword">if</span> keywords.keys.<span class="hljs-keyword">include</span>? initial_msg</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">¶</a>
</div>
<p>the message that somebody texted in matches one of our keywords.
Send back the matching response.</p>
</div>
<div class="content"><div class='highlight'><pre> puts keywords[initial_msg]
<span class="hljs-keyword">else</span></pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">¶</a>
</div>
<p>the message that somebody texted does not match any of our keywords.
Send back the valid choices.</p>
</div>
<div class="content"><div class='highlight'><pre> puts <span class="hljs-string">"Please choose from: <span class="hljs-subst">#{keywords.keys.join(<span class="hljs-string">','</span>)}</span>"</span>
<span class="hljs-keyword">end</span></pre></div></div>
</li>
</ul>
</div>
</body>
</html>