(request: Request, conversation_id: Text)
| 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…