MCPcopy
hub / github.com/RasaHQ/rasa / trigger_intent

Function trigger_intent

rasa/server.py:919–972  ·  view source on GitHub ↗
(request: Request, conversation_id: Text)

Source from the content-addressed store, hash-verified

917 @requires_auth(app, auth_token)
918 @ensure_loaded_agent(app)
919 async def trigger_intent(request: Request, conversation_id: Text) -> HTTPResponse:
920 request_params = request.json
921
922 intent_to_trigger = request_params.get("name")
923 entities = request_params.get("entities", [])
924
925 if not intent_to_trigger:
926 raise ErrorResponse(
927 HTTPStatus.BAD_REQUEST,
928 "BadRequest",
929 "Name of the intent not provided in request body.",
930 {"parameter": "name", "in": "body"},
931 )
932
933 verbosity = event_verbosity_parameter(request, EventVerbosity.AFTER_RESTART)
934
935 try:
936 async with app.ctx.agent.lock_store.lock(conversation_id):
937 tracker = await (
938 app.ctx.agent.processor.fetch_tracker_and_update_session(
939 conversation_id
940 )
941 )
942 output_channel = _get_output_channel(request, tracker)
943 if intent_to_trigger not in app.ctx.agent.domain.intents:
944 raise ErrorResponse(
945 HTTPStatus.NOT_FOUND,
946 "NotFound",
947 f"The intent {trigger_intent} does not exist in the domain.",
948 )
949 await app.ctx.agent.trigger_intent(
950 intent_name=intent_to_trigger,
951 entities=entities,
952 output_channel=output_channel,
953 tracker=tracker,
954 )
955 except ErrorResponse:
956 raise
957 except Exception as e:
958 logger.debug(traceback.format_exc())
959 raise ErrorResponse(
960 HTTPStatus.INTERNAL_SERVER_ERROR,
961 "ConversationError",
962 f"An unexpected error occurred. Error: {e}",
963 )
964
965 state = tracker.current_state(verbosity)
966
967 response_body: Dict[Text, Any] = {"tracker": state}
968
969 if isinstance(output_channel, CollectingOutputChannel):
970 response_body["messages"] = output_channel.messages
971
972 return response.json(response_body)
973
974 @app.post("/conversations/<conversation_id:path>/predict")
975 @requires_auth(app, auth_token)

Callers

nothing calls this directly

Calls 8

ErrorResponseClass · 0.85
_get_output_channelFunction · 0.85
lockMethod · 0.80
trigger_intentMethod · 0.80
current_stateMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…