class_docstr: A custom http input channel.
  
  This implementation is the basis for a custom implementation of a chat
  frontend. You can customize this to send messages to Rasa and
  retrieve responses from the assistant.
class_docstr_tok: ["A","custom","http","input","channel",".","This","implementation","is","the","basis","for","a","custom","implementation","of","a","chat","frontend",".","You","can","customize","this","to","send","messages","to","Rasa","and","retrieve","responses","from","the","assistant","."]
docstr: Groups the collection of endpoints used by rest channel.
docstr_tok: ["Groups","the","collection","of","endpoints","used","by","rest","channel","."]
code: def blueprint(
      self, on_new_message: Callable[[UserMessage], Awaitable[None]]
  ) -> Blueprint:
      """Groups the collection of endpoints used by rest channel."""
      module_type = inspect.getmodule(self)
      if module_type is not None:
          module_name = module_type.__name__
      else:
          module_name = None
  
      custom_webhook = Blueprint(
          "custom_webhook_{}".format(type(self).__name__),
          module_name,
      )
  
      # noinspection PyUnusedLocal
      @custom_webhook.route("/", methods=["GET"])
      async def health(request: Request) -> HTTPResponse:
          return response.json({"status": "ok"})
  
      @custom_webhook.route("/webhook", methods=["POST"])
      async def receive(
          request: Request,
      ) -> Union[ResponseStream, HTTPResponse]:
          sender_id = await self._extract_sender(request)
          text = self._extract_message(request)
          should_use_stream = rasa.utils.endpoints.bool_arg(
              request, "stream", default=False
          )
          input_channel = self._extract_input_channel(request)
          metadata = self.get_metadata(request)
  
          if should_use_stream:
              return response.stream(
                  self.stream_response(
                      on_new_message,
                      text,
                      sender_id,
                      input_channel,
                      metadata,
                  ),
                  content_type="text/event-stream",
              )
          else:
              collector = CollectingOutputChannel()
              # noinspection PyBroadException
              try:
                  await on_new_message(
                      UserMessage(
                          text,
                          collector,
                          sender_id,
                          input_channel=input_channel,
                          metadata=metadata,
                          headers=request.headers,
                      )
                  )
              except CancelledError:
                  structlogger.error(
                      "rest.message.received.timeout",
                      text=copy.deepcopy(text),
                  )
              except Exception:
                  structlogger.exception(
                      "rest.message.received.failure",
                      text=copy.deepcopy(text),
                  )
  
              return response.json(collector.messages)
  
      return custom_webhook
  
imports: import asyncio
  import copy
  import inspect
  import json
  import logging
  import structlog
  from asyncio import Queue, CancelledError
  from sanic import Blueprint, response
  from sanic.request import Request
  from sanic.response import HTTPResponse, ResponseStream
  from typing import Text, Dict, Any, Optional, Callable, Awaitable, NoReturn, Union
  import rasa.utils.endpoints
  from rasa.core.channels.channel import InputChannel, CollectingOutputChannel, UserMessage
label_desc: Use image node_id 6 for calling the RestInput obj's underlying member method code with example usage: obj.blueprint(on_new_message) and returns: custom_webhook, response, response, response