Input Adapters

ChatterBot’s input adapters are designed to allow a chat bot to have a versatile method of receiving or retrieving input from a given source.

The goal of an input adapter is to get input from some source, and then to convert it into a format that ChatterBot can understand. This format is the Statement object found in ChatterBot’s conversation module.

Variable input type adapter

chatterbot.input.VariableInputTypeAdapter(**kwargs)[source]

The variable input type adapter allows the chat bot to accept a number of different input types using the same adapter. This adapter accepts strings, dictionaries and Statements.

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.VariableInputTypeAdapter"
)

Terminal input adapter

chatterbot.input.TerminalAdapter(**kwargs)[source]

A simple adapter that allows ChatterBot to communicate through the terminal.

The input terminal adapter allows a user to type into their terminal to communicate with the chat bot.

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.TerminalAdapter"
)

Gitter input adapter

chatterbot.input.Gitter(**kwargs)[source]

An input adapter that allows a ChatterBot instance to get input statements from a Gitter room.

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.Gitter",
    gitter_api_token="my-gitter-api-token",
    gitter_room="my-room-name",
    gitter_only_respond_to_mentions=True,
)

HipChat input adapter

chatterbot.input.HipChat(**kwargs)[source]

An input adapter that allows a ChatterBot instance to get input statements from a HipChat room.

This is an input adapter that allows a ChatterBot instance to communicate through HipChat.

Be sure to also see the documentation for the HipChat output adapter.

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.HipChat",
    hipchat_host="https://mydomain.hipchat.com",
    hipchat_room="my-room-name",
    hipchat_access_token="my-hipchat-access-token",
)

Mailgun input adapter

chatterbot.input.Mailgun(**kwargs)[source]

Get input from Mailgun.

The Mailgun adapter allows a chat bot to receive emails using the Mailgun API.

# -*- coding: utf-8 -*-
from chatterbot import ChatBot
from settings import MAILGUN

'''
To use this example, create a new file called settings.py.
In settings.py define the following:

MAILGUN = {
    "CONSUMER_KEY": "my-mailgun-api-key",
    "API_ENDPOINT": "https://api.mailgun.net/v3/my-domain.com/messages"
}
'''

# Change these to match your own email configuration
FROM_EMAIL = "mailgun@salvius.org"
RECIPIENTS = ["gunthercx@gmail.com"]

bot = ChatBot(
    "Mailgun Example Bot",
    mailgun_from_address=FROM_EMAIL,
    mailgun_api_key=MAILGUN["CONSUMER_KEY"],
    mailgun_api_endpoint=MAILGUN["API_ENDPOINT"],
    mailgun_recipients=RECIPIENTS,
    input_adapter="chatterbot.input.Mailgun",
    output_adapter="chatterbot.output.Mailgun",
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    database="../database.db"
)

# Send an example email to the address provided
response = bot.get_response("How are you?")
print("Check your inbox at ", RECIPIENTS)

Microsoft Bot Framework input adapter

chatterbot.input.Microsoft(**kwargs)[source]

An input adapter that allows a ChatterBot instance to get input statements from a Microsoft Bot using Directline client protocol. https://docs.botframework.com/en-us/restapi/directline/#navtitle

This is an input adapter that allows a ChatterBot instance to communicate through Microsoft using direct line client protocol.

Be sure to also see the documentation for the Microsoft output adapter.

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.Microsoft",
    directline_host="https://directline.botframework.com",
    directline_conversation_id="IEyJvnDULgn",
    direct_line_token_or_secret="RCurR_XV9ZA.cwA.BKA.iaJrC8xpy8qbOF5xnR2vtCX7CZj0LdjAPGfiCpg4Fv0",
)