我尝试在丽塔实施一个小问卷作为样本:
您想打开哪个系统?
SYSInitials
你的问题是什么?
我忘记了密码
谢谢!你的电话已经开通了!
我可以帮忙怎么做?
所以,我试试这个:
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
但是当我注册时,:informar_motivo route
在通过:abrir_chamado route
后,也会匹配:informar_motivo
路线。
但我需要:
me: abrir chamado
Lita: Hello Shell用户,您有什么问题?
我:我忘记了密码
丽塔:谢谢!你的电话已经开通了!
答案 0 :(得分:0)
我找到了一个丑陋的解决方案,但有效: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