Unverified Commit a9ee1830 authored by crazywoola's avatar crazywoola Committed by GitHub

fix: service suggested api (#1452)

parent b4861d2b
...@@ -11,7 +11,7 @@ from controllers.service_api.wraps import AppApiResource ...@@ -11,7 +11,7 @@ from controllers.service_api.wraps import AppApiResource
from libs.helper import TimestampField, uuid_value from libs.helper import TimestampField, uuid_value
from services.message_service import MessageService from services.message_service import MessageService
from extensions.ext_database import db from extensions.ext_database import db
from models.model import Account, Message from models.model import Message, EndUser
class MessageListApi(AppApiResource): class MessageListApi(AppApiResource):
...@@ -103,24 +103,26 @@ class MessageSuggestedApi(AppApiResource): ...@@ -103,24 +103,26 @@ class MessageSuggestedApi(AppApiResource):
message_id = str(message_id) message_id = str(message_id)
if app_model.mode != 'chat': if app_model.mode != 'chat':
raise NotChatAppError() raise NotChatAppError()
try: try:
message = db.session.query(Message).filter( message = db.session.query(Message).filter(
Message.id == message_id, Message.id == message_id,
Message.app_id == app_model.id, Message.app_id == app_model.id,
).first() ).first()
if end_user is None and message.from_account_id is not None: if end_user is None and message.from_end_user_id is not None:
user = db.session.get(Account, message.from_account_id) user = db.session.query(EndUser) \
elif end_user is None and message.from_end_user_id is not None: .filter(
user = create_or_update_end_user_for_user_id(app_model, message.from_end_user_id) EndUser.tenant_id == app_model.tenant_id,
EndUser.id == message.from_end_user_id,
EndUser.type == 'service_api'
).first()
else: else:
user = end_user user = end_user
questions = MessageService.get_suggested_questions_after_answer( questions = MessageService.get_suggested_questions_after_answer(
app_model=app_model, app_model=app_model,
user=user, user=user,
message_id=message_id message_id=message_id,
check_enabled=False
) )
except services.errors.message.MessageNotExistsError: except services.errors.message.MessageNotExistsError:
raise NotFound("Message Not Exists.") raise NotFound("Message Not Exists.")
......
...@@ -196,10 +196,10 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ...@@ -196,10 +196,10 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
</Col> </Col>
<Col sticky> <Col sticky>
<CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}> <CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
```bash {{ title: 'cURL' }} ```bash {{ title: 'cURL' }}
curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggeste' \ curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment