I am connecting to the slack API successfully using the subscription events which sends a response which looks like this:
Parameters: {"token"=>"[FILTERED]", "team_id"=>"xxx", "api_app_id"=>"yyy", "event"=>{"bot_id"=>"zzz",............
I can parse that info using this:
json_params = JSON.parse(request.raw_post)
user = json_params['event']['bot_id']
Now to the problem. I am then adding action buttons, which makes a HTML post response to my URL but the call is in a different format than the subscription event post and JSON.parse is not working.
The format looks like this:
Parameters: {"payload"=>"{"type":"block_actions","user":{"id":"xxx","username":"yyy","name":"my name"
If I do the same: json_params = JSON.parse(request.raw_post)
It throws this error:
JSON::ParserError (783: unexpected token at 'payload=%7B%22type%22%3A%22block_............
Also tried
json_params = JSON.parse(request)
That returns //TypeError (no implicit conversion of ActionDispatch::Request into String):
And I tried
puts request and puts request.raw and JSON.parse(request.body) and puts request.body too and they didn't work, I am new to rails so struggling on this for ages, any ideas?
question from:
https://stackoverflow.com/questions/65893598/how-to-parse-access-json-from-slack-action-using-ruby-on-rails 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…