@@ -41,6 +41,21 @@ class ChatBotAssistantService {
4141 description:
4242 'Danh sách các thẻ phân loại (ví dụ: ["Học tập", "Gấp", "Backend"]). Gửi mảng rỗng [] nếu không có.' ,
4343 ),
44+ 'start_time' : Schema (
45+ SchemaType .string,
46+ description:
47+ 'Thời gian bắt đầu công việc theo định dạng ISO 8601 (VD: 2026-04-18T15:00:00Z). Nếu người dùng không nói, hãy bỏ qua hoặc để rỗng.' ,
48+ ),
49+ 'due_time' : Schema (
50+ SchemaType .string,
51+ description:
52+ 'Thời gian kết thúc (deadline) theo định dạng ISO 8601. Nếu không có, bỏ qua.' ,
53+ ),
54+ 'category_name' : Schema (
55+ SchemaType .string,
56+ description:
57+ 'Phân loại công việc vào 1 trong 4 nhóm: "Cá nhân", "Học tập", "Công việc", hoặc "Giải trí". Nếu không phân loại được, mặc định trả về "Cá nhân".' ,
58+ ),
4459 },
4560 requiredProperties: ['title' , 'priority' , 'tags' ],
4661 ),
@@ -77,26 +92,38 @@ class ChatBotAssistantService {
7792 final priority = (args['priority' ] as num ? )? .toInt () ?? 1 ;
7893 final rawTags = args['tags' ] as List <dynamic >? ?? [];
7994 final tags = rawTags.map ((e) => e.toString ()).toList ();
95+ final startTime = args['start_time' ] as String ? ;
96+ final dueTime = args['due_time' ] as String ? ;
8097
8198 final userId = Supabase .instance.client.auth.currentUser? .id;
8299 if (userId == null ) {
83100 return 'Vui lòng đăng nhập để tạo công việc.' ;
84101 }
85-
102+ final categoryName = args[ 'category_name' ] as String ? ?? 'Cá nhân' ;
86103 final dbResponse = await Supabase .instance.client.rpc (
87104 'create_task_full' ,
88105 params: {
89- 'p_title' : title,
90- 'p_priority' : priority,
106+ 'p_title' : args[ ' title' ] ,
107+ 'p_priority' : (args[ ' priority' ] as num ? ) ? . toInt () ?? 1 ,
91108 'p_profile_id' : userId,
92- 'p_tag_names' : tags,
109+ 'p_tag_names' :
110+ (args['tags' ] as List ? )? .map ((e) => e.toString ()).toList () ??
111+ [],
112+ 'p_category_name' : categoryName,
113+ 'p_start_time' : args['start_time' ],
114+ 'p_due_time' : args['due_time' ],
93115 },
94116 );
95117
96118 final isSuccess = dbResponse['success' ] == true ;
119+ if (! isSuccess) {
120+ debugPrint ("Lỗi từ Supabase: ${dbResponse ['error' ]}" );
121+ }
97122 final functionResponse = await _chatSession! .sendMessage (
98123 Content .functionResponse ('create_task_full' , {
99124 'status' : isSuccess ? 'Thành công' : 'Thất bại' ,
125+
126+ 'reason' : isSuccess ? '' : dbResponse['error' ].toString (),
100127 }),
101128 );
102129 return functionResponse.text ?? 'Đã xử lý xong yêu cầu của bạn!' ;
0 commit comments