This block will be executed if the intent provided as argument matches with the incoming message intent and if it was previously created and trained in the NLP engine.
intent(name=String|Array, &block)
Configuration
The NLP engine must be enabled and configured in bot/config/nlp.rb file in order to implement this block.
Platforms
Platform
Supported
Messenger
WhatsApp
Telegram
Usage
In the following example, MainContext will handle 3 different intentions:
greeting: Greeting messages like "Hi", "Hello" and so on.
goodbye: Goodbye messages like "Bye", "GodBye", "Goodnight" and so on.
thanks: Thank you messages like "Thanks", "Thank you", "I appreciate it" and so on.
class MainContext < Conversation
def blocks
intent :set_alarm do |text, entities, traits, confidence|
unless entities["wit$datetime:datetime"].nil?
entity = entities["wit$datetime:datetime"].first
@reply.text "I'll wake you up at #{entity[:value]}"
else
@reply.text "To help you with that, I need you to tell me a time for the alarm."
end
@reply.typing 1.second
unless traits["wit$sentiment"].nil?
trait = traits["wit$sentiment"].first
case trait[:value]
when "positive"
@reply.text "And thank you for asking so kindly."
when "negative"
@reply.text "But you could try to be nicer next time.."
when "neutral"
# Nothing here
end
end
end
end
class MainContext < Conversation
def blocks
any_intent do |intent|
if intent == "gretting"
@reply.text "Hello!"
elsif intent == "godbye"
@reply.text "Bye bye!"
elsif intent == "thanks"
@reply.text "You're welcome"
end
end
end
end