class_docstr: Input channel for Twilio Voice.
class_docstr_tok: ["Input","channel","for","Twilio","Voice","."]
docstr: Defines endpoints for Twilio voice channel.
docstr_tok: ["Defines","endpoints","for","Twilio","voice","channel","."]
code: def blueprint(
      self, on_new_message: Callable[[UserMessage], Awaitable[None]]
  ) -> Blueprint:
      """Defines endpoints for Twilio voice channel."""
      twilio_voice_webhook = Blueprint("Twilio_voice_webhook", __name__)
  
      @twilio_voice_webhook.route("/", methods=["GET"])
      async def health(request: Request) -> HTTPResponse:
          return response.json({"status": "ok"})
  
      @twilio_voice_webhook.route("/webhook", methods=["POST"])
      async def receive(request: Request) -> HTTPResponse:
          sender_id = request.form.get("From")
          text = request.form.get("SpeechResult")
          input_channel = self.name()
          call_status = request.form.get("CallStatus")
  
          collector = TwilioVoiceCollectingOutputChannel()
  
          # Provide an initial greeting to answer the user's call.
          if (text is None) and (call_status == "ringing"):
              text = self.initial_prompt
  
          # determine the response.
          if text is not None:
              await on_new_message(
                  UserMessage(
                      text,
                      collector,
                      sender_id,
                      input_channel=input_channel,
                  )
              )
  
              twilio_response = self._build_twilio_voice_response(
                  collector.messages
              )
          # If the user doesn't respond resend the last message.
          else:
              # Get last user utterance from tracker.
              tracker = (
                  await request.app.ctx.agent.tracker_store.retrieve(
                      sender_id
                  )
              )
              last_response = None
              if tracker:
                  last_response = next(
                      (
                          e
                          for e in reversed(tracker.events)
                          if isinstance(e, BotUttered)
                      ),
                      None,
                  )
  
              # If no previous utterance found use the reprompt_fallback phrase.
              if last_response is None:
                  last_response_text = self.reprompt_fallback_phrase
              else:
                  last_response_text = last_response.text
  
              twilio_response = self._build_twilio_voice_response(
                  [{"text": last_response_text}]
              )
          return response.text(
              str(twilio_response), content_type="text/xml"
          )
  
      return twilio_voice_webhook
  
imports: from sanic import Blueprint, response
  from sanic.request import Request
  from sanic.response import HTTPResponse
  from twilio.twiml.voice_response import VoiceResponse, Gather
  from typing import Text, Callable, Awaitable, List, Any, Dict, Optional
  import rasa.utils.io
  import rasa.shared.utils.io
  from rasa.shared.core.events import BotUttered
  from rasa.shared.exceptions import InvalidConfigException
  from rasa.core.channels.channel import InputChannel, CollectingOutputChannel, UserMessage
label_desc: Use image node_id 11 for calling the TwilioVoiceInput obj's underlying member method code with example usage: obj.blueprint(on_new_message) and returns: twilio_voice_webhook, response, response