Chatbots for Developers
Chatbots connect to the Klat server and respond to user shouts. Bots will respond individually like any other user in the conversation.
Generating Responses
Basic Bot
Basic bots override self.ask_chatbot
to generate a response. Bots have access to the shout, the user who originated the shout, and the timestamp of the shout. Any means may be used to generate and return a response via the self.propose_response
method.
Script Bot
Bots extending the NeonBot
class operate by passing user shouts to a Neon Script and returning those responses. NeonBot
init takes the name of the script to run ("SCRIPT_NAME"
in the example below), as well as the messagebus configuration for the NeonCore
instance on which to run the script.
Testing
Basic Bot
The response generation of a bot should be tested individually before connecting it to the Klat network. # TODO: Outline the convenience methods available to do this!!
Script Bot
A script should be tested separately from the bot before creating a NeonBot
. More information about developing scripts can be found on the Neon Scripts Repository. After the script functions as expected, it can be used to extend a NeonBot
.
Python Examples
Basic Bot
from chat_bot import ChatBot class MyBot(ChatBot): def __init__(self, socket, domain, user, password): super(MyBot, self).__init__(socket, domain, user, password) self.last_search = None def ask_chatbot(self, user, shout, timestamp): """ Handles an incoming shout into the current conversation :param user: user associated with shout :param shout: text shouted by user :param timestamp: formatted timestamp of shout """ response = "" # Generate some response here self.propose_response(shout, response) self.pause_responses() def on_login(self): """ Do any initialization after logging in """ pass
Script Bot
from neon_connector.neonbot import NeonBot class ScriptBot(NeonBot): def __init__(self, socket, domain, user, password): super(ScriptBot, self).__init__(socket, domain, user, password, "SCRIPT NAME", {"host": "CORE_ADDR", "port": 8181, "ssl": False, "route": "/core"})