简体   繁体   中英

How I create a simples questionnaire with Lita.io?

I try implementing a little questionnaire in Lita as the sample:

For which system do you want to open a call?

SYSInitials

What's your problem?

I forgot my password

Thanks! Your call was opened!

Any help how I can do this?

So, I'm try this:

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

But when I register, :informar_motivo route , after passing of the :abrir_chamado route , is matched :informar_motivo route too.

利塔对话通量

but I need:

me: abrir chamado

Lita: Hello Shell User, What is your problem?

me: I forgot my password

Lita: Thanks! Your call was opened!

I found a ugly solution, but works :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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM