class Ruboty::Zatsudan::Actions::Zatsudan
Public Instance Methods
call()
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 8 def call message.reply(zatsudan(message.body)) rescue => e message.reply(e.message) end
Private Instance Methods
connection()
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 43 def connection @connection ||= Faraday.new(url: zatsudan_api_url) do |faraday| faraday.adapter Faraday.default_adapter end end
context()
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 61 def context message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:context] end
context=(context)
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 57 def context=(context) message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:context] = context end
mode()
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 53 def mode message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:mode] end
mode=(mode)
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 49 def mode=(mode) message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:mode] = mode end
zatsudan(utt)
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 24 def zatsudan(utt) res = connection.post do |req| req.url "/dialogue/v1/dialogue?APIKEY=#{zatsudan_api_key}" req.headers['Content-Type'] = 'application/json' if context && mode req.body = JSON.generate(utt: utt, nickname: message.from_name, mode: mode, context: context) else req.body = JSON.generate(utt: utt, nickname: message.from_name) end end zatsudan_reply = JSON.parse(res.body) self.context = zatsudan_reply['context'] self.mode = zatsudan_reply['mode'] zatsudan_reply['utt'] end
zatsudan_api_key()
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 20 def zatsudan_api_key ENV['DOCOMO_APIKEY'] end
zatsudan_api_url()
click to toggle source
# File lib/ruboty/zatsudan/actions/zatsudan.rb, line 16 def zatsudan_api_url 'https://api.apigw.smt.docomo.ne.jp' end