-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
170 lines (115 loc) · 6.04 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
<!DOCTYPE html>
<html>
<head>
<title>survey 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>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-comment">#!/usr/bin/env ruby</span></pre></div></div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<h1 id="survey-bot">survey bot</h1>
<h1 id="summary-and-configuration">Summary and Configuration</h1>
<p>This bot asks up to ten questions of the inbound messager, then stores
these answers. Questions are not validated, and do not trigger any
particular behaviors. If a question is blank, it is not asked.</p>
<p><a href="https://cloud.githubusercontent.com/assets/9991/15373000/3c6d6012-1d11-11e6-8a36-902716d06985.png">Survey bot flow chart</a></p>
<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 survey-bot’</p>
<p>This bot requires a ruby installation, 2.0 or older</p>
<h2 id="annoated-bot-code-full-source-in-repo">Annoated Bot Code - Full source in repo</h2>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">require</span> <span class="hljs-string">'./lib/greenbot.rb'</span> <span class="hljs-comment"># ./lib/greenbot.rb contains helper libraries</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">handle</span><span class="hljs-params">(prompt, fieldName= <span class="hljs-keyword">nil</span>)</span></span></pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>If there’s nothing to tell or ask, get out of here.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> prompt
<span class="hljs-keyword">if</span> fieldName.<span class="hljs-keyword">nil</span>?</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>No field name, so just say it.</p>
</div>
<div class="content"><div class='highlight'><pre> tell prompt <span class="hljs-keyword">if</span> prompt
<span class="hljs-keyword">else</span></pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<p>If there’s a field name, then we are asking for something.
Ask and remember the answer</p>
</div>
<div class="content"><div class='highlight'><pre> answer = ask prompt
answer.remember(fieldName)
<span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span></pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<p>Ask the first two prompts.</p>
</div>
<div class="content"><div class='highlight'><pre>handle ENV[<span class="hljs-string">'PROMPT_1'</span>]
handle ENV[<span class="hljs-string">'PROMPT_2'</span>]</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">¶</a>
</div>
<p>Ask the guest for their name, if configured
Don’t use handle because we want to confirm their name</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> ENV[<span class="hljs-string">'NAME_PROMPT'</span>]
name = confirmed_gets(ENV[<span class="hljs-string">'NAME_PROMPT'</span>])
name.remember(<span class="hljs-string">'name'</span>)
<span class="hljs-keyword">end</span></pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">¶</a>
</div>
<p>For each of the ten possible questions, ask them if they are configured
and save the answer</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-string">%w( QUESTION_1 QUESTION_2 QUESTION_3
QUESTION_4 QUESTION_5 QUESTION_6
QUESTION_7 QUESTION_8 QUESTION_9
QUESTION_10 )</span>.each { |p| handle(ENV[p], p) }
handle ENV[<span class="hljs-string">'SIGNATURE'</span>]</pre></div></div>
</li>
</ul>
</div>
</body>
</html>