A simple survey bot, asks questions and remembers answers
npm install survey-bot
``
#!/usr/bin/env ruby
`
This bot requires a ruby installation, 2.0 or older
`
require './lib/greenbot.rb' # ./lib/greenbot.rb contains helper libraries
def handle(prompt, fieldName= nil)
`
If there's nothing to tell or ask, get out of here.
`
return unless prompt
if fieldName.nil?
`
No field name, so just say it.
`
tell prompt if prompt
else
`
If there's a field name, then we are asking for something.
Ask and remember the answer
`
answer = ask prompt
answer.remember(fieldName)
end
end
`
Ask the first two prompts.
`
handle ENV['PROMPT_1']
handle ENV['PROMPT_2']
`
Ask the guest for their name, if configured
Don't use handle because we want to confirm their name
`
if ENV['NAME_PROMPT']
name = confirmed_gets(ENV['NAME_PROMPT'])
name.remember('name')
end
`
For each of the ten possible questions, ask them if they are configured
and save the answer
`
%w( QUESTION_1 QUESTION_2 QUESTION_3
QUESTION_4 QUESTION_5 QUESTION_6
QUESTION_7 QUESTION_8 QUESTION_9
QUESTION_10 ).each { |p| handle(ENV[p], p) }
handle ENV['SIGNATURE']
``