Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何使用Lita.io创建simples问卷?_Ruby_Chatbot_Lita - Fatal编程技术网

Ruby 如何使用Lita.io创建simples问卷?

Ruby 如何使用Lita.io创建simples问卷?,ruby,chatbot,lita,Ruby,Chatbot,Lita,我尝试在Lita中实施一个小问卷作为样本: 您想为哪个系统打电话? 系统首字母 你有什么问题? 我忘记密码了 谢谢!你的电话被打开了 有人帮我怎么做吗 所以,我想试试这个: module Lita module Handlers class Helpdesk < Handler on :shut_down_complete, :clear_context route(/^abrir chamado$/i, :abrir_chamado) r

我尝试在Lita中实施一个小问卷作为样本:

您想为哪个系统打电话?

系统首字母

你有什么问题?

我忘记密码了

谢谢!你的电话被打开了

有人帮我怎么做吗

所以,我想试试这个:

module Lita
  module Handlers
    class Helpdesk < Handler
      on :shut_down_complete, :clear_context

      route(/^abrir chamado$/i, :abrir_chamado)
      route(/^.*$/i, :motivo)
      http.get '/info', :web

      def motivo(response)
        return unless context == 'abrir_chamado'
        response.reply('Thanks! Your call was opened!')
        clear_context
      end

      def abrir_chamado(response)
        redis.set(:context, :abrir_chamado)
        user = response.user
        response.reply(
          %(Hello #{user.name}, What is your problem?)
        )
      end

      def context
        @contetx ||= redis.get(:context)
      end

      def clear_context
        redis.del(:context)
      end

      Lita.register_handler(Helpdesk)
    end
  end
end
模块Lita
模块处理程序
类帮助台
但当我注册时,
:informar\u motivo路由
,在通过
:abrir\u chamado路由
后,也匹配了
:informar\u motivo
路由

但我需要:

me:abrir chamado

Lita:你好,Shell用户,您有什么问题

我:我忘记密码了

丽塔:
谢谢!你的电话被打开了


我找到了一个丑陋的解决方案,但效果很好:p

module Lita
  module Handlers
    class Helpdesk < Handler
      on :shut_down_complete, :clear_context
      on :unhandled_message, :motivo

      route(/^abrir chamado$/i, :abrir_chamado)

      http.get '/info', :web

      def motivo(payload)
        response = payload[:message]
        return unless context == 'abrir_chamado'
        response.reply('Thanks! Your call was opened!')
        clear_context
      end

      def abrir_chamado(response)
        redis.set(:context, :abrir_chamado)
        user = response.user
        response.reply(
          %(Hello #{user.name}, What is your problem?)
        )
      end

      def context
        @contetx ||= redis.get(:context)
      end

      def clear_context
        redis.del(:context)
      end

      Lita.register_handler(Helpdesk)
    end
  end
end
模块Lita
模块处理程序
类帮助台