Hello rasa fans!
I have a customized channel that works like the callback channel. I needed to customize it so I could extract metadata from the user message.
I tried to create a custom Chanel based on Callback input with the extract_metadata method. However is not working, Can you help me:
This is my InputChannel:
class Cisco360Input(RestInput):
@classmethod
def name(cls) -> Text:
return "cisco360"
@classmethod
def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChannel:
return cls(EndpointConfig.from_dict(credentials))
def __init__(self, endpoint: EndpointConfig) -> None:
self.callback_endpoint = endpoint
def blueprint(
self, on_new_message: Callable[[UserMessage], Awaitable[Any]]
) -> Blueprint:
callback_webhook = Blueprint("callback_webhook", __name__)
@callback_webhook.route("/", methods=["GET"])
async def health(_: Request) -> HTTPResponse:
return response.json({"status": "ok"})
@callback_webhook.route("/webhook", methods=["POST"])
async def webhook(request: Request) -> HTTPResponse:
sender_id = await self._extract_sender(request)
text = self._extract_message(request)
metadata = self._extract_metadata(request) # method to get metadata
collector = self.get_output_channel()
await on_new_message(
UserMessage(text, collector, sender_id, input_channel=self.name(), metadata=metadata)
)
return response.text("success")
return callback_webhook
def get_output_channel(self) -> CollectingOutputChannel:
return Cisco360Output(self.callback_endpoint)
def _extract_metadata(self, req: Request) -> Optional[Text]:
self.custom_metadata = req.json.get("metadata", {})
return req.json.get("metadata", None)