Possibility to pass a specific yaml_reply file name to send_replies
luizcarvalho opened this issue · comments
Is your feature request related to a problem? Please describe.
would be extremely useful if we can pass to send_replies
method a specific yaml_reply
name in cases with expensive task or reuse a specific yaml_reply
, etc
Describe the solution you'd like
def say_meus_atendimentos
send_replies('wait_reply')
@data = Google.search('stealth chatbots')
send_replies
end
Or
def say_meus_atendimentos
@data = Google.search('stealth chatbots')
if @data
send_replies
else
send_replies('no_results')
end
end
and many others cases
In https://github.com/hellostealth/stealth/blob/master/lib/stealth/controller/replies.rb, something like this, maybe works.
(...)
def send_replies(yml_reply_file_name = nil)
yaml_reply, preprocessor = action_replies(yml_reply_file_name)
(...)
def action_replies(yml_reply_file_name=nil)
reply_dir = [*self._replies_path, replies_folder]
reply_filename = "#{yml_reply_file_name || current_session.state_string}.yml"
(...)
Hi @luizcarvalho, you should be able to do all of this via the replies themselves.
Just make sure you add the .erb
extension to your reply file. So reply.yml
should be named reply.yml.erb
. It can then contain Ruby code:
<% if current_message.message == "Sometimes" %>
- reply_type: delay
duration: <%= SHORT_DELAY %>
- reply_type: text
text: "Sometimes"
<% else %>
- reply_type: delay
duration: <%= SHORT_DELAY %>
- reply_type: text
text: "Always"
<% end %>