tychat-contracts 1.0.70 → 1.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/ai/ai-action.dto.d.ts +1 -0
  2. package/dist/ai/ai-action.dto.d.ts.map +1 -1
  3. package/dist/ai/ai-action.dto.js +13 -1
  4. package/dist/conversations/conversation-response.dto.d.ts +2 -2
  5. package/dist/conversations/conversation-response.dto.d.ts.map +1 -1
  6. package/dist/conversations/conversation-response.dto.js +5 -4
  7. package/dist/conversations/conversation-session-response.dto.d.ts.map +1 -1
  8. package/dist/conversations/conversation-session-response.dto.js +3 -2
  9. package/dist/conversations/conversation-type.dto.d.ts +4 -1
  10. package/dist/conversations/conversation-type.dto.d.ts.map +1 -1
  11. package/dist/conversations/conversation-type.dto.js +8 -3
  12. package/dist/conversations/create-conversation-session.dto.d.ts.map +1 -1
  13. package/dist/conversations/create-conversation-session.dto.js +3 -2
  14. package/dist/conversations/create-conversation.dto.d.ts +2 -2
  15. package/dist/conversations/create-conversation.dto.d.ts.map +1 -1
  16. package/dist/conversations/create-conversation.dto.js +6 -5
  17. package/dist/patients/index.d.ts +1 -0
  18. package/dist/patients/index.d.ts.map +1 -1
  19. package/dist/patients/index.js +1 -0
  20. package/dist/patients/upsert-patient-by-phone.dto.d.ts +9 -0
  21. package/dist/patients/upsert-patient-by-phone.dto.d.ts.map +1 -0
  22. package/dist/patients/upsert-patient-by-phone.dto.js +45 -0
  23. package/package.json +1 -1
  24. package/src/ai/ai-action.dto.ts +12 -1
  25. package/src/conversations/conversation-response.dto.ts +8 -7
  26. package/src/conversations/conversation-session-response.dto.ts +4 -3
  27. package/src/conversations/conversation-type.dto.ts +12 -3
  28. package/src/conversations/create-conversation-session.dto.ts +4 -3
  29. package/src/conversations/create-conversation.dto.ts +8 -7
  30. package/src/patients/index.ts +1 -0
  31. package/src/patients/upsert-patient-by-phone.dto.ts +29 -0
@@ -22,6 +22,7 @@ export declare class AiStructuredResponseDto {
22
22
  type: AiResponseTypeDto;
23
23
  actionType?: AiActionTypeDto;
24
24
  message?: string;
25
+ messages?: string[];
25
26
  data?: AiActionDataDto;
26
27
  }
27
28
  //# sourceMappingURL=ai-action.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-action.dto.d.ts","sourceRoot":"","sources":["../../src/ai/ai-action.dto.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,iBAAiB,gCAAiC,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,eAAO,MAAM,eAAe,yEAIlB,CAAC;AACX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,qBAAa,eAAe;IAO1B,SAAS,CAAC,EAAE,MAAM,CAAC;IASnB,IAAI,CAAC,EAAE,MAAM,CAAC;IASd,GAAG,CAAC,EAAE,MAAM,CAAC;IAQb,SAAS,CAAC,EAAE,MAAM,CAAC;IAQnB,aAAa,CAAC,EAAE,OAAO,CAAC;IAQxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAQ/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAQ5B,WAAW,CAAC,EAAE,MAAM,CAAC;IAUrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAQxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAQhB,IAAI,CAAC,EAAE,MAAM,CAAC;IAQd,aAAa,CAAC,EAAE,MAAM,CAAC;IAQvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAUhB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,qBAAa,uBAAuB;IAOlC,IAAI,EAAE,iBAAiB,CAAC;IASxB,UAAU,CAAC,EAAE,eAAe,CAAC;IAQ7B,OAAO,CAAC,EAAE,MAAM,CAAC;IAOjB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB"}
1
+ {"version":3,"file":"ai-action.dto.d.ts","sourceRoot":"","sources":["../../src/ai/ai-action.dto.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,iBAAiB,gCAAiC,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,eAAO,MAAM,eAAe,yEAIlB,CAAC;AACX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,qBAAa,eAAe;IAO1B,SAAS,CAAC,EAAE,MAAM,CAAC;IASnB,IAAI,CAAC,EAAE,MAAM,CAAC;IASd,GAAG,CAAC,EAAE,MAAM,CAAC;IAQb,SAAS,CAAC,EAAE,MAAM,CAAC;IAQnB,aAAa,CAAC,EAAE,OAAO,CAAC;IAQxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAQ/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAQ5B,WAAW,CAAC,EAAE,MAAM,CAAC;IAUrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAQxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAQhB,IAAI,CAAC,EAAE,MAAM,CAAC;IAQd,aAAa,CAAC,EAAE,MAAM,CAAC;IAQvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAUhB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,qBAAa,uBAAuB;IAOlC,IAAI,EAAE,iBAAiB,CAAC;IASxB,UAAU,CAAC,EAAE,eAAe,CAAC;IAQ7B,OAAO,CAAC,EAAE,MAAM,CAAC;IAWjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAOpB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB"}
@@ -171,6 +171,7 @@ class AiStructuredResponseDto {
171
171
  type;
172
172
  actionType;
173
173
  message;
174
+ messages;
174
175
  data;
175
176
  }
176
177
  exports.AiStructuredResponseDto = AiStructuredResponseDto;
@@ -195,13 +196,24 @@ __decorate([
195
196
  ], AiStructuredResponseDto.prototype, "actionType", void 0);
196
197
  __decorate([
197
198
  (0, swagger_1.ApiPropertyOptional)({
198
- description: 'Message returned to the user',
199
+ description: 'Message returned to the user (full text, all parts joined)',
199
200
  example: 'I need your CPF and birth date to create the patient.',
200
201
  }),
201
202
  (0, class_validator_1.IsOptional)(),
202
203
  (0, class_validator_1.IsString)(),
203
204
  __metadata("design:type", String)
204
205
  ], AiStructuredResponseDto.prototype, "message", void 0);
206
+ __decorate([
207
+ (0, swagger_1.ApiPropertyOptional)({
208
+ description: 'Individual message parts to send as separate WhatsApp messages for a more natural conversation flow. When present, each entry is dispatched as its own message.',
209
+ type: [String],
210
+ example: ['Dados registrados com sucesso!', 'Temos os seguintes procedimentos disponíveis:\n- Consulta clínica'],
211
+ }),
212
+ (0, class_validator_1.IsOptional)(),
213
+ (0, class_validator_1.IsArray)(),
214
+ (0, class_validator_1.IsString)({ each: true }),
215
+ __metadata("design:type", Array)
216
+ ], AiStructuredResponseDto.prototype, "messages", void 0);
205
217
  __decorate([
206
218
  (0, swagger_1.ApiPropertyOptional)({
207
219
  description: 'Structured payload extracted from the conversation',
@@ -1,4 +1,4 @@
1
- import { ConversationTypeDto } from './conversation-type.dto';
1
+ import { ConversationMessageTypeDto } from './conversation-type.dto';
2
2
  /**
3
3
  * Represents a persisted conversation message returned by the API.
4
4
  */
@@ -8,7 +8,7 @@ export declare class ConversationResponseDto {
8
8
  unitId?: number;
9
9
  patientId: string;
10
10
  sessionUuid: string;
11
- type: ConversationTypeDto;
11
+ type: ConversationMessageTypeDto;
12
12
  message: string;
13
13
  aiUsageId?: string;
14
14
  createdAt: string;
@@ -1 +1 @@
1
- {"version":3,"file":"conversation-response.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/conversation-response.dto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D;;GAEG;AACH,qBAAa,uBAAuB;IAIlC,EAAE,EAAE,MAAM,CAAC;IAKX,MAAM,EAAE,MAAM,CAAC;IAIf,MAAM,CAAC,EAAE,MAAM,CAAC;IAQhB,SAAS,EAAE,MAAM,CAAC;IAQlB,WAAW,EAAE,MAAM,CAAC;IAMpB,IAAI,EAAE,mBAAmB,CAAC;IAQ1B,OAAO,EAAE,MAAM,CAAC;IAQhB,SAAS,CAAC,EAAE,MAAM,CAAC;IAQnB,SAAS,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"conversation-response.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/conversation-response.dto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE;;GAEG;AACH,qBAAa,uBAAuB;IAIlC,EAAE,EAAE,MAAM,CAAC;IAKX,MAAM,EAAE,MAAM,CAAC;IAIf,MAAM,CAAC,EAAE,MAAM,CAAC;IAShB,SAAS,EAAE,MAAM,CAAC;IAQlB,WAAW,EAAE,MAAM,CAAC;IAMpB,IAAI,EAAE,0BAA0B,CAAC;IAQjC,OAAO,EAAE,MAAM,CAAC;IAQhB,SAAS,CAAC,EAAE,MAAM,CAAC;IAQnB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -46,11 +46,12 @@ __decorate([
46
46
  ], ConversationResponseDto.prototype, "unitId", void 0);
47
47
  __decorate([
48
48
  (0, swagger_1.ApiProperty)({
49
- description: 'Patient identifier (e.g. phone number)',
50
- example: '5511999999999',
49
+ description: 'Patient UUID',
50
+ example: '550e8400-e29b-41d4-a716-446655440000',
51
51
  }),
52
52
  (0, class_validator_1.IsString)(),
53
53
  (0, class_validator_1.IsNotEmpty)(),
54
+ (0, class_validator_1.IsUUID)(),
54
55
  __metadata("design:type", String)
55
56
  ], ConversationResponseDto.prototype, "patientId", void 0);
56
57
  __decorate([
@@ -64,8 +65,8 @@ __decorate([
64
65
  ], ConversationResponseDto.prototype, "sessionUuid", void 0);
65
66
  __decorate([
66
67
  (0, swagger_1.ApiProperty)({
67
- description: 'Conversation type: "ia" or "human"',
68
- example: 'ia',
68
+ description: 'Conversation message type: "ia", "human" or "patient"',
69
+ example: 'patient',
69
70
  }),
70
71
  __metadata("design:type", String)
71
72
  ], ConversationResponseDto.prototype, "type", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"conversation-session-response.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/conversation-session-response.dto.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,8BAA8B;IAIzC,EAAE,EAAE,MAAM,CAAC;IAQX,WAAW,EAAE,MAAM,CAAC;IAKpB,MAAM,EAAE,MAAM,CAAC;IAQf,SAAS,EAAE,MAAM,CAAC;IAIlB,MAAM,CAAC,EAAE,MAAM,CAAC;IAQhB,SAAS,EAAE,MAAM,CAAC;IAQlB,SAAS,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"conversation-session-response.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/conversation-session-response.dto.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,8BAA8B;IAIzC,EAAE,EAAE,MAAM,CAAC;IAQX,WAAW,EAAE,MAAM,CAAC;IAKpB,MAAM,EAAE,MAAM,CAAC;IASf,SAAS,EAAE,MAAM,CAAC;IAIlB,MAAM,CAAC,EAAE,MAAM,CAAC;IAQhB,SAAS,EAAE,MAAM,CAAC;IAQlB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -49,11 +49,12 @@ __decorate([
49
49
  ], ConversationSessionResponseDto.prototype, "tenant", void 0);
50
50
  __decorate([
51
51
  (0, swagger_1.ApiProperty)({
52
- description: 'Patient identifier (e.g. phone number)',
53
- example: '5511999999999',
52
+ description: 'Patient UUID',
53
+ example: '550e8400-e29b-41d4-a716-446655440000',
54
54
  }),
55
55
  (0, class_validator_1.IsString)(),
56
56
  (0, class_validator_1.IsNotEmpty)(),
57
+ (0, class_validator_1.IsUUID)(),
57
58
  __metadata("design:type", String)
58
59
  ], ConversationSessionResponseDto.prototype, "patientId", void 0);
59
60
  __decorate([
@@ -1,3 +1,6 @@
1
+ export declare const CONVERSATION_SESSION_TYPES: readonly ["ia", "human"];
1
2
  export declare const CONVERSATION_TYPES: readonly ["ia", "human"];
2
- export type ConversationTypeDto = (typeof CONVERSATION_TYPES)[number];
3
+ export type ConversationTypeDto = (typeof CONVERSATION_SESSION_TYPES)[number];
4
+ export declare const CONVERSATION_MESSAGE_TYPES: readonly ["ia", "human", "patient"];
5
+ export type ConversationMessageTypeDto = (typeof CONVERSATION_MESSAGE_TYPES)[number];
3
6
  //# sourceMappingURL=conversation-type.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"conversation-type.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/conversation-type.dto.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,0BAA2B,CAAC;AAC3D,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"conversation-type.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/conversation-type.dto.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,0BAA0B,0BAA2B,CAAC;AAGnE,eAAO,MAAM,kBAAkB,0BAA6B,CAAC;AAE7D,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAI9E,eAAO,MAAM,0BAA0B,qCAAsC,CAAC;AAC9E,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONVERSATION_TYPES = void 0;
4
- // Allowed conversation types.
3
+ exports.CONVERSATION_MESSAGE_TYPES = exports.CONVERSATION_TYPES = exports.CONVERSATION_SESSION_TYPES = void 0;
4
+ // Allowed conversation session types.
5
5
  // "ia" → patient interacting with the AI.
6
6
  // "human" → human staff member responding to the patient.
7
- exports.CONVERSATION_TYPES = ['ia', 'human'];
7
+ exports.CONVERSATION_SESSION_TYPES = ['ia', 'human'];
8
+ // Backwards-compatible alias for session types.
9
+ exports.CONVERSATION_TYPES = exports.CONVERSATION_SESSION_TYPES;
10
+ // Allowed conversation message types for the `conversations` table.
11
+ // "patient" → message authored by the patient/user (WhatsApp sender).
12
+ exports.CONVERSATION_MESSAGE_TYPES = ['ia', 'human', 'patient'];
@@ -1 +1 @@
1
- {"version":3,"file":"create-conversation-session.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/create-conversation-session.dto.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,4BAA4B;IAIvC,MAAM,EAAE,MAAM,CAAC;IAQf,SAAS,EAAE,MAAM,CAAC;IAMlB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"create-conversation-session.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/create-conversation-session.dto.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,4BAA4B;IAIvC,MAAM,EAAE,MAAM,CAAC;IASf,SAAS,EAAE,MAAM,CAAC;IAMlB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -30,11 +30,12 @@ __decorate([
30
30
  ], CreateConversationSessionDto.prototype, "tenant", void 0);
31
31
  __decorate([
32
32
  (0, swagger_1.ApiProperty)({
33
- description: 'Patient identifier (e.g. phone number or WhatsApp id)',
34
- example: '5511999999999',
33
+ description: 'Patient UUID',
34
+ example: '550e8400-e29b-41d4-a716-446655440000',
35
35
  }),
36
36
  (0, class_validator_1.IsString)(),
37
37
  (0, class_validator_1.IsNotEmpty)(),
38
+ (0, class_validator_1.IsUUID)(),
38
39
  __metadata("design:type", String)
39
40
  ], CreateConversationSessionDto.prototype, "patientId", void 0);
40
41
  __decorate([
@@ -1,4 +1,4 @@
1
- import { ConversationTypeDto } from './conversation-type.dto';
1
+ import { ConversationMessageTypeDto } from './conversation-type.dto';
2
2
  /**
3
3
  * Payload used to persist a single conversation message.
4
4
  * AiUsageId must be provided whenever type is "ia" so token costs can be tracked.
@@ -8,7 +8,7 @@ export declare class CreateConversationDto {
8
8
  unitId?: number;
9
9
  patientId: string;
10
10
  sessionUuid: string;
11
- type: ConversationTypeDto;
11
+ type: ConversationMessageTypeDto;
12
12
  message: string;
13
13
  aiUsageId?: string;
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"create-conversation.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/create-conversation.dto.ts"],"names":[],"mappings":"AAUA,OAAO,EAAsB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAElF;;;GAGG;AACH,qBAAa,qBAAqB;IAIhC,MAAM,EAAE,MAAM,CAAC;IAMf,MAAM,CAAC,EAAE,MAAM,CAAC;IAQhB,SAAS,EAAE,MAAM,CAAC;IAOlB,WAAW,EAAE,MAAM,CAAC;IASpB,IAAI,EAAE,mBAAmB,CAAC;IAQ1B,OAAO,EAAE,MAAM,CAAC;IAQhB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"create-conversation.dto.d.ts","sourceRoot":"","sources":["../../src/conversations/create-conversation.dto.ts"],"names":[],"mappings":"AAUA,OAAO,EAA8B,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAEjG;;;GAGG;AACH,qBAAa,qBAAqB;IAIhC,MAAM,EAAE,MAAM,CAAC;IAMf,MAAM,CAAC,EAAE,MAAM,CAAC;IAShB,SAAS,EAAE,MAAM,CAAC;IAOlB,WAAW,EAAE,MAAM,CAAC;IASpB,IAAI,EAAE,0BAA0B,CAAC;IAQjC,OAAO,EAAE,MAAM,CAAC;IAQhB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -42,11 +42,12 @@ __decorate([
42
42
  ], CreateConversationDto.prototype, "unitId", void 0);
43
43
  __decorate([
44
44
  (0, swagger_1.ApiProperty)({
45
- description: 'Patient identifier (e.g. phone number)',
45
+ description: 'Patient UUID',
46
46
  example: '5511999999999',
47
47
  }),
48
48
  (0, class_validator_1.IsString)(),
49
49
  (0, class_validator_1.IsNotEmpty)(),
50
+ (0, class_validator_1.IsUUID)(),
50
51
  __metadata("design:type", String)
51
52
  ], CreateConversationDto.prototype, "patientId", void 0);
52
53
  __decorate([
@@ -59,11 +60,11 @@ __decorate([
59
60
  ], CreateConversationDto.prototype, "sessionUuid", void 0);
60
61
  __decorate([
61
62
  (0, swagger_1.ApiProperty)({
62
- description: 'Conversation type: "ia" when the AI responds to the patient, "human" when a staff member responds',
63
- enum: conversation_type_dto_1.CONVERSATION_TYPES,
64
- example: 'ia',
63
+ description: 'Conversation message type: "ia" when the AI responds, "human" when staff responds, "patient" when the patient/user sends the message',
64
+ enum: conversation_type_dto_1.CONVERSATION_MESSAGE_TYPES,
65
+ example: 'patient',
65
66
  }),
66
- (0, class_validator_1.IsEnum)(conversation_type_dto_1.CONVERSATION_TYPES),
67
+ (0, class_validator_1.IsEnum)(conversation_type_dto_1.CONVERSATION_MESSAGE_TYPES),
67
68
  __metadata("design:type", String)
68
69
  ], CreateConversationDto.prototype, "type", void 0);
69
70
  __decorate([
@@ -2,4 +2,5 @@ export * from './create-patient.dto';
2
2
  export * from './update-patient.dto';
3
3
  export * from './patient-history-entry.dto';
4
4
  export * from './list-patients-query.dto';
5
+ export * from './upsert-patient-by-phone.dto';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/patients/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/patients/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC"}
@@ -18,3 +18,4 @@ __exportStar(require("./create-patient.dto"), exports);
18
18
  __exportStar(require("./update-patient.dto"), exports);
19
19
  __exportStar(require("./patient-history-entry.dto"), exports);
20
20
  __exportStar(require("./list-patients-query.dto"), exports);
21
+ __exportStar(require("./upsert-patient-by-phone.dto"), exports);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Minimal patient information used to upsert a patient based on WhatsApp phone.
3
+ * Used for incoming webhook messages where we don't have CPF/birthDate yet.
4
+ */
5
+ export declare class UpsertPatientByPhoneDto {
6
+ phone: string;
7
+ pushName?: string;
8
+ }
9
+ //# sourceMappingURL=upsert-patient-by-phone.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsert-patient-by-phone.dto.d.ts","sourceRoot":"","sources":["../../src/patients/upsert-patient-by-phone.dto.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,uBAAuB;IASlC,KAAK,EAAE,MAAM,CAAC;IAUd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UpsertPatientByPhoneDto = void 0;
13
+ const swagger_1 = require("@nestjs/swagger");
14
+ const class_validator_1 = require("class-validator");
15
+ /**
16
+ * Minimal patient information used to upsert a patient based on WhatsApp phone.
17
+ * Used for incoming webhook messages where we don't have CPF/birthDate yet.
18
+ */
19
+ class UpsertPatientByPhoneDto {
20
+ phone;
21
+ pushName;
22
+ }
23
+ exports.UpsertPatientByPhoneDto = UpsertPatientByPhoneDto;
24
+ __decorate([
25
+ (0, swagger_1.ApiProperty)({
26
+ description: 'Patient phone as received from WhatsApp (local/normalized format)',
27
+ example: '5511999999999',
28
+ maxLength: 30,
29
+ }),
30
+ (0, class_validator_1.IsString)(),
31
+ (0, class_validator_1.IsNotEmpty)(),
32
+ (0, class_validator_1.MaxLength)(30),
33
+ __metadata("design:type", String)
34
+ ], UpsertPatientByPhoneDto.prototype, "phone", void 0);
35
+ __decorate([
36
+ (0, swagger_1.ApiPropertyOptional)({
37
+ description: 'WhatsApp contact display name (PushName)',
38
+ example: 'Maria Silva',
39
+ maxLength: 255,
40
+ }),
41
+ (0, class_validator_1.IsOptional)(),
42
+ (0, class_validator_1.IsString)(),
43
+ (0, class_validator_1.MaxLength)(255),
44
+ __metadata("design:type", String)
45
+ ], UpsertPatientByPhoneDto.prototype, "pushName", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tychat-contracts",
3
- "version": "1.0.70",
3
+ "version": "1.0.72",
4
4
  "description": "DTOs compartilhados com class-validator (API e microserviços)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -160,13 +160,24 @@ export class AiStructuredResponseDto {
160
160
  actionType?: AiActionTypeDto;
161
161
 
162
162
  @ApiPropertyOptional({
163
- description: 'Message returned to the user',
163
+ description: 'Message returned to the user (full text, all parts joined)',
164
164
  example: 'I need your CPF and birth date to create the patient.',
165
165
  })
166
166
  @IsOptional()
167
167
  @IsString()
168
168
  message?: string;
169
169
 
170
+ @ApiPropertyOptional({
171
+ description:
172
+ 'Individual message parts to send as separate WhatsApp messages for a more natural conversation flow. When present, each entry is dispatched as its own message.',
173
+ type: [String],
174
+ example: ['Dados registrados com sucesso!', 'Temos os seguintes procedimentos disponíveis:\n- Consulta clínica'],
175
+ })
176
+ @IsOptional()
177
+ @IsArray()
178
+ @IsString({ each: true })
179
+ messages?: string[];
180
+
170
181
  @ApiPropertyOptional({
171
182
  description: 'Structured payload extracted from the conversation',
172
183
  type: AiActionDataDto,
@@ -1,6 +1,6 @@
1
1
  import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2
- import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
3
- import { ConversationTypeDto } from './conversation-type.dto';
2
+ import { IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
3
+ import { ConversationMessageTypeDto } from './conversation-type.dto';
4
4
 
5
5
  /**
6
6
  * Represents a persisted conversation message returned by the API.
@@ -21,11 +21,12 @@ export class ConversationResponseDto {
21
21
  unitId?: number;
22
22
 
23
23
  @ApiProperty({
24
- description: 'Patient identifier (e.g. phone number)',
25
- example: '5511999999999',
24
+ description: 'Patient UUID',
25
+ example: '550e8400-e29b-41d4-a716-446655440000',
26
26
  })
27
27
  @IsString()
28
28
  @IsNotEmpty()
29
+ @IsUUID()
29
30
  patientId: string;
30
31
 
31
32
  @ApiProperty({
@@ -37,10 +38,10 @@ export class ConversationResponseDto {
37
38
  sessionUuid: string;
38
39
 
39
40
  @ApiProperty({
40
- description: 'Conversation type: "ia" or "human"',
41
- example: 'ia',
41
+ description: 'Conversation message type: "ia", "human" or "patient"',
42
+ example: 'patient',
42
43
  })
43
- type: ConversationTypeDto;
44
+ type: ConversationMessageTypeDto;
44
45
 
45
46
  @ApiProperty({
46
47
  description: 'Message content',
@@ -1,5 +1,5 @@
1
1
  import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2
- import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
2
+ import { IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
3
3
 
4
4
  /**
5
5
  * Represents a conversation session record returned by the API.
@@ -25,11 +25,12 @@ export class ConversationSessionResponseDto {
25
25
  tenant: string;
26
26
 
27
27
  @ApiProperty({
28
- description: 'Patient identifier (e.g. phone number)',
29
- example: '5511999999999',
28
+ description: 'Patient UUID',
29
+ example: '550e8400-e29b-41d4-a716-446655440000',
30
30
  })
31
31
  @IsString()
32
32
  @IsNotEmpty()
33
+ @IsUUID()
33
34
  patientId: string;
34
35
 
35
36
  @ApiPropertyOptional({ description: 'Tenant unit id', example: 1 })
@@ -1,5 +1,14 @@
1
- // Allowed conversation types.
1
+ // Allowed conversation session types.
2
2
  // "ia" → patient interacting with the AI.
3
3
  // "human" → human staff member responding to the patient.
4
- export const CONVERSATION_TYPES = ['ia', 'human'] as const;
5
- export type ConversationTypeDto = (typeof CONVERSATION_TYPES)[number];
4
+ export const CONVERSATION_SESSION_TYPES = ['ia', 'human'] as const;
5
+
6
+ // Backwards-compatible alias for session types.
7
+ export const CONVERSATION_TYPES = CONVERSATION_SESSION_TYPES;
8
+
9
+ export type ConversationTypeDto = (typeof CONVERSATION_SESSION_TYPES)[number];
10
+
11
+ // Allowed conversation message types for the `conversations` table.
12
+ // "patient" → message authored by the patient/user (WhatsApp sender).
13
+ export const CONVERSATION_MESSAGE_TYPES = ['ia', 'human', 'patient'] as const;
14
+ export type ConversationMessageTypeDto = (typeof CONVERSATION_MESSAGE_TYPES)[number];
@@ -1,5 +1,5 @@
1
1
  import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2
- import { IsInt, IsNotEmpty, IsOptional, IsString, Min } from 'class-validator';
2
+ import { IsInt, IsNotEmpty, IsOptional, IsString, IsUUID, Min } from 'class-validator';
3
3
 
4
4
  /**
5
5
  * Payload used to obtain (or create) an active 24-hour conversation session
@@ -12,11 +12,12 @@ export class CreateConversationSessionDto {
12
12
  tenant: string;
13
13
 
14
14
  @ApiProperty({
15
- description: 'Patient identifier (e.g. phone number or WhatsApp id)',
16
- example: '5511999999999',
15
+ description: 'Patient UUID',
16
+ example: '550e8400-e29b-41d4-a716-446655440000',
17
17
  })
18
18
  @IsString()
19
19
  @IsNotEmpty()
20
+ @IsUUID()
20
21
  patientId: string;
21
22
 
22
23
  @ApiPropertyOptional({ description: 'Tenant unit id', example: 1 })
@@ -8,7 +8,7 @@ import {
8
8
  IsUUID,
9
9
  Min,
10
10
  } from 'class-validator';
11
- import { CONVERSATION_TYPES, ConversationTypeDto } from './conversation-type.dto';
11
+ import { CONVERSATION_MESSAGE_TYPES, ConversationMessageTypeDto } from './conversation-type.dto';
12
12
 
13
13
  /**
14
14
  * Payload used to persist a single conversation message.
@@ -27,11 +27,12 @@ export class CreateConversationDto {
27
27
  unitId?: number;
28
28
 
29
29
  @ApiProperty({
30
- description: 'Patient identifier (e.g. phone number)',
30
+ description: 'Patient UUID',
31
31
  example: '5511999999999',
32
32
  })
33
33
  @IsString()
34
34
  @IsNotEmpty()
35
+ @IsUUID()
35
36
  patientId: string;
36
37
 
37
38
  @ApiProperty({
@@ -43,12 +44,12 @@ export class CreateConversationDto {
43
44
 
44
45
  @ApiProperty({
45
46
  description:
46
- 'Conversation type: "ia" when the AI responds to the patient, "human" when a staff member responds',
47
- enum: CONVERSATION_TYPES,
48
- example: 'ia',
47
+ 'Conversation message type: "ia" when the AI responds, "human" when staff responds, "patient" when the patient/user sends the message',
48
+ enum: CONVERSATION_MESSAGE_TYPES,
49
+ example: 'patient',
49
50
  })
50
- @IsEnum(CONVERSATION_TYPES)
51
- type: ConversationTypeDto;
51
+ @IsEnum(CONVERSATION_MESSAGE_TYPES)
52
+ type: ConversationMessageTypeDto;
52
53
 
53
54
  @ApiProperty({
54
55
  description: 'Message content',
@@ -2,4 +2,5 @@ export * from './create-patient.dto';
2
2
  export * from './update-patient.dto';
3
3
  export * from './patient-history-entry.dto';
4
4
  export * from './list-patients-query.dto';
5
+ export * from './upsert-patient-by-phone.dto';
5
6
 
@@ -0,0 +1,29 @@
1
+ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2
+ import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
3
+
4
+ /**
5
+ * Minimal patient information used to upsert a patient based on WhatsApp phone.
6
+ * Used for incoming webhook messages where we don't have CPF/birthDate yet.
7
+ */
8
+ export class UpsertPatientByPhoneDto {
9
+ @ApiProperty({
10
+ description: 'Patient phone as received from WhatsApp (local/normalized format)',
11
+ example: '5511999999999',
12
+ maxLength: 30,
13
+ })
14
+ @IsString()
15
+ @IsNotEmpty()
16
+ @MaxLength(30)
17
+ phone: string;
18
+
19
+ @ApiPropertyOptional({
20
+ description: 'WhatsApp contact display name (PushName)',
21
+ example: 'Maria Silva',
22
+ maxLength: 255,
23
+ })
24
+ @IsOptional()
25
+ @IsString()
26
+ @MaxLength(255)
27
+ pushName?: string;
28
+ }
29
+