class_docstr: Telegram input channel.
class_docstr_tok: ["Telegram","input","channel","."]
code: def blueprint(
      self, on_new_message: Callable[[UserMessage], Awaitable[Any]]
  ) -> Blueprint:
      telegram_webhook = Blueprint("telegram_webhook", __name__)
      out_channel = self.get_output_channel()
  
      @telegram_webhook.route("/", methods=["GET"])
      async def health(_: Request) -> HTTPResponse:
          return response.json({"status": "ok"})
  
      @telegram_webhook.route("/set_webhook", methods=["GET", "POST"])
      async def set_webhook(_: Request) -> HTTPResponse:
          s = await out_channel.set_webhook(self.webhook_url)
          if s:
              logger.info("Webhook Setup Successful")
              return response.text("Webhook setup successful")
          else:
              logger.warning("Webhook Setup Failed")
              return response.text("Invalid webhook")
  
      @telegram_webhook.route("/webhook", methods=["GET", "POST"])
      async def message(request: Request) -> Any:
          if request.method == "POST":
              request_dict = request.json
              if isinstance(request_dict, Text):
                  request_dict = json.loads(request_dict)
              update = Update(**request_dict)
              credentials = await out_channel.get_me()
              if not credentials.username == self.verify:
                  logger.debug(
                      "Invalid access token, check it matches Telegram"
                  )
                  return response.text("failed")
  
              if self._is_button(update):
                  msg = update.callback_query.message
                  text = update.callback_query.data
              elif self._is_edited_message(update):
                  msg = update.edited_message
                  text = update.edited_message.text
              else:
                  msg = update.message
                  if self._is_user_message(msg):
                      text = msg.text.replace("/bot", "")
                  elif self._is_location(msg):
                      text = '{{"lng":{0}, "lat":{1}}}'.format(
                          msg.location.longitude, msg.location.latitude
                      )
                  else:
                      return response.text("success")
              sender_id = msg.chat.id
              metadata = self.get_metadata(request)
              try:
                  if text == (
                      INTENT_MESSAGE_PREFIX + USER_INTENT_RESTART
                  ):
                      await on_new_message(
                          UserMessage(
                              text,
                              out_channel,
                              sender_id,
                              input_channel=self.name(),
                              metadata=metadata,
                          )
                      )
                      await on_new_message(
                          UserMessage(
                              "/start",
                              out_channel,
                              sender_id,
                              input_channel=self.name(),
                              metadata=metadata,
                          )
                      )
                  else:
                      await on_new_message(
                          UserMessage(
                              text,
                              out_channel,
                              sender_id,
                              input_channel=self.name(),
                              metadata=metadata,
                          )
                      )
              except Exception as e:
                  logger.error(
                      f"Exception when trying to handle message.{e}"
                  )
                  logger.debug(e, exc_info=True)
                  if self.debug_mode:
                      raise
                  pass
  
              return response.text("success")
  
      return telegram_webhook
  
imports: import asyncio
  import json
  import logging
  from copy import deepcopy
  from sanic import Blueprint, response
  from sanic.request import Request
  from sanic.response import HTTPResponse
  from aiogram import Bot
  from aiogram.types import InlineKeyboardButton, Update, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, Message
  from aiogram.utils.exceptions import TelegramAPIError
  from typing import Dict, Text, Any, List, Optional, Callable, Awaitable
  from rasa.core.channels.channel import InputChannel, UserMessage, OutputChannel
  from rasa.shared.constants import INTENT_MESSAGE_PREFIX
  from rasa.shared.core.constants import USER_INTENT_RESTART
  from rasa.shared.exceptions import RasaException
label_desc: Use image node_id 8 for calling the TelegramInput obj's underlying member method code with example usage: obj.blueprint(on_new_message) and returns: telegram_webhook, response, response, response, response, response, response