-
Notifications
You must be signed in to change notification settings - Fork 3
Bot
Bots are cool - they listen for input in the form of messages from conversations, and then output text back to the user. They extend from a participant, so everything you can do with that can be done with a bot.
Let's make a bot that agrees with the user. I'll be using this wit app, although you can always set one up for yourself.
-
Let's create the class. It should extend from
WitBot::Bot::Base
:class Bot < WitBot::Bot::Base end
-
Now, let's have the bot listen to intents. Let's use the
:Test
intent I setupclass Bot < WitBot::Bot::Base intents :Test end
-
To accept this intent, we just create a method, interpreting the message and sending a response with
#send_message
:protected def on_Test(message) outcome = message.outcome thing = outcome.entities["thing"] adjective = outcome.entities["adjective"] msg = "Yup, that #{thing || 'thing'} is #{adjective || 'a word'}." send_message msg end
-
To create an instance of the bot, you pass a [conversation].
conversation = WitBot::Bot::Conversation::Base.new # Create a conversation bot = Bot.new conversation # Create the bot
-
Now, send the conversation a message, and the bot will reply.
conversation.send_message "This is a cool test."
On Rails? Use the bot generator:
$ rails g wit_bot:bot BotName [intents]
You can check out the example for more info.
Down here?
Cool.
I should add something somewhat interesting for you to read...
Here's how to get started with wit_bot in 3 steps:
- Learn how to use wit.ai
- Learn how to setup the gem
- Learn how to send a message
- Learn how to use message threads
- Learn how to use context
- Learn how to use conversations
- Learn to use the REPL
- Learn how to use conversations
- Learn how to use participants
- Learn how to use bots