Created
December 27, 2017 14:47
-
-
Save vanakenm/2e64778246a484a309e58eee3a2e4cc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommandsController < ApplicationController | |
skip_before_action :verify_authenticity_token, :only => :create | |
protect_from_forgery except: [:create] | |
def create | |
quote,random = EffinQuote.find_or_random(command_params[:text]) | |
HTTParty.post(command_params[:response_url], { body: contents(quote).to_json, headers: { | |
"Content-Type" => "application/json" | |
} | |
}) | |
render json: { response_type: "in_channel" }, status: :created | |
end | |
private | |
def contents(quote) | |
{ | |
"response_type": "in_channel", | |
"attachments": [ | |
{ | |
"title": quote.contents, | |
"title_link": quote.twitter_url, | |
"image_url": quote.url | |
} | |
] | |
} | |
end | |
# Only allow a trusted parameter "white list" through. | |
def command_params | |
params.permit(:text, :token, :user_id, :response_url, :team_domain) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment