How to pass extra parameters to Chatterbot's Statement object and get those parameters with get_response() method or get_response.serialize()
Author: MurphyAdamCreated Jun 19, 2020Updated Oct 19, 2025
I am using Chatterbot's logical adapters to generate different responses including calls to external APIs such as weather and news. My problem is simple, I would like to pass an extra parameter to the Statement object when I am returning a response from a logical adapter. This extra parameter would be something like 'message_type' explaining the data returned as in message_type='weather_data'. To illustrate that, here is some code:
what I am doing now:
class WeatherAPIAdapter(LogicAdapter):
def __init__(self, chatbot, **kwargs):
super().__init__(chatbot, **kwargs)
# varibales
def can_process(self, statement):
"""
Return true if the input statement contains
'what' and 'is' and 'temperature'.
"""
# verification code here
return True
def process(self, input_statement, additional_response_selection_parameters):
from chatterbot.conversation import Statement
weather_data = call_to_api()
response_statement = Statement(
text=weather_data
)
response_statement.confidence = 1.0
return response_statementwhat I need:
class WeatherAPIAdapter(LogicAdapter):
def __init__(self, chatbot, **kwargs):
super().__init__(chatbot, **kwargs)
# varibales
def can_process(self, statement):
"""
Return true if the input statement contains
'what' and 'is' and 'temperature'.
"""
# verification code here
return True
def process(self, input_statement, additional_response_selection_parameters):
from chatterbot.conversation import Statement
weather_data = call_to_api()
message_type = "weather_data"
response_statement = Statement(
text=weather_data,
message_type=message_type
)
response_statement.confidence = 1.0
return response_statementand then be able to get the message_type using like the following:
message_type = bot.get_response(input_data).message_type
response = bot.get_response(input_data).textor with the serialize() method:
data = bot.get_response(input_data).serialize()Thank you very much for your help.
Source: gunthercox/ChatterBot