"Post 404 not found" with Rails and Api.ai

I'm making a webhook with Ruby on Rails to conect Dialogflow (api.ai) and Telegram with my application. I'm also using Ngrok on the webhook.

Everytime I write to the Telegram bot (token setted in Dialogflow fullfilment) the text is sent to Dialogflow to create a JSON request with the parameters I want. This is working.

The problem start when I want to receive this JSON on my app. I'm receiving this error: Ngrok configuration

Here is my routes.rb:

   # Telegram
   post "/#{Chamber.env.dialogflow.route}" => 'chatbot_users#webhook'

Here is my dialogflow.yml:

  dialogflow:
    url: 'https://XXXXXac.ngrok.io'
    route: 'webhook'

Here is my chatbot_users_controller

class ChatbotUsersController < ApplicationController
  skip_before_filter :verify_authenticity_token

  def webhook
    p "-----------------------NOT REACHING THIS POINT--------------------"
    if request.headers['Content-Type'] == 'application/json'
      data = JSON.parse(request.body)
    else
      data = params.as_json
    end  
  end
end

If more code is needed, just ask. Thanks in advice.

Upvotes: 2

Views: 467

Answers (1)

John Baker
John Baker

Reputation: 2398

First, you can run rake routes, to see if the generated path has that actual naming.

I would suggest using :as in routes.rb when you declare the path. The as option lets you override the normal naming for the actually generated paths.

post "/#{Chamber.env.dialogflow.route}" => 'chatbot_users#webhook', :as => 'webhook'

Upvotes: 2

Related Questions