async def test_socketio_channel_jwt_authentication_invalid_key( caplog: LogCaptureFixture, ): from rasa.core.channels.socketio import SocketIOInput public_key = "random_key123" invalid_public_key = "my_invalid_key" jwt_algorithm = "HS256" invalid_auth_token = jwt.encode({"payload": "value"}, invalid_public_key, algorithm=jwt_algorithm) input_channel = SocketIOInput( # event name for messages sent from the user user_message_evt="user_uttered", # event name for messages sent from the bot bot_message_evt="bot_uttered", # socket.io namespace to use for the messages namespace=None, # public key for JWT methods jwt_key=public_key, # method used for the signature of the JWT authentication payload jwt_method=jwt_algorithm, ) assert input_channel.jwt_key == public_key assert input_channel.jwt_algorithm == jwt_algorithm with caplog.at_level(logging.ERROR): rasa.core.channels.channel.decode_bearer_token( invalid_auth_token, input_channel.jwt_key, input_channel.jwt_algorithm) assert any("JWT public key invalid." in message for message in caplog.messages)
def test_socketio_channel(): with mock.patch.object(sanic.Sanic, "run", fake_sanic_run): # START DOC INCLUDE from rasa.core.channels.socketio import SocketIOInput from rasa.core.agent import Agent from rasa.core.interpreter import RegexInterpreter # load your trained agent agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter()) input_channel = SocketIOInput( # event name for messages sent from the user user_message_evt="user_uttered", # event name for messages sent from the bot bot_message_evt="bot_uttered", # socket.io namespace to use for the messages namespace=None, ) s = agent.handle_channels([input_channel], 5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs routes_list = utils.list_routes(s) assert routes_list.get("socketio_webhook.health").startswith( "/webhooks/socketio") assert routes_list.get("handle_request").startswith("/socket.io")
async def test_socketio_channel_jwt_authentication(): from rasa.core.channels.socketio import SocketIOInput public_key = "random_key123" jwt_algorithm = "HS256" auth_token = jwt.encode({"payload": "value"}, public_key, algorithm=jwt_algorithm) input_channel = SocketIOInput( # event name for messages sent from the user user_message_evt="user_uttered", # event name for messages sent from the bot bot_message_evt="bot_uttered", # socket.io namespace to use for the messages namespace=None, # public key for JWT methods jwt_key=public_key, # method used for the signature of the JWT authentication payload jwt_method=jwt_algorithm, ) assert input_channel.jwt_key == public_key assert input_channel.jwt_algorithm == jwt_algorithm assert rasa.core.channels.channel.decode_bearer_token( auth_token, input_channel.jwt_key, input_channel.jwt_algorithm)
def test_socketio_channel(): # START DOC INCLUDE from rasa.core.channels.socketio import SocketIOInput input_channel = SocketIOInput( # event name for messages sent from the user user_message_evt="user_uttered", # event name for messages sent from the bot bot_message_evt="bot_uttered", # socket.io namespace to use for the messages namespace=None, ) s = rasa.core.run.configure_app([input_channel], port=5004) # END DOC INCLUDE # the above marker marks the end of the code snipped included # in the docs routes_list = utils.list_routes(s) assert routes_list.get("socketio_webhook.health").startswith("/webhooks/socketio") assert routes_list.get("handle_request").startswith("/socket.io")
from rasa.core.channels.socketio import SocketIOInput from rasa.core.agent import Agent from rasa.core.interpreter import RasaNLUInterpreter from rasa.utils.endpoints import EndpointConfig #from MyIo import RestInput action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") nlu_interpreter = RasaNLUInterpreter('/data/xingyang/Documents/Hangzhou Dianzi University - Chatbot/capstone-master/models/20190717-114901/nlu') agent = Agent.load('/data/xingyang/Documents/Hangzhou Dianzi University - Chatbot/capstone-master/models/20190717-114901/core', interpreter=nlu_interpreter, action_endpoint=action_endpoint) #input_channel = RestInput() input_channel = SocketIOInput( # event name for messages sent from the user user_message_evt="user_uttered", # event name for messages sent from the bot bot_message_evt="bot_uttered", # socket.io namespace to use for the messages namespace=None ) #s = agent.handle_channels([input_channel],5005, serve_forever=True) agent.handle_channels([input_channel], http_port=5005,route="/webhooks/",cors="*")