Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.
Ben edited this page Apr 3, 2016 · 6 revisions

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.

  1. Let's create the class. It should extend from WitBot::Bot::Base:

    class Bot < WitBot::Bot::Base
    end
  2. Now, let's have the bot listen to intents. Let's use the :Test intent I setup

    class Bot < WitBot::Bot::Base
      intents :Test
    end
  3. 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
  4. 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
  5. 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.

Getting Started

Here's how to get started with wit_bot in 3 steps:

  1. Learn how to use wit.ai
  2. Learn how to setup the gem
  3. Learn how to send a message

Dive Deeper

Create Bots

Integrate it

Clone this wiki locally