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_statement
what 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_statement
and then be able to get the message_type using like the following:
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:
what I need:
and then be able to get the message_type using like the following:
or with the serialize() method:
Thank you very much for your help.