gpt4 book ai didi

ruby - 如何在 Stealth bot 框架中设置 before_action to route 方法?

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:03 26 4
gpt4 key购买 nike

我正在尝试使用 before_action's在我的 Stealth 中回调机器人,但不起作用。我不知道这是否是正确的方法。

这是我的代码:

class BotController < Stealth::Controller

helper :all
before_action :print_this, only: :route


def route
if current_session.present?
step_to session: current_session
else
step_to flow: 'hello', state: 'say_hello'
end
end

def print_this
puts "\n\n\n\n\n aaaaaaaaaaaaaaaaaaa \n\n\n\n"
end

end

没有任何反应,没有错误,没有打印消息。

有什么问题吗?

编辑:

before_action在另一个 Controller 中工作,但不在 BotController

编辑 2:这是一个具有行为的日志:

1) 使用 before_action :print_this, only: :route

sidekiq_1   | 2018-09-12T17:13:10.544Z 1 TID-gt9nk8dzx Stealth::Services::HandleMessageJob JID-1b773e7908fcb72b7aa10a3d INFO: start
sidekiq_1 | [previous_session] User 160479129292600: setting to
sidekiq_1 | [session] User 160479129292600: setting session to hello->say_hello
sidekiq_1 | [previous_session] User 160479129292600: setting to hello->say_hello
sidekiq_1 | [session] User 160479129292600: setting session to main->show_menu
sidekiq_1 | 2018-09-12T17:13:11.738Z 1 TID-gt9nk8dzx Stealth::Services::HandleMessageJob JID-1b773e7908fcb72b7aa10a3d INFO: done: 1.194 sec

2) 使用 before_action :print_this, only: :say_hello ( say_helloHellosController < BotController HERE WORKS 的一个 Action

sidekiq_1   | 2018-09-12T17:18:24.751Z 1 TID-gte80drk9 Stealth::Services::HandleMessageJob JID-62e6901208770b68439ac083 INFO: start
sidekiq_1 | [previous_session] User 1604791292926176: setting to atendimento->say_meus_atendimentos
sidekiq_1 | [session] User 1604791292926176: setting session to hello->say_hello
sidekiq_1 |
sidekiq_1 |
sidekiq_1 |
sidekiq_1 |
sidekiq_1 |
sidekiq_1 | aaaaaaaaaaaaaaaaaaa
sidekiq_1 |
sidekiq_1 |
sidekiq_1 |
sidekiq_1 | [previous_session] User 1604791292926176: setting to hello->say_hello
sidekiq_1 | [session] User 1604791292926176: setting session to main->show_menu
sidekiq_1 | 2018-09-12T17:18:25.524Z 1 TID-gte80drk9 Stealth::Services::HandleMessageJob JID-62e6901208770b68439ac083 INFO: done: 0.772 sec

这是,在 BotController 中不起作用吗?仅。

最佳答案

好的,我知道这不起作用的原因,route不是 Action ,只是 Stealth::Controller 的一个特殊方法,所以回调不会被 before_action 或其他回调调用。

关于ruby - 如何在 Stealth bot 框架中设置 before_action to route 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52295623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com