Skip to content

Instantly share code, notes, and snippets.

@vanakenm
Created December 27, 2017 14:47
Show Gist options
  • Save vanakenm/2e64778246a484a309e58eee3a2e4cc3 to your computer and use it in GitHub Desktop.
Save vanakenm/2e64778246a484a309e58eee3a2e4cc3 to your computer and use it in GitHub Desktop.
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