diff --git a/api/controllers/service_api/app/message.py b/api/controllers/service_api/app/message.py index 1b148a9756..d90fa2081f 100644 --- a/api/controllers/service_api/app/message.py +++ b/api/controllers/service_api/app/message.py @@ -93,6 +93,18 @@ class MessageFeedbackApi(Resource): return {"result": "success"} +class AppGetFeedbacksApi(Resource): + @validate_app_token + def get(self, app_model: App): + """Get All Feedbacks of an app""" + parser = reqparse.RequestParser() + parser.add_argument("page", type=int, default=1, location="args") + parser.add_argument("limit", type=int_range(1, 101), required=False, default=20, location="args") + args = parser.parse_args() + feedbacks = MessageService.get_all_messages_feedbacks(app_model, page=args["page"], limit=args["limit"]) + return {"data": feedbacks} + + class MessageSuggestedApi(Resource): @validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.QUERY, required=True)) def get(self, app_model: App, end_user: EndUser, message_id): @@ -119,3 +131,4 @@ class MessageSuggestedApi(Resource): api.add_resource(MessageListApi, "/messages") api.add_resource(MessageFeedbackApi, "/messages//feedbacks") api.add_resource(MessageSuggestedApi, "/messages//suggested") +api.add_resource(AppGetFeedbacksApi, "/app/feedbacks") diff --git a/api/models/model.py b/api/models/model.py index 03ecd14aee..ab426649c5 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -1237,6 +1237,21 @@ class MessageFeedback(Base): account = db.session.query(Account).filter(Account.id == self.from_account_id).first() return account + def to_dict(self): + return { + "id": str(self.id), + "app_id": str(self.app_id), + "conversation_id": str(self.conversation_id), + "message_id": str(self.message_id), + "rating": self.rating, + "content": self.content, + "from_source": self.from_source, + "from_end_user_id": str(self.from_end_user_id) if self.from_end_user_id else None, + "from_account_id": str(self.from_account_id) if self.from_account_id else None, + "created_at": self.created_at.isoformat(), + "updated_at": self.updated_at.isoformat(), + } + class MessageFile(Base): __tablename__ = "message_files" diff --git a/api/services/message_service.py b/api/services/message_service.py index aefab1556c..51b070ece7 100644 --- a/api/services/message_service.py +++ b/api/services/message_service.py @@ -177,6 +177,21 @@ class MessageService: return feedback + @classmethod + def get_all_messages_feedbacks(cls, app_model: App, page: int, limit: int): + """Get all feedbacks of an app""" + offset = (page - 1) * limit + feedbacks = ( + db.session.query(MessageFeedback) + .filter(MessageFeedback.app_id == app_model.id) + .order_by(MessageFeedback.created_at.desc(), MessageFeedback.id.desc()) + .limit(limit) + .offset(offset) + .all() + ) + + return [record.to_dict() for record in feedbacks] + @classmethod def get_message(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str): message = ( diff --git a/web/app/components/develop/template/template.en.mdx b/web/app/components/develop/template/template.en.mdx index 75f044f780..43dc226107 100755 --- a/web/app/components/develop/template/template.en.mdx +++ b/web/app/components/develop/template/template.en.mdx @@ -383,6 +383,69 @@ The text generation application offers non-session support and is ideal for tran --- + + + + Get application's feedbacks. + + ### Query + + + (optional)pagination,default:1 + + + + + + (optional) records per page default:20 + + + + ### Response + - `data` (List) return apps feedback list. + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- + --- + + + + アプリのエンドユーザーからのフィードバックや「いいね」を取得します。 + + ### クエリ + + + (任意)ページ番号。デフォルト値:1 + + + + + + (任意)1ページあたりの件数。デフォルト値:20 + + + + ### レスポンス + - `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。 + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- + +--- + + + + Get application's feedbacks. + + ### Query + + + (optional)pagination,default:1 + + + + + + (optional) records per page default:20 + + + + ### Response + - `data` (List) return apps feedback list. + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + --- - + \ No newline at end of file diff --git a/web/app/components/develop/template/template_advanced_chat.en.mdx b/web/app/components/develop/template/template_advanced_chat.en.mdx index b77e0528d7..6377bfba00 100644 --- a/web/app/components/develop/template/template_advanced_chat.en.mdx +++ b/web/app/components/develop/template/template_advanced_chat.en.mdx @@ -487,6 +487,69 @@ Chat applications support session persistence, allowing previous chat history to --- + + + + Get application's feedbacks. + + ### Query + + + (optional)pagination,default:1 + + + + + + (optional) records per page default:20 + + + + ### Response + - `data` (List) return apps feedback list. + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- + + + + アプリのエンドユーザーからのフィードバックや「いいね」を取得します。 + + ### クエリ + + + (任意)ページ番号。デフォルト値:1 + + + + + + (任意)1ページあたりの件数。デフォルト値:20 + + + + ### レスポンス + - `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。 + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- + + + + + 获取应用的终端用户反馈、点赞。 + + ### Query + + + (选填)分页,默认值:1 + + + + + + (选填)每页数量,默认值:20 + + + + ### Response + - `data` (List) 返回该APP的点赞、反馈列表。 + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + + ``` + + + + +--- + + + + Get application's feedbacks. + + ### Query + + + (optional)pagination,default:1 + + + + + + (optional) records per page default:20 + + + + ### Response + - `data` (List) return apps feedback list. + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- + + + + アプリのエンドユーザーからのフィードバックや「いいね」を取得します。 + + ### クエリ + + + (任意)ページ番号。デフォルト値:1 + + + + + + (任意)1ページあたりの件数。デフォルト値:20 + + + + ### レスポンス + - `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。 + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- + + + + + 获取应用的终端用户反馈、点赞。 + + ### Query + + + (选填)分页,默认值:1 + + + + + + (选填)每页数量,默认值:20 + + + + ### Response + - `data` (List) 返回该APP的点赞、反馈列表。 + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \ + --header 'Authorization: Bearer {api_key}' \ + --header 'Content-Type: application/json' + ``` + + + + + ```json {{ title: 'Response' }} + { + "data": [ + { + "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25", + "app_id": "f252d396-fe48-450e-94ec-e184218e7346", + "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d", + "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11", + "rating": "like", + "content": "message feedback information-3", + "from_source": "user", + "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5", + "from_account_id": null, + "created_at": "2025-04-24T09:24:38", + "updated_at": "2025-04-24T09:24:38" + } + ] + } + ``` + + + +--- +