Class: Lita::Handlers::AlexaNewsRecorder
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::AlexaNewsRecorder
- Defined in:
- lib/lita/handlers/alexa_news_recorder.rb
Instance Method Summary collapse
- #alexa_response(message) ⇒ Object
- #check_for_publisher! ⇒ Object
- #extract_message(payload) ⇒ Object
- #record_message(request, response) ⇒ Object
Instance Method Details
#alexa_response(message) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lita/handlers/alexa_news_recorder.rb', line 39 def alexa_response() { "version": "1.0", "sessionAttributes": { }, "response": { "outputSpeech": { "type": "PlainText", "text": "Added your message to Lita's flash briefing: #{}" }, "card": { "type": "Simple", "title": "Recorded flash message", "content": "Added your message to Lita's flash briefing: #{}" }, "shouldEndSession": true } } end |
#check_for_publisher! ⇒ Object
25 26 27 28 |
# File 'lib/lita/handlers/alexa_news_recorder.rb', line 25 def check_for_publisher! return if robot.handlers.include?(Lita::Handlers::AlexaNewsPublisher) raise ConfigurationError, "Must install AlexaNewsPublisher handler to make me work!" end |
#extract_message(payload) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/lita/handlers/alexa_news_recorder.rb', line 30 def (payload) parsed = JSON.parse(payload) value = parsed.dig('request', 'intent', 'slots', 'Message', 'value') raise ArgumentError if value.nil? value end |
#record_message(request, response) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lita/handlers/alexa_news_recorder.rb', line 9 def (request, response) check_for_publisher! Lita.logger.debug "Inbound request params: " Lita.logger.debug request.params Lita.logger.debug "Inbound request body: " Lita.logger.debug request.body.string # it's a StringIO = (request.body.string) robot.trigger(:save_alexa_message, username: 'Alexa News Recorder', message: ) response.write JSON.dump(alexa_response) end |