async def test_twilio_receive_no_previous_response(stack_agent: Agent): app = server.create_app(agent=stack_agent) inputs = { "initial_prompt": "hello", "reprompt_fallback_phrase": "i didn't get that", "speech_model": "default", "speech_timeout": "5", "assistant_voice": "woman", "enhanced": "false", } tv = TwilioVoiceInput(**inputs) channel.register([tv], app, "/webhooks/") client = app.asgi_client body = {"From": "Ray", "CallStatus": "answered"} _, response = await client.post( "/webhooks/twilio_voice/webhook", headers={"Content-type": "application/x-www-form-urlencoded"}, data=body, ) assert response.status == HTTPStatus.OK assert ( response.body == b'<?xml version="1.0" encoding="UTF-8"?><Response><Gather action="/webhooks/twilio_voice/webhook" actionOnEmptyResult="true" enhanced="false" input="speech" speechModel="default" speechTimeout="5"><Say voice="woman">i didn\'t get that</Say></Gather></Response>' )
def test_list_routes(default_agent): from rasa import server app = server.create_app(default_agent, auth_token=None) routes = utils.list_routes(app) assert set(routes.keys()) == { "hello", "version", "status", "retrieve_tracker", "append_events", "replace_events", "retrieve_story", "execute_action", "predict", "add_message", "train", "evaluate_stories", "evaluate_intents", "tracker_predict", "parse", "load_model", "unload_model", "get_domain", }
def configure_app( input_channels: Optional[List["InputChannel"]] = None, cors: Optional[Union[Text, List[Text]]] = None, auth_token: Optional[Text] = None, enable_api: bool = True, jwt_secret: Optional[Text] = None, jwt_method: Optional[Text] = None, route: Optional[Text] = "/webhooks/", port: int = constants.DEFAULT_SERVER_PORT, log_file: Optional[Text] = None, ): """Run the agent.""" from rasa import server if enable_api: app = server.create_app( cors_origins=cors, auth_token=auth_token, jwt_secret=jwt_secret, jwt_method=jwt_method, ) else: app = Sanic(__name__, configure_logging=False) CORS(app, resources={r"/*": { "origins": cors or "" }}, automatic_options=True) _configure_logging(log_file) if input_channels: rasa.core.channels.channel.register(input_channels, app, route=route) else: input_channels = [] if logger.isEnabledFor(logging.DEBUG): utils.list_routes(app) # configure async loop logging async def configure_async_logging(): if logger.isEnabledFor(logging.DEBUG): rasa.utils.io.enable_async_loop_debugging(asyncio.get_event_loop()) app.add_task(configure_async_logging) if "cmdline" in {c.name() for c in input_channels}: async def run_cmdline_io(running_app: Sanic): """Small wrapper to shut down the server once cmd io is done.""" await asyncio.sleep(1) # allow server to start await console.record_messages( server_url=constants.DEFAULT_SERVER_FORMAT.format(port)) logger.info("Killing Sanic server now.") running_app.stop() # kill the sanic serverx app.add_task(run_cmdline_io) return app
async def rasa_non_trained_server_secured(empty_agent: Agent) -> Sanic: app = server.create_app(agent=empty_agent, auth_token="rasa", jwt_secret="core") channel.register([RestInput()], app, "/webhooks/") return app
async def rasa_nlu_server(nlu_agent: Agent) -> Sanic: app = server.create_app(agent=nlu_agent) channel.register([RestInput()], app, "/webhooks/") return app
async def rasa_non_trained_server(empty_agent: Agent) -> Sanic: app = server.create_app(agent=empty_agent) channel.register([RestInput()], app, "/webhooks/") return app
def configure_app( input_channels: Optional[List["InputChannel"]] = None, cors: Optional[Union[Text, List[Text], None]] = None, auth_token: Optional[Text] = None, enable_api: bool = True, response_timeout: int = constants.DEFAULT_RESPONSE_TIMEOUT, jwt_secret: Optional[Text] = None, jwt_method: Optional[Text] = None, route: Optional[Text] = "/webhooks/", port: int = constants.DEFAULT_SERVER_PORT, endpoints: Optional[AvailableEndpoints] = None, log_file: Optional[Text] = None, conversation_id: Optional[Text] = uuid.uuid4().hex, ) -> Sanic: """Run the agent.""" rasa.core.utils.configure_file_logging(logger, log_file) if enable_api: app = server.create_app( cors_origins=cors, auth_token=auth_token, response_timeout=response_timeout, jwt_secret=jwt_secret, jwt_method=jwt_method, endpoints=endpoints, ) else: app = _create_app_without_api(cors) if input_channels: channels.channel.register(input_channels, app, route=route) else: input_channels = [] if logger.isEnabledFor(logging.DEBUG): rasa.core.utils.list_routes(app) # configure async loop logging async def configure_async_logging(): if logger.isEnabledFor(logging.DEBUG): rasa.utils.io.enable_async_loop_debugging(asyncio.get_event_loop()) app.add_task(configure_async_logging) if "cmdline" in {c.name() for c in input_channels}: async def run_cmdline_io(running_app: Sanic) -> None: """Small wrapper to shut down the server once cmd io is done.""" await asyncio.sleep(1) # allow server to start await console.record_messages( server_url=constants.DEFAULT_SERVER_FORMAT.format( "http", port), sender_id=conversation_id, ) logger.info("Killing Sanic server now.") running_app.stop() # kill the sanic server app.add_task(run_cmdline_io) return app
async def rasa_server_secured(default_agent): app = server.create_app(agent=default_agent, auth_token="rasa", jwt_secret="core") channel.register([RestInput()], app, "/webhooks/") return app
async def rasa_core_server(core_agent): app = server.create_app(agent=core_agent) channel.register([RestInput()], app, "/webhooks/") return app