Error running rasa "TypeError: Object of type Message is not JSON serializable"

hi. i keep getting this error every time i try to run my rasa chatbot. this was a working code and i got the errors when i tried sudo apt-get update/ upgrade.

error:

Encountered an exception while running action ‘action_intro’.Bot will continue, but the actions events are lost. Please check the logs of your action server for more information. Traceback (most recent call last): File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/processor.py”, line 772, in _run_action events = await action.run( File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/actions/action.py”, line 685, in run response = await self.action_endpoint.request( File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/utils/endpoints.py”, line 146, in request async with session.request( File “/home/ndn/rvenv/lib/python3.8/site-packages/aiohttp/client.py”, line 1117, in aenter self._resp = await self._coro File “/home/ndn/rvenv/lib/python3.8/site-packages/aiohttp/client.py”, line 390, in _request data = payload.JsonPayload(json, dumps=self._json_serialize) File “/home/ndn/rvenv/lib/python3.8/site-packages/aiohttp/payload.py”, line 381, in init dumps(value).encode(encoding), File “/usr/lib/python3.8/json/init.py”, line 231, in dumps return _default_encoder.encode(obj) File “/usr/lib/python3.8/json/encoder.py”, line 199, in encode chunks = self.iterencode(o, _one_shot=True) File “/usr/lib/python3.8/json/encoder.py”, line 257, in iterencode return _iterencode(o, 0) File “/usr/lib/python3.8/json/encoder.py”, line 179, in default raise TypeError(f’Object of type {o.class.name} ’ TypeError: Object of type Message is not JSON serializable 2021-07-18 15:17:52 ERROR rasa.core.tracker_store - Error happened when trying to save conversation tracker to ‘InMemoryTrackerStore’. Falling back to use the ‘InMemoryTrackerStore’. Please investigate the following error: Object of type Message is not JSON serializable. 2021-07-18 15:17:52 ERROR addons.custom_telegram - Exception when trying to handle message.Object of type Message is not JSON serializable Exception occurred while handling uri: ‘http://xxx.ngrok.io/webhooks/custom/webhook’ Traceback (most recent call last): File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/tracker_store.py”, line 1232, in save self._tracker_store.save(tracker) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/tracker_store.py”, line 314, in save serialised = InMemoryTrackerStore.serialise_tracker(tracker) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/tracker_store.py”, line 262, in serialise_tracker return json.dumps(dialogue.as_dict()) File “/usr/lib/python3.8/json/init.py”, line 231, in dumps return _default_encoder.encode(obj) File “/usr/lib/python3.8/json/encoder.py”, line 199, in encode chunks = self.iterencode(o, _one_shot=True) File “/usr/lib/python3.8/json/encoder.py”, line 257, in iterencode return _iterencode(o, 0) File “/usr/lib/python3.8/json/encoder.py”, line 179, in default raise TypeError(f’Object of type {o.class.name} ’ TypeError: Object of type Message is not JSON serializable

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/home/ndn/rvenv/lib/python3.8/site-packages/sanic/app.py”, line 931, in handle_request response = await response File “/home/ndn/Desktop/TESTBOT/addons/custom_telegram.py”, line 332, in message await on_new_message( File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/channels/channel.py”, line 89, in handler await app.agent.handle_message(message) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/agent.py”, line 577, in handle_message return await processor.handle_message(message) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/processor.py”, line 111, in handle_message self._save_tracker(tracker) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/processor.py”, line 901, in _save_tracker self.tracker_store.save(tracker) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/tracker_store.py”, line 1235, in save self.fallback_tracker_store.save(tracker) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/tracker_store.py”, line 314, in save serialised = InMemoryTrackerStore.serialise_tracker(tracker) File “/home/ndn/rvenv/lib/python3.8/site-packages/rasa/core/tracker_store.py”, line 262, in serialise_tracker return json.dumps(dialogue.as_dict()) File “/usr/lib/python3.8/json/init.py”, line 231, in dumps return _default_encoder.encode(obj) File “/usr/lib/python3.8/json/encoder.py”, line 199, in encode chunks = self.iterencode(o, _one_shot=True) File “/usr/lib/python3.8/json/encoder.py”, line 257, in iterencode return _iterencode(o, 0) File “/usr/lib/python3.8/json/encoder.py”, line 179, in default raise TypeError(f’Object of type {o.class.name} ’ TypeError: Object of type Message is not JSON serializable

it states that the error starts with this action/function found in my action.py file. i tried making a new virtualenv and reinstalled rasa along with other dependencies like scrapy and telegram-pagination, etc. and it still gave me the same error. could there be something wrong with my environment/dependencies? please help. ):

action.py:

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet, SessionStarted, ActionExecuted, EventType


class ActionIntro(Action):

    def name(self):
        return "action_intro"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]):

        name = tracker.get_slot("name")
        # checks if bot already asked for user's name
        if name is None:
            dispatcher.utter_message(template="utter_im_upbot")
            dispatcher.utter_message(template="utter_ask_name")
        else:
            dispatcher.utter_message(template="utter_greet")
            dispatcher.utter_message(template="utter_main_category")

        return []

@ccloud check syntax

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet, SessionStarted, ActionExecuted, EventType


class ActionIntro(Action):

def name(self) ->Text:
    return "action_intro"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) ->List[Dict[:Text , Any]]:
        name = tracker.get_slot("name")
    # checks if bot already asked for user's name
    if name is None:
        dispatcher.utter_message(template="utter_im_upbot")
        dispatcher.utter_message(template="utter_ask_name")
    else:
        dispatcher.utter_message(template="utter_greet")
        dispatcher.utter_message(template="utter_main_category")

    return []

I can see you also using ngrok or some APIs? If not this code will solve your issue. If not then share complete code. Do compare your code with my suggested code. Good Luck!

hi! thank you so much for replying. i didnt know the rasa updates had these changes. altho, i changed the syntax and it still didnt work.

im actually using a custom channel. i tried running my code with the default telegram channel of rasa and it worked! so i figured the problem was with my custom channel. i made a new topic here in the forum in case, since it seems a different topic. here is the link: Custom channel not working

thank u so much!