def test_extract_input_channel(test_input, expected): from rasa.core.channels.channel import RestInput input_channel = RestInput() fake_request = MagicMock() fake_request.json = test_input assert input_channel._extract_input_channel(fake_request) == expected
def test_channel_registration_with_absolute_url_prefix_overwrites_route(): from rasa.core.channels.channel import RestInput import rasa.core input_channel = RestInput() test_route = "/absolute_route" input_channel.url_prefix = lambda: test_route app = Sanic(__name__) ignored_base_route = "/should_be_ignored" rasa.core.channels.channel.register( [input_channel], app, route="/should_be_ignored" ) # Assure that an absolute url returned by `url_prefix` overwrites route parameter # given in `register`. routes_list = utils.list_routes(app) assert routes_list.get("custom_webhook_RestInput.health").startswith(test_route) assert ignored_base_route not in routes_list.get("custom_webhook_RestInput.health")
async def on_message_wrapper(on_new_message, text, queue, sender_id): collector = QueueOutputChannel(queue) message = UserMessage(text, collector, sender_id, input_channel=RestInput.name()) await on_new_message( message ) ## TODO find details about this functions # func sends message to core await queue.put("DONE")
def test_register_channel_without_route(): """Check we properly connect the input channel blueprint if route is None""" from rasa.core.channels.channel import RestInput import rasa.core input_channel = RestInput() app = Sanic(__name__) rasa.core.channels.channel.register([input_channel], app, route=None) routes_list = utils.list_routes(app) assert routes_list.get("custom_webhook_RestInput.receive").startswith("/webhook")
def test_channel_inheritance(): from rasa.core.channels.channel import RestInput from rasa.core.channels.rasa_chat import RasaChatInput rasa_input = RasaChatInput("https://example.com") s = rasa.core.run.configure_app([RestInput(), rasa_input], port=5004) routes_list = utils.list_routes(s) assert routes_list.get("custom_webhook_RasaChatInput.health").startswith( "/webhooks/rasa") assert routes_list.get("custom_webhook_RasaChatInput.receive").startswith( "/webhooks/rasa/webhook")
async def on_message_wrapper( on_new_message: Callable[[UserMessage], Awaitable[None]], text: Text, queue: Queue, sender_id: Text, ) -> None: collector = QueueOutputChannel(queue) message = UserMessage( text, collector, sender_id, input_channel=RestInput.name() ) await on_new_message(message) await queue.put("DONE") # pytype: disable=bad-return-type
def test_channel_inheritance(): from rasa.core.channels.channel import RestInput from rasa.core.channels.rasa_chat import RasaChatInput from rasa.core.agent import Agent from rasa.core.interpreter import RegexInterpreter # load your trained agent agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) rasa_input = RasaChatInput("https://example.com") s = agent.handle_channels([RestInput(), rasa_input], 5004) routes_list = utils.list_routes(s) assert routes_list.get("custom_webhook_RasaChatInput.health").startswith( "/webhooks/rasa") assert routes_list.get("custom_webhook_RasaChatInput.receive").startswith( "/webhooks/rasa/webhook")
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_nlu_server(nlu_agent): app = server.create_app(agent=nlu_agent) channel.register([RestInput()], app, "/webhooks/") return app
def url_prefix(self): return RestInput.name()
async def rasa_server_without_api() -> Sanic: app = _create_app_without_api() channel.register([RestInput()], app, "/webhooks/") return app
async def rasa_core_server(core_agent: Agent) -> Sanic: app = server.create_app(agent=core_agent) channel.register([RestInput()], app, "/webhooks/") return app
def url_prefix(self) -> Text: return RestInput.name()