etrex / kamigo

a chatbot framework based on rails
https://etrex.tw/kamigo/
MIT License
78 stars 11 forks source link

`kamigo.rb` 設定檔無法運作 #49

Closed chaowudev closed 2 years ago

chaowudev commented 2 years ago

問題

設定 .env 檔的環境變數後,嘗試將 kamigo.rb 設定檔的 comment 打開,在開啟 rails server 時出現錯誤。

kamigo.rb 設定檔的設定

Kamigo.setup do |config|
  # When user input doesn't match the route, Kamigo will pass the reuqest to default_path with default_http_method.
  # config.default_path = "/"
  # config.default_http_method = "GET"

  # When Kamigo don't know what message to reply, then Kamigo reply the line_default_message.
  # config.line_default_message = {
  #   type: "text",
  #   text: "Sorry, I don't understand your message."
  # }

  # When line_default_message is nil, then Kamigo don't reply message.
  # config.line_default_message = nil

  # Integrate with line login
  # config.line_login_channel_id = ENV["LINE_LOGIN_CHANNEL_ID"]
  config.line_login_channel_secret = ENV["LINE_LOGIN_CHANNEL_SECRET"]
  config.line_login_redirect_uri = ENV["LINE_LOGIN_REDIRECT_URI"]

  # Integrate with liff
  config.liff_url_compact = ENV["LIFF_COMPACT"]
  config.liff_url_tall = ENV["LIFF_TALL"]
  config.liff_url_full = ENV["LIFF_FULL"]

  # Integrate with line messaging api
  # config.line_message_api_channel_id = ENV["LINE_CHANNEL_ID"]
  config.line_message_api_channel_secret = ENV["LINE_CHANNEL_SECRET"]
  config.line_message_api_channel_token = ENV["LINE_CHANNEL_TOKEN"]
end

開啟 Rails server 的 Log

=> Booting Puma
=> Rails 7.0.3 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/Users/wuchaochao/Documents/kamigo_demo/config/initializers/kamigo.rb:27:in `block in <main>': undefined method `line_message_api_channel_secret=' for Kamigo:Module (NoMethodError)

  config.line_message_api_channel_secret = ENV["LINE_CHANNEL_SECRET"]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Did you mean?  line_message_api_channel_secret
               line_message_api_channel_id
               line_message_api_channel_token
               line_messaging_api_channel_secret=
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/kamigo-0.26.0/lib/kamigo.rb:56:in `setup'
    from /Users/wuchaochao/Documents/kamigo_demo/config/initializers/kamigo.rb:1:in `<main>'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/engine.rb:667:in `block in load_config_initializer'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.3/lib/active_support/notifications.rb:208:in `instrument'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/engine.rb:666:in `load_config_initializer'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/engine.rb:619:in `each'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/engine.rb:619:in `block in <class:Engine>'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:32:in `run'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:50:in `each'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:50:in `tsort_each_child'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:415:in `call'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:415:in `each_strongly_connected_component_from'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `each'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `call'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/application.rb:372:in `initialize!'
    from /Users/wuchaochao/Documents/kamigo_demo/config/environment.rb:5:in `<main>'
    from config.ru:3:in `require_relative'
    from config.ru:3:in `block in <main>'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:116:in `eval'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:116:in `new_from_string'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:105:in `load_file'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/builder.rb:66:in `parse_file'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:349:in `build_app_and_options_from_config'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:249:in `app'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rack-2.2.3.1/lib/rack/server.rb:422:in `wrapped_app'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:36:in `start'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:143:in `block in perform'
    from <internal:kernel>:90:in `tap'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands/server/server_command.rb:134:in `perform'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/command/base.rb:87:in `perform'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/command.rb:48:in `invoke'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.3/lib/rails/commands.rb:18:in `<main>'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /Users/wuchaochao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from bin/rails:4:in `<main>'
etrex commented 2 years ago

以下這段功能未完成,可直接刪除:

  config.line_login_channel_secret = ENV["LINE_LOGIN_CHANNEL_SECRET"]
  config.line_login_redirect_uri = ENV["LINE_LOGIN_REDIRECT_URI"]

  # Integrate with liff
  config.liff_url_compact = ENV["LIFF_COMPACT"]
  config.liff_url_tall = ENV["LIFF_TALL"]
  config.liff_url_full = ENV["LIFF_FULL"]

  # Integrate with line messaging api
  # config.line_message_api_channel_id = ENV["LINE_CHANNEL_ID"]
  config.line_message_api_channel_secret = ENV["LINE_CHANNEL_SECRET"]
  config.line_message_api_channel_token = ENV["LINE_CHANNEL_TOKEN"]

目前尚未支援以 kamigo.rb 設定串接參數

template 已修正,新版 kamigo 不會生成這段文字