rasagpt / app /rasa /custom_telegram.py
paulpierre's picture
added function descriptions, cleaned up formatting
c095e79
raw
history blame contribute delete
739 Bytes
from rasa.core.channels.telegram import TelegramInput
from rasa.shared.utils import common as rasa_common
from typing import Any, Dict, Optional, Text
from sanic.request import Request
'''
The purpose of this script is to extend TelegramInput to allow for custom metadata to be passed to Rasa.
'''
class CustomTelegramInput(TelegramInput):
def get_metadata(self, request: Request) -> Optional[Dict[Text, Any]]:
# For whatever reason, Rasa is unable to pass data via 'metadata' so 'meta' works for now
metadata = request.json.get('message', {}).get('meta')
# Debug
rasa_common.logger.debug(f'[πŸ€– ActionGPTFallback]\nmetadata: {metadata}')
return metadata if metadata is not None else None