2016-07-27 7 views
0

私はRuby Gem for wit.aiを使用していて、wit.aiクライアントに照会するRORにAPIを作成しました。wit.ai Ruby Gem、繰り返し呼び出しは終了しません

しかし、予期しないことに、APIのメソッドは、応答を受け取った後でも、クライアントメソッドを繰り返し呼び出します。

APIメソッドは決してJSONレスポンスをレンダリングしません。

この問題を解決するにはどうすればよいですか?なぜこうなった?

これは、Rails Consoleと同じことをしても問題ありません。

ApiController

module Api 

    module V0 

    class ApiController < ApplicationController 

     def response 
      q = params[:q] 
      response = Api::V0::ApiModel.handle_response q 
      render :json => response, :status => 200 
     end 
    end 
    end 
end 

ApiModel

module Api 

    module V0 

     class ApiModel 

     def self.handle_response q 
      response = ChatbotHelper.query q 
      if response['type'] == "msg" 
       message = response["msg"] 
       json = {"message" => message} 
      else 
       json = response 
      end 
      json 
     end 
     end 
    end 
end 

ChatbotHelper

module ChatbotHelper 

    def self.init 

    actions = { 
     send: -> (request, response) { 

      puts "REQUEST #{request} RESPONSE #{response}" 
      puts("#{response['text']}") 
      response 
     }, 
     getData: -> (context){ 

     }, 
    } 

    @client = Wit.new(access_token: "XYZ", actions: actions) 

end 

def self.query q 
    begin 
     self.init 
     response = self.get_response q 
    rescue SocketError 
     response = {"message": "SocketError"} 
    end 
    response 
end 

def self.get_response q 
    puts "GET RESPONSE" 
    response = @client.converse("b", q, {}) 
    response 
end 
end 
+0

デバッガを使用してコードを実行してループが起きている場所を見つけます。 –

+0

何度も何度も起こっているwit.aiクライアントへの呼び出し。コードに関連するバグはありません。 ポーリングと同様のものです。 wit.aiに関連するもののように見えます。 回避策が見つかりません –

+0

別のAPI呼び出しを作成してこれをデバッグすると、 'render:json =>レスポンス、:status => 200'自体で問題が認識されました.. 何が起こっているのでしょうか? –

答えて

0

ああ!それは、APIコントローラの関数の名前、すなわちresponseのために起こっていました。RORのためのinbuilt関数のようです。

関連する問題