@talkpilot/core-db 1.0.1
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.
- package/.cursor/rules/development.mdc +65 -0
- package/DEVELOPMENT.md +98 -0
- package/README.md +140 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/municipal/cities/cities.getters.d.ts +9 -0
- package/dist/municipal/cities/cities.getters.d.ts.map +1 -0
- package/dist/municipal/cities/cities.getters.js +38 -0
- package/dist/municipal/cities/cities.getters.js.map +1 -0
- package/dist/municipal/cities/cities.types.d.ts +10 -0
- package/dist/municipal/cities/cities.types.d.ts.map +1 -0
- package/dist/municipal/cities/cities.types.js +3 -0
- package/dist/municipal/cities/cities.types.js.map +1 -0
- package/dist/municipal/cities/index.d.ts +3 -0
- package/dist/municipal/cities/index.d.ts.map +1 -0
- package/dist/municipal/cities/index.js +18 -0
- package/dist/municipal/cities/index.js.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +62 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +180 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +69 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.js +3 -0
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.js.map +1 -0
- package/dist/municipal/departmentsSubjects/index.d.ts +3 -0
- package/dist/municipal/departmentsSubjects/index.d.ts.map +1 -0
- package/dist/municipal/departmentsSubjects/index.js +18 -0
- package/dist/municipal/departmentsSubjects/index.js.map +1 -0
- package/dist/municipal/index.d.ts +10 -0
- package/dist/municipal/index.d.ts.map +1 -0
- package/dist/municipal/index.js +37 -0
- package/dist/municipal/index.js.map +1 -0
- package/dist/municipal/mongodb-client.d.ts +13 -0
- package/dist/municipal/mongodb-client.d.ts.map +1 -0
- package/dist/municipal/mongodb-client.js +56 -0
- package/dist/municipal/mongodb-client.js.map +1 -0
- package/dist/municipal/streets/index.d.ts +3 -0
- package/dist/municipal/streets/index.d.ts.map +1 -0
- package/dist/municipal/streets/index.js +18 -0
- package/dist/municipal/streets/index.js.map +1 -0
- package/dist/municipal/streets/streets.getters.d.ts +21 -0
- package/dist/municipal/streets/streets.getters.d.ts.map +1 -0
- package/dist/municipal/streets/streets.getters.js +85 -0
- package/dist/municipal/streets/streets.getters.js.map +1 -0
- package/dist/municipal/streets/streets.types.d.ts +16 -0
- package/dist/municipal/streets/streets.types.d.ts.map +1 -0
- package/dist/municipal/streets/streets.types.js +3 -0
- package/dist/municipal/streets/streets.types.js.map +1 -0
- package/dist/municipal/tickets/index.d.ts +3 -0
- package/dist/municipal/tickets/index.d.ts.map +1 -0
- package/dist/municipal/tickets/index.js +18 -0
- package/dist/municipal/tickets/index.js.map +1 -0
- package/dist/municipal/tickets/tickets.getters.d.ts +44 -0
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.getters.js +199 -0
- package/dist/municipal/tickets/tickets.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts +35 -0
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.types.js +3 -0
- package/dist/municipal/tickets/tickets.types.js.map +1 -0
- package/dist/talkpilot/agents/agents.getters.d.ts +9 -0
- package/dist/talkpilot/agents/agents.getters.d.ts.map +1 -0
- package/dist/talkpilot/agents/agents.getters.js +34 -0
- package/dist/talkpilot/agents/agents.getters.js.map +1 -0
- package/dist/talkpilot/agents/agents.types.d.ts +13 -0
- package/dist/talkpilot/agents/agents.types.d.ts.map +1 -0
- package/dist/talkpilot/agents/agents.types.js +3 -0
- package/dist/talkpilot/agents/agents.types.js.map +1 -0
- package/dist/talkpilot/agents/index.d.ts +3 -0
- package/dist/talkpilot/agents/index.d.ts.map +1 -0
- package/dist/talkpilot/agents/index.js +19 -0
- package/dist/talkpilot/agents/index.js.map +1 -0
- package/dist/talkpilot/calls/calls.getters.d.ts +24 -0
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.getters.js +151 -0
- package/dist/talkpilot/calls/calls.getters.js.map +1 -0
- package/dist/talkpilot/calls/calls.types.d.ts +32 -0
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.types.js +3 -0
- package/dist/talkpilot/calls/calls.types.js.map +1 -0
- package/dist/talkpilot/calls/index.d.ts +3 -0
- package/dist/talkpilot/calls/index.d.ts.map +1 -0
- package/dist/talkpilot/calls/index.js +19 -0
- package/dist/talkpilot/calls/index.js.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +9 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +76 -0
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +23 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts.map +1 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.js +3 -0
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.js.map +1 -0
- package/dist/talkpilot/clients/clients.getters.d.ts +5 -0
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.getters.js +14 -0
- package/dist/talkpilot/clients/clients.getters.js.map +1 -0
- package/dist/talkpilot/clients/clients.types.d.ts +12 -0
- package/dist/talkpilot/clients/clients.types.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.types.js +3 -0
- package/dist/talkpilot/clients/clients.types.js.map +1 -0
- package/dist/talkpilot/clients/index.d.ts +3 -0
- package/dist/talkpilot/clients/index.d.ts.map +1 -0
- package/dist/talkpilot/clients/index.js +18 -0
- package/dist/talkpilot/clients/index.js.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +7 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +21 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +53 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js +3 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js.map +1 -0
- package/dist/talkpilot/clientsConfig/index.d.ts +3 -0
- package/dist/talkpilot/clientsConfig/index.d.ts.map +1 -0
- package/dist/talkpilot/clientsConfig/index.js +19 -0
- package/dist/talkpilot/clientsConfig/index.js.map +1 -0
- package/dist/talkpilot/flows/flows.getter.d.ts +5 -0
- package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -0
- package/dist/talkpilot/flows/flows.getter.js +13 -0
- package/dist/talkpilot/flows/flows.getter.js.map +1 -0
- package/dist/talkpilot/flows/flows.schema.d.ts +154 -0
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -0
- package/dist/talkpilot/flows/flows.schema.js +94 -0
- package/dist/talkpilot/flows/flows.schema.js.map +1 -0
- package/dist/talkpilot/flows/flows.types.d.ts +116 -0
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -0
- package/dist/talkpilot/flows/flows.types.js +3 -0
- package/dist/talkpilot/flows/flows.types.js.map +1 -0
- package/dist/talkpilot/flows/index.d.ts +3 -0
- package/dist/talkpilot/flows/index.d.ts.map +1 -0
- package/dist/talkpilot/flows/index.js +6 -0
- package/dist/talkpilot/flows/index.js.map +1 -0
- package/dist/talkpilot/groups/groups.getters.d.ts +8 -0
- package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -0
- package/dist/talkpilot/groups/groups.getters.js +26 -0
- package/dist/talkpilot/groups/groups.getters.js.map +1 -0
- package/dist/talkpilot/groups/groups.types.d.ts +26 -0
- package/dist/talkpilot/groups/groups.types.d.ts.map +1 -0
- package/dist/talkpilot/groups/groups.types.js +3 -0
- package/dist/talkpilot/groups/groups.types.js.map +1 -0
- package/dist/talkpilot/groups/index.d.ts +3 -0
- package/dist/talkpilot/groups/index.d.ts.map +1 -0
- package/dist/talkpilot/groups/index.js +19 -0
- package/dist/talkpilot/groups/index.js.map +1 -0
- package/dist/talkpilot/groups/phone.utils.d.ts +4 -0
- package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -0
- package/dist/talkpilot/groups/phone.utils.js +42 -0
- package/dist/talkpilot/groups/phone.utils.js.map +1 -0
- package/dist/talkpilot/index.d.ts +19 -0
- package/dist/talkpilot/index.d.ts.map +1 -0
- package/dist/talkpilot/index.js +46 -0
- package/dist/talkpilot/index.js.map +1 -0
- package/dist/talkpilot/leads/index.d.ts +3 -0
- package/dist/talkpilot/leads/index.d.ts.map +1 -0
- package/dist/talkpilot/leads/index.js +6 -0
- package/dist/talkpilot/leads/index.js.map +1 -0
- package/dist/talkpilot/leads/leads.getter.d.ts +4 -0
- package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -0
- package/dist/talkpilot/leads/leads.getter.js +7 -0
- package/dist/talkpilot/leads/leads.getter.js.map +1 -0
- package/dist/talkpilot/leads/leads.schema.d.ts +50 -0
- package/dist/talkpilot/leads/leads.schema.d.ts.map +1 -0
- package/dist/talkpilot/leads/leads.schema.js +37 -0
- package/dist/talkpilot/leads/leads.schema.js.map +1 -0
- package/dist/talkpilot/leads/leads.types.d.ts +18 -0
- package/dist/talkpilot/leads/leads.types.d.ts.map +1 -0
- package/dist/talkpilot/leads/leads.types.js +3 -0
- package/dist/talkpilot/leads/leads.types.js.map +1 -0
- package/dist/talkpilot/mongodb-client.d.ts +13 -0
- package/dist/talkpilot/mongodb-client.d.ts.map +1 -0
- package/dist/talkpilot/mongodb-client.js +71 -0
- package/dist/talkpilot/mongodb-client.js.map +1 -0
- package/dist/talkpilot/phone_numbers/index.d.ts +3 -0
- package/dist/talkpilot/phone_numbers/index.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/index.js +18 -0
- package/dist/talkpilot/phone_numbers/index.js.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +8 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +44 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts +29 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +18 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +16 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.js +3 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.js.map +1 -0
- package/dist/talkpilot/plans/index.d.ts +3 -0
- package/dist/talkpilot/plans/index.d.ts.map +1 -0
- package/dist/talkpilot/plans/index.js +19 -0
- package/dist/talkpilot/plans/index.js.map +1 -0
- package/dist/talkpilot/plans/plans.getters.d.ts +10 -0
- package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -0
- package/dist/talkpilot/plans/plans.getters.js +103 -0
- package/dist/talkpilot/plans/plans.getters.js.map +1 -0
- package/dist/talkpilot/plans/plans.types.d.ts +53 -0
- package/dist/talkpilot/plans/plans.types.d.ts.map +1 -0
- package/dist/talkpilot/plans/plans.types.js +29 -0
- package/dist/talkpilot/plans/plans.types.js.map +1 -0
- package/dist/talkpilot/results/index.d.ts +3 -0
- package/dist/talkpilot/results/index.d.ts.map +1 -0
- package/dist/talkpilot/results/index.js +6 -0
- package/dist/talkpilot/results/index.js.map +1 -0
- package/dist/talkpilot/results/results.getter.d.ts +7 -0
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -0
- package/dist/talkpilot/results/results.getter.js +26 -0
- package/dist/talkpilot/results/results.getter.js.map +1 -0
- package/dist/talkpilot/results/results.schema.d.ts +35 -0
- package/dist/talkpilot/results/results.schema.d.ts.map +1 -0
- package/dist/talkpilot/results/results.schema.js +29 -0
- package/dist/talkpilot/results/results.schema.js.map +1 -0
- package/dist/talkpilot/results/results.types.d.ts +34 -0
- package/dist/talkpilot/results/results.types.d.ts.map +1 -0
- package/dist/talkpilot/results/results.types.js +3 -0
- package/dist/talkpilot/results/results.types.js.map +1 -0
- package/dist/talkpilot/sessions/index.d.ts +3 -0
- package/dist/talkpilot/sessions/index.d.ts.map +1 -0
- package/dist/talkpilot/sessions/index.js +6 -0
- package/dist/talkpilot/sessions/index.js.map +1 -0
- package/dist/talkpilot/sessions/sessions.getter.d.ts +7 -0
- package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -0
- package/dist/talkpilot/sessions/sessions.getter.js +26 -0
- package/dist/talkpilot/sessions/sessions.getter.js.map +1 -0
- package/dist/talkpilot/sessions/sessions.schema.d.ts +53 -0
- package/dist/talkpilot/sessions/sessions.schema.d.ts.map +1 -0
- package/dist/talkpilot/sessions/sessions.schema.js +38 -0
- package/dist/talkpilot/sessions/sessions.schema.js.map +1 -0
- package/dist/talkpilot/sessions/sessions.types.d.ts +22 -0
- package/dist/talkpilot/sessions/sessions.types.d.ts.map +1 -0
- package/dist/talkpilot/sessions/sessions.types.js +3 -0
- package/dist/talkpilot/sessions/sessions.types.js.map +1 -0
- package/dist/talkpilot/subscriptions/index.d.ts +4 -0
- package/dist/talkpilot/subscriptions/index.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/index.js +20 -0
- package/dist/talkpilot/subscriptions/index.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +13 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.js +105 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +8 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js +27 -0
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +50 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.js +14 -0
- package/dist/talkpilot/subscriptions/subscriptions.types.js.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +4 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +20 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +1 -0
- package/dist/test-utils/db-utils.d.ts +4 -0
- package/dist/test-utils/db-utils.d.ts.map +1 -0
- package/dist/test-utils/db-utils.js +28 -0
- package/dist/test-utils/db-utils.js.map +1 -0
- package/dist/test-utils/factories/index.d.ts +13 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -0
- package/dist/test-utils/factories/index.js +29 -0
- package/dist/test-utils/factories/index.js.map +1 -0
- package/dist/test-utils/factories/municipal/cities.d.ts +5 -0
- package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/cities.js +18 -0
- package/dist/test-utils/factories/municipal/cities.js.map +1 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +5 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.js +27 -0
- package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -0
- package/dist/test-utils/factories/municipal/streets.d.ts +5 -0
- package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/streets.js +19 -0
- package/dist/test-utils/factories/municipal/streets.js.map +1 -0
- package/dist/test-utils/factories/municipal/tickets.d.ts +5 -0
- package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/tickets.js +27 -0
- package/dist/test-utils/factories/municipal/tickets.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/agents.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/agents.js +21 -0
- package/dist/test-utils/factories/talkpilot/agents.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/calls.d.ts +6 -0
- package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/calls.js +39 -0
- package/dist/test-utils/factories/talkpilot/calls.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +18 -0
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.js +18 -0
- package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/flows.d.ts +14 -0
- package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/flows.js +33 -0
- package/dist/test-utils/factories/talkpilot/flows.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/groups.d.ts +6 -0
- package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/groups.js +34 -0
- package/dist/test-utils/factories/talkpilot/groups.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +16 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.js +20 -0
- package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/sessions.d.ts +5 -0
- package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/sessions.js +37 -0
- package/dist/test-utils/factories/talkpilot/sessions.js.map +1 -0
- package/dist/utils/validation.d.ts +7 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +23 -0
- package/dist/utils/validation.js.map +1 -0
- package/jest.config.js +22 -0
- package/package.json +43 -0
- package/src/__tests__/setup.ts +20 -0
- package/src/index.ts +13 -0
- package/src/municipal/__tests__/validation.spec.ts +50 -0
- package/src/municipal/cities/cities.getters.ts +44 -0
- package/src/municipal/cities/cities.types.ts +11 -0
- package/src/municipal/cities/index.ts +2 -0
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +273 -0
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +76 -0
- package/src/municipal/departmentsSubjects/index.ts +11 -0
- package/src/municipal/index.ts +18 -0
- package/src/municipal/mongodb-client.ts +58 -0
- package/src/municipal/streets/index.ts +2 -0
- package/src/municipal/streets/streets.getters.ts +105 -0
- package/src/municipal/streets/streets.types.ts +18 -0
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -0
- package/src/municipal/tickets/index.ts +2 -0
- package/src/municipal/tickets/tickets.getters.ts +234 -0
- package/src/municipal/tickets/tickets.types.ts +39 -0
- package/src/talkpilot/__tests__/db.spec.ts +38 -0
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +19 -0
- package/src/talkpilot/__tests__/validation.spec.ts +62 -0
- package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +29 -0
- package/src/talkpilot/agents/agents.getters.ts +34 -0
- package/src/talkpilot/agents/agents.types.ts +14 -0
- package/src/talkpilot/agents/index.ts +2 -0
- package/src/talkpilot/calls/__tests__/calls.spec.ts +56 -0
- package/src/talkpilot/calls/calls.getters.ts +134 -0
- package/src/talkpilot/calls/calls.types.ts +45 -0
- package/src/talkpilot/calls/index.ts +2 -0
- package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +78 -0
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +101 -0
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +25 -0
- package/src/talkpilot/clients/clients.getters.ts +11 -0
- package/src/talkpilot/clients/clients.types.ts +12 -0
- package/src/talkpilot/clients/index.ts +2 -0
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +28 -0
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +20 -0
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +55 -0
- package/src/talkpilot/clientsConfig/index.ts +2 -0
- package/src/talkpilot/flows/flows.getter.ts +11 -0
- package/src/talkpilot/flows/flows.schema.ts +90 -0
- package/src/talkpilot/flows/flows.types.ts +151 -0
- package/src/talkpilot/flows/index.ts +2 -0
- package/src/talkpilot/groups/__tests__/groups.spec.ts +83 -0
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +32 -0
- package/src/talkpilot/groups/groups.getters.ts +27 -0
- package/src/talkpilot/groups/groups.types.ts +29 -0
- package/src/talkpilot/groups/index.ts +2 -0
- package/src/talkpilot/groups/phone.utils.ts +40 -0
- package/src/talkpilot/index.ts +27 -0
- package/src/talkpilot/leads/index.ts +2 -0
- package/src/talkpilot/leads/leads.getter.ts +5 -0
- package/src/talkpilot/leads/leads.schema.ts +33 -0
- package/src/talkpilot/leads/leads.types.ts +20 -0
- package/src/talkpilot/mongodb-client.ts +78 -0
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +43 -0
- package/src/talkpilot/phone_numbers/index.ts +2 -0
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +47 -0
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +14 -0
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +15 -0
- package/src/talkpilot/plans/index.ts +2 -0
- package/src/talkpilot/plans/plans.getters.ts +121 -0
- package/src/talkpilot/plans/plans.types.ts +84 -0
- package/src/talkpilot/results/index.ts +2 -0
- package/src/talkpilot/results/results.getter.ts +26 -0
- package/src/talkpilot/results/results.schema.ts +25 -0
- package/src/talkpilot/results/results.types.ts +32 -0
- package/src/talkpilot/sessions/__tests__/sessions.spec.ts +43 -0
- package/src/talkpilot/sessions/index.ts +2 -0
- package/src/talkpilot/sessions/sessions.getter.ts +28 -0
- package/src/talkpilot/sessions/sessions.schema.ts +34 -0
- package/src/talkpilot/sessions/sessions.types.ts +28 -0
- package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +42 -0
- package/src/talkpilot/subscriptions/index.ts +3 -0
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +147 -0
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +26 -0
- package/src/talkpilot/subscriptions/subscriptions.types.ts +65 -0
- package/src/test-utils/db-utils.ts +24 -0
- package/src/test-utils/factories/index.ts +12 -0
- package/src/test-utils/factories/municipal/cities.ts +16 -0
- package/src/test-utils/factories/municipal/departmentsSubjects.ts +29 -0
- package/src/test-utils/factories/municipal/streets.ts +17 -0
- package/src/test-utils/factories/municipal/tickets.ts +27 -0
- package/src/test-utils/factories/talkpilot/agents.ts +19 -0
- package/src/test-utils/factories/talkpilot/calls.ts +37 -0
- package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +18 -0
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +19 -0
- package/src/test-utils/factories/talkpilot/flows.ts +31 -0
- package/src/test-utils/factories/talkpilot/groups.ts +33 -0
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +20 -0
- package/src/test-utils/factories/talkpilot/sessions.ts +35 -0
- package/src/utils/validation.ts +23 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ObjectId, WithId } from 'mongodb';
|
|
2
|
+
import { TranscriptionSegment } from '../results/results.types';
|
|
3
|
+
|
|
4
|
+
export type Call = {
|
|
5
|
+
callSid: string;
|
|
6
|
+
flowId: ObjectId;
|
|
7
|
+
clientId: string;
|
|
8
|
+
sessionId: ObjectId | null;
|
|
9
|
+
runId?: string;
|
|
10
|
+
resultId: ObjectId;
|
|
11
|
+
customerPhoneNumber: string;
|
|
12
|
+
agentPhoneNumber: string;
|
|
13
|
+
isIncomingCall: boolean;
|
|
14
|
+
isOutgoingCall: boolean;
|
|
15
|
+
callLength: number;
|
|
16
|
+
transcription?: TranscriptionSegment[];
|
|
17
|
+
status?: string;
|
|
18
|
+
leads?: Record<string, string>[];
|
|
19
|
+
summary?: string;
|
|
20
|
+
recordingUrl?: string;
|
|
21
|
+
env: string;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
createdAt: Date;
|
|
24
|
+
agentHungUp?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ImmutableCallFields =
|
|
28
|
+
| 'customerPhoneNumber'
|
|
29
|
+
| 'agentPhoneNumber'
|
|
30
|
+
| 'isIncomingCall'
|
|
31
|
+
| 'isOutgoingCall'
|
|
32
|
+
| 'sessionId'
|
|
33
|
+
| 'callSid'
|
|
34
|
+
| 'flowId'
|
|
35
|
+
| 'clientId'
|
|
36
|
+
| 'runId'
|
|
37
|
+
| 'resultId'
|
|
38
|
+
| 'env'
|
|
39
|
+
| 'createdAt';
|
|
40
|
+
|
|
41
|
+
export type CallUpdateParams = Partial<Omit<Call, ImmutableCallFields>>;
|
|
42
|
+
|
|
43
|
+
export type CallDoc = WithId<Call>;
|
|
44
|
+
|
|
45
|
+
export type CallsByHour = { hour: string; calls: number };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getClientAudioBuffersCollection,
|
|
3
|
+
insertClientAudioBuffer,
|
|
4
|
+
findClientAudioBuffersByCallSidAndRange,
|
|
5
|
+
getMergedAudioByCallSid,
|
|
6
|
+
} from '../clientAudioBuffer.getters';
|
|
7
|
+
import { ObjectId } from 'mongodb';
|
|
8
|
+
import { createAudioBufferInput } from '../../../test-utils/factories';
|
|
9
|
+
|
|
10
|
+
describe('clientAudioBuffers getters', () => {
|
|
11
|
+
it('should return the "clientAudioBuffers" collection', () => {
|
|
12
|
+
const collection = getClientAudioBuffersCollection();
|
|
13
|
+
expect(collection.collectionName).toBe('clientAudioBuffers');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should insert a client audio buffer and return insertedId', async () => {
|
|
17
|
+
const inputToCheck = createAudioBufferInput();
|
|
18
|
+
const result = await insertClientAudioBuffer(inputToCheck);
|
|
19
|
+
expect(result.insertedId).toBeInstanceOf(ObjectId);
|
|
20
|
+
|
|
21
|
+
const savedDoc = await getClientAudioBuffersCollection().findOne({ _id: result.insertedId });
|
|
22
|
+
expect(savedDoc).toBeDefined();
|
|
23
|
+
expect(savedDoc?.createdAt).toBeInstanceOf(Date);
|
|
24
|
+
expect(savedDoc?.expiresAt).toBeInstanceOf(Date);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should return only buffers in the specified bucketStartMs range', async () => {
|
|
28
|
+
const callSid = 'CA1234567890abcdef1234567890abcdef';
|
|
29
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 500 }));
|
|
30
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 1000 }));
|
|
31
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 3000 }));
|
|
32
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 6000 }));
|
|
33
|
+
|
|
34
|
+
const result = await findClientAudioBuffersByCallSidAndRange(callSid, 500, 3000);
|
|
35
|
+
expect(result).toHaveLength(3);
|
|
36
|
+
const bucketStartValues = result.map((doc) => doc.bucketStartMs);
|
|
37
|
+
const bucketStartsSorted = bucketStartValues.sort((a, b) => a - b);
|
|
38
|
+
expect(bucketStartsSorted).toEqual([500, 1000, 3000]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return all buffers when no range is provided', async () => {
|
|
42
|
+
const callSid = 'CA1234567890abcdef1234567890abcdeg';
|
|
43
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 500 }));
|
|
44
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 1000 }));
|
|
45
|
+
await insertClientAudioBuffer(createAudioBufferInput({ callSid, bucketStartMs: 3000 }));
|
|
46
|
+
|
|
47
|
+
const result = await findClientAudioBuffersByCallSidAndRange(callSid);
|
|
48
|
+
expect(result).toHaveLength(3);
|
|
49
|
+
const bucketStartValues = result.map((doc) => doc.bucketStartMs);
|
|
50
|
+
const bucketStartsSorted = bucketStartValues.sort((a, b) => a - b);
|
|
51
|
+
expect(bucketStartsSorted).toEqual([500, 1000, 3000]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should merge audio buffers by callSid in chronological order', async () => {
|
|
55
|
+
const callSid = 'CA1234567890abcdef1234567890abcdeh';
|
|
56
|
+
|
|
57
|
+
const firstBuffer = Buffer.from([1, 2]);
|
|
58
|
+
const secondBuffer = Buffer.from([3]);
|
|
59
|
+
const thirdBuffer = Buffer.from([4, 5]);
|
|
60
|
+
|
|
61
|
+
await insertClientAudioBuffer(
|
|
62
|
+
createAudioBufferInput({ callSid, bucketStartMs: 1000, data: secondBuffer })
|
|
63
|
+
);
|
|
64
|
+
await insertClientAudioBuffer(
|
|
65
|
+
createAudioBufferInput({ callSid, bucketStartMs: 500, data: firstBuffer })
|
|
66
|
+
);
|
|
67
|
+
await insertClientAudioBuffer(
|
|
68
|
+
createAudioBufferInput({ callSid, bucketStartMs: 3000, data: thirdBuffer })
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const merged = await getMergedAudioByCallSid(callSid);
|
|
72
|
+
const expected = Buffer.concat([firstBuffer, secondBuffer, thirdBuffer]);
|
|
73
|
+
|
|
74
|
+
expect(merged).toBeInstanceOf(Buffer);
|
|
75
|
+
expect(merged.length).toBe(expected.length);
|
|
76
|
+
expect(merged.equals(expected)).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { getDb } from '@core/db';
|
|
2
|
+
import {
|
|
3
|
+
ClientAudioBufferDoc,
|
|
4
|
+
ClientAudioBufferType,
|
|
5
|
+
CreateAudioBufferInput,
|
|
6
|
+
} from './clientsAudioBuffers.types';
|
|
7
|
+
import { Collection, InsertOneResult } from 'mongodb';
|
|
8
|
+
|
|
9
|
+
const getClientAudioBuffersCollection = (): Collection<ClientAudioBufferType> => {
|
|
10
|
+
return getDb().collection<ClientAudioBufferType>('clientAudioBuffers');
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const insertClientAudioBuffer = async (
|
|
14
|
+
audioBufferInput: CreateAudioBufferInput
|
|
15
|
+
): Promise<InsertOneResult<ClientAudioBufferType>> => {
|
|
16
|
+
const collection = getClientAudioBuffersCollection();
|
|
17
|
+
const realtimeDate = new Date();
|
|
18
|
+
const ttlMs = audioBufferInput.ttlMs ?? 3600_000;
|
|
19
|
+
const expiresAt = new Date(realtimeDate.getTime() + ttlMs);
|
|
20
|
+
|
|
21
|
+
const inputFieldsForDocument = {
|
|
22
|
+
callSid: audioBufferInput.callSid,
|
|
23
|
+
clientId: audioBufferInput.clientId,
|
|
24
|
+
bucketStartMs: audioBufferInput.bucketStartMs,
|
|
25
|
+
bucketDurationMs: audioBufferInput.bucketDurationMs,
|
|
26
|
+
data: audioBufferInput.data,
|
|
27
|
+
};
|
|
28
|
+
const clientAudioBufferMongoDocument: ClientAudioBufferType = {
|
|
29
|
+
...inputFieldsForDocument,
|
|
30
|
+
codec: 'mulaw',
|
|
31
|
+
sampleRateHz: 8000,
|
|
32
|
+
channels: 1,
|
|
33
|
+
createdAt: realtimeDate,
|
|
34
|
+
expiresAt: expiresAt,
|
|
35
|
+
};
|
|
36
|
+
return collection.insertOne(clientAudioBufferMongoDocument);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const findClientAudioBuffersByCallSidAndRange = async (
|
|
40
|
+
callSid: string,
|
|
41
|
+
startMs?: number,
|
|
42
|
+
endMs?: number
|
|
43
|
+
): Promise<ClientAudioBufferDoc[]> => {
|
|
44
|
+
const collection = getClientAudioBuffersCollection();
|
|
45
|
+
if (startMs === undefined) {
|
|
46
|
+
return collection.find({ callSid }).toArray();
|
|
47
|
+
}
|
|
48
|
+
const endMsToUse = endMs ?? Date.now();
|
|
49
|
+
return collection
|
|
50
|
+
.find({
|
|
51
|
+
callSid,
|
|
52
|
+
bucketStartMs: {
|
|
53
|
+
$gte: startMs,
|
|
54
|
+
$lte: endMsToUse,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
.toArray();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const getAudioChunksByCallSid = async (callSid: string): Promise<Buffer[]> => {
|
|
61
|
+
const collection = getClientAudioBuffersCollection();
|
|
62
|
+
const chunks = await collection.find({ callSid }).toArray();
|
|
63
|
+
|
|
64
|
+
if (!chunks.length) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
chunks.sort((a: any, b: any) => a.bucketStartMs - b.bucketStartMs);
|
|
69
|
+
|
|
70
|
+
return chunks.map((chunk: any) => {
|
|
71
|
+
const data: any = chunk.data;
|
|
72
|
+
|
|
73
|
+
if (Buffer.isBuffer(data)) {
|
|
74
|
+
return data;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (data?.buffer) {
|
|
78
|
+
return Buffer.from(data.buffer);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return Buffer.from(data);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const getMergedAudioByCallSid = async (callSid: string): Promise<Buffer> => {
|
|
86
|
+
const buffers = await getAudioChunksByCallSid(callSid);
|
|
87
|
+
|
|
88
|
+
if (!buffers.length) {
|
|
89
|
+
return Buffer.alloc(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Buffer.concat(buffers);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
insertClientAudioBuffer,
|
|
97
|
+
getClientAudioBuffersCollection,
|
|
98
|
+
findClientAudioBuffersByCallSidAndRange,
|
|
99
|
+
getAudioChunksByCallSid,
|
|
100
|
+
getMergedAudioByCallSid,
|
|
101
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WithId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
export type ClientAudioBufferType = {
|
|
4
|
+
callSid: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
bucketStartMs: number;
|
|
7
|
+
bucketDurationMs: number;
|
|
8
|
+
codec: 'mulaw';
|
|
9
|
+
sampleRateHz: 8000;
|
|
10
|
+
channels: 1;
|
|
11
|
+
data: Buffer;
|
|
12
|
+
expiresAt: Date;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type CreateAudioBufferInput = {
|
|
17
|
+
callSid: string;
|
|
18
|
+
clientId: string;
|
|
19
|
+
bucketStartMs: number;
|
|
20
|
+
bucketDurationMs: number;
|
|
21
|
+
data: Buffer;
|
|
22
|
+
ttlMs?: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type ClientAudioBufferDoc = WithId<ClientAudioBufferType>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getDb, Client } from '../index';
|
|
2
|
+
import { Collection } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
export const getClientsCollection = (): Collection<Client> => {
|
|
5
|
+
return getDb().collection<Client>('clients');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const getClientByAPIKey = async (apiKey: string): Promise<Client | null> => {
|
|
9
|
+
const client = await getClientsCollection().findOne({ apiKey, isActive: true });
|
|
10
|
+
return client ? client : null;
|
|
11
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createClientConfigDoc, getClientConfig } from '../clientsConfig.getters';
|
|
2
|
+
import { createClientConfig } from '../../../test-utils/factories';
|
|
3
|
+
|
|
4
|
+
describe('db.clientsConfig', () => {
|
|
5
|
+
describe('getClientConfig', () => {
|
|
6
|
+
it('should return client config by clientId', async () => {
|
|
7
|
+
const clientId = 'test-client-id';
|
|
8
|
+
const clientConfig = createClientConfig({
|
|
9
|
+
clientId,
|
|
10
|
+
products: { feature1: true, feature2: false } as any,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
await createClientConfigDoc(clientConfig);
|
|
14
|
+
|
|
15
|
+
const result = await getClientConfig(clientId);
|
|
16
|
+
|
|
17
|
+
expect(result).toMatchObject({
|
|
18
|
+
clientId,
|
|
19
|
+
products: { feature1: true, feature2: false },
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return null for non-existent clientId', async () => {
|
|
24
|
+
const result = await getClientConfig('non-existent-client');
|
|
25
|
+
expect(result).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ClientConfigDoc, getDb } from '../index';
|
|
2
|
+
import { Collection } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
export const getClientsConfigCollection = (): Collection<ClientConfigDoc> => {
|
|
5
|
+
return getDb().collection('clientsConfig');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const getClientConfig = (clientId: string) => {
|
|
9
|
+
return getClientsConfigCollection().findOne({ clientId });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getClientConfigByPhone = async (
|
|
13
|
+
phoneNumber: string
|
|
14
|
+
): Promise<ClientConfigDoc | null> => {
|
|
15
|
+
return getClientsConfigCollection().findOne({ phoneNumber });
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const createClientConfigDoc = async (clientConfig: ClientConfigDoc): Promise<void> => {
|
|
19
|
+
await getClientsConfigCollection().insertOne(clientConfig);
|
|
20
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WithId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for initiating a call for short SLA
|
|
5
|
+
*/
|
|
6
|
+
export type InitiateCallForShortSlaConfig = {
|
|
7
|
+
active: boolean;
|
|
8
|
+
max_hours: number;
|
|
9
|
+
contacts?: { name: string; phoneNumber: string }[];
|
|
10
|
+
flow_id?: string | string[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Moked 106 configuration structure
|
|
15
|
+
*/
|
|
16
|
+
export type Moked106Config = {
|
|
17
|
+
initiate_call_for_short_sla?: InitiateCallForShortSlaConfig;
|
|
18
|
+
avoidSaveTickets?: boolean;
|
|
19
|
+
withUploadImagesSms?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Municipal products structure
|
|
24
|
+
*/
|
|
25
|
+
export type MunicipalProduct = {
|
|
26
|
+
moked_106?: Moked106Config;
|
|
27
|
+
cityName: string;
|
|
28
|
+
crmName?: string;
|
|
29
|
+
cityDisplayName?: string;
|
|
30
|
+
cityLogoURL?: string;
|
|
31
|
+
timezone: string;
|
|
32
|
+
websiteUrl?: string;
|
|
33
|
+
isProductionReady?: boolean;
|
|
34
|
+
municipalDisplayName?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Products structure
|
|
39
|
+
*/
|
|
40
|
+
export type Products = {
|
|
41
|
+
municipal?: MunicipalProduct;
|
|
42
|
+
[key: string]: unknown; // Allow other products
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Client configuration type
|
|
47
|
+
* @template P - Products type (defaults to Products for type safety)
|
|
48
|
+
*/
|
|
49
|
+
export type ClientConfig<P extends Products = Products> = {
|
|
50
|
+
clientId: string;
|
|
51
|
+
phoneNumber?: string;
|
|
52
|
+
products: P;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type ClientConfigDoc<P extends Products = Products> = WithId<ClientConfig<P>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Collection, ObjectId, WithId } from 'mongodb';
|
|
2
|
+
import { getDb } from '../index';
|
|
3
|
+
import type { Flow } from './flows.types';
|
|
4
|
+
|
|
5
|
+
export const getFlowsCollection = (): Collection<Flow> => {
|
|
6
|
+
return getDb().collection<Flow>('flows');
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const findFlowById = (flowId: ObjectId, clientId: string): Promise<WithId<Flow> | null> => {
|
|
10
|
+
return getFlowsCollection().findOne({ _id: flowId, clientId });
|
|
11
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export const flowMongoSchema = {
|
|
2
|
+
bsonType: 'object',
|
|
3
|
+
required: ['flowName', 'systemInstructions', 'initialSentence', 'interactions'],
|
|
4
|
+
properties: {
|
|
5
|
+
_id: { bsonType: 'objectId' },
|
|
6
|
+
flowName: { bsonType: 'string' },
|
|
7
|
+
clientId: { bsonType: 'string' },
|
|
8
|
+
systemInstructions: { bsonType: 'string' },
|
|
9
|
+
initialSentence: { bsonType: 'string' },
|
|
10
|
+
voice: { bsonType: ['string', 'null'] },
|
|
11
|
+
interactions: {
|
|
12
|
+
bsonType: 'array',
|
|
13
|
+
items: {
|
|
14
|
+
bsonType: 'object',
|
|
15
|
+
required: ['id', 'type', 'text', 'position'],
|
|
16
|
+
properties: {
|
|
17
|
+
id: { bsonType: 'string' },
|
|
18
|
+
type: { bsonType: 'string' },
|
|
19
|
+
text: { bsonType: 'string' },
|
|
20
|
+
successStatus: { bsonType: ['string', 'null'] },
|
|
21
|
+
conditions: {
|
|
22
|
+
bsonType: ['array', 'null'],
|
|
23
|
+
items: {
|
|
24
|
+
bsonType: 'object',
|
|
25
|
+
required: ['conditionString'],
|
|
26
|
+
properties: {
|
|
27
|
+
conditionString: { bsonType: 'string' },
|
|
28
|
+
nodeType: { bsonType: ['string', 'null'] },
|
|
29
|
+
id: { bsonType: ['string', 'null'] },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultNodeType: { bsonType: ['string', 'null'] },
|
|
34
|
+
defaultChild: {
|
|
35
|
+
bsonType: ['object', 'null'],
|
|
36
|
+
properties: { id: { bsonType: 'string' } },
|
|
37
|
+
},
|
|
38
|
+
position: {
|
|
39
|
+
bsonType: 'object',
|
|
40
|
+
required: ['x', 'y'],
|
|
41
|
+
properties: {
|
|
42
|
+
x: { bsonType: 'number' },
|
|
43
|
+
y: { bsonType: 'number' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
name: { bsonType: ['string', 'null'] },
|
|
47
|
+
children: { bsonType: ['array', 'null'], items: { bsonType: 'string' } },
|
|
48
|
+
resultsLabel: { bsonType: ['string', 'null'] },
|
|
49
|
+
resultsColor: { bsonType: ['string', 'null'] },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
edges: {
|
|
54
|
+
bsonType: ['array', 'null'],
|
|
55
|
+
items: {
|
|
56
|
+
bsonType: 'object',
|
|
57
|
+
required: ['id', 'source', 'target'],
|
|
58
|
+
properties: {
|
|
59
|
+
id: { bsonType: 'string' },
|
|
60
|
+
source: { bsonType: 'string' },
|
|
61
|
+
target: { bsonType: 'string' },
|
|
62
|
+
label: { bsonType: ['string', 'null'] },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
metaKeys: {
|
|
67
|
+
bsonType: ['array', 'null'],
|
|
68
|
+
items: {
|
|
69
|
+
bsonType: 'object',
|
|
70
|
+
required: ['key'],
|
|
71
|
+
properties: {
|
|
72
|
+
key: { bsonType: 'string' },
|
|
73
|
+
required: { bsonType: 'bool' },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
userProperties: {
|
|
78
|
+
bsonType: ['array', 'null'],
|
|
79
|
+
items: {
|
|
80
|
+
bsonType: 'object',
|
|
81
|
+
required: ['name', 'description'],
|
|
82
|
+
properties: {
|
|
83
|
+
name: { bsonType: 'string' },
|
|
84
|
+
description: { bsonType: 'string' },
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
} as const;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
/* ---------- Basic helpers ---------- */
|
|
4
|
+
|
|
5
|
+
export type Position = { x: number; y: number };
|
|
6
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
7
|
+
|
|
8
|
+
export type QuestionType = 'open' | 'multiple' | 'table';
|
|
9
|
+
export type SelectionType = 'single' | 'multiple';
|
|
10
|
+
|
|
11
|
+
export type Question = {
|
|
12
|
+
id: string;
|
|
13
|
+
type: QuestionType;
|
|
14
|
+
text: string;
|
|
15
|
+
repeatAnswer?: boolean;
|
|
16
|
+
// For 'multiple' type questions:
|
|
17
|
+
answers?: string[] | null;
|
|
18
|
+
selectionType?: SelectionType | null; // 'single' = choose one, 'multiple' = choose one or more
|
|
19
|
+
// For 'table' type questions:
|
|
20
|
+
tableHeader?: string | null;
|
|
21
|
+
tableRows?: string[] | null;
|
|
22
|
+
tableColumns?: string[] | null; // These are the answer options shared across all rows
|
|
23
|
+
// Note: 'table' questions can also have selectionType to indicate if each row allows single or multiple selections
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type NodeKind =
|
|
27
|
+
| 'start'
|
|
28
|
+
| 'say'
|
|
29
|
+
| 'condition'
|
|
30
|
+
| 'improvise'
|
|
31
|
+
| 'tool'
|
|
32
|
+
| 'sendMessage'
|
|
33
|
+
| 'questionsList'
|
|
34
|
+
| 'end';
|
|
35
|
+
type BaseNode = {
|
|
36
|
+
id: string;
|
|
37
|
+
type: NodeKind;
|
|
38
|
+
text: string;
|
|
39
|
+
|
|
40
|
+
name?: string | null;
|
|
41
|
+
position: Position;
|
|
42
|
+
children?: string[] | null;
|
|
43
|
+
successStatus?: string | null;
|
|
44
|
+
questions?: Question[] | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type StartNode = BaseNode & { type: 'start' };
|
|
48
|
+
|
|
49
|
+
export type SayNode = BaseNode & { type: 'say' };
|
|
50
|
+
|
|
51
|
+
export type ConditionNode = BaseNode & {
|
|
52
|
+
type: 'condition';
|
|
53
|
+
conditions: Array<{
|
|
54
|
+
conditionString: string;
|
|
55
|
+
nodeType?: string | null;
|
|
56
|
+
id?: string | null;
|
|
57
|
+
}>;
|
|
58
|
+
defaultNodeType?: string | null;
|
|
59
|
+
defaultChild?: { id?: string } | null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type ImproviseNode = BaseNode & { type: 'improvise' };
|
|
63
|
+
|
|
64
|
+
export type FlowTool = {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
url: string;
|
|
69
|
+
method: HttpMethod;
|
|
70
|
+
headers?: Record<string, string>;
|
|
71
|
+
parameters: Record<string, unknown>;
|
|
72
|
+
bodyFormat?: 'json' | 'form-data';
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type SendMethod = 'sms' | 'whatsapp';
|
|
76
|
+
|
|
77
|
+
export type SendMessageNode = BaseNode & {
|
|
78
|
+
type: 'sendMessage';
|
|
79
|
+
/** Which channel to use. If omitted, decide at runtime (e.g., default to whatsapp). */
|
|
80
|
+
send_method: SendMethod;
|
|
81
|
+
/** Destination phone (E.164 or templated string like "{{userPhone}}"). */
|
|
82
|
+
phone_number: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type ToolNode = BaseNode & {
|
|
86
|
+
type: 'tool';
|
|
87
|
+
name: string;
|
|
88
|
+
text: string;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type QuestionsListNode = BaseNode & {
|
|
92
|
+
type: 'questionsList';
|
|
93
|
+
questions: Question[];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type EndNode = BaseNode & { type: 'end' };
|
|
97
|
+
|
|
98
|
+
export type Interaction =
|
|
99
|
+
| StartNode
|
|
100
|
+
| SayNode
|
|
101
|
+
| ConditionNode
|
|
102
|
+
| ImproviseNode
|
|
103
|
+
| ToolNode
|
|
104
|
+
| SendMessageNode
|
|
105
|
+
| QuestionsListNode
|
|
106
|
+
| EndNode;
|
|
107
|
+
|
|
108
|
+
export type Edge = {
|
|
109
|
+
id: string;
|
|
110
|
+
source: string;
|
|
111
|
+
target: string;
|
|
112
|
+
label?: string | null;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export type MetaKey = {
|
|
116
|
+
key: string;
|
|
117
|
+
required?: boolean;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type UserProperty = {
|
|
121
|
+
name: string;
|
|
122
|
+
description: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/* ---------- The Flow object ---------- */
|
|
126
|
+
|
|
127
|
+
export type Flow = {
|
|
128
|
+
freeTextContent?: string;
|
|
129
|
+
isFreeText?: boolean;
|
|
130
|
+
_id?: ObjectId;
|
|
131
|
+
|
|
132
|
+
flowName: string;
|
|
133
|
+
clientId: string;
|
|
134
|
+
|
|
135
|
+
systemInstructions: string;
|
|
136
|
+
initialSentence: string;
|
|
137
|
+
voice?: string;
|
|
138
|
+
|
|
139
|
+
insights: string[];
|
|
140
|
+
|
|
141
|
+
interactions: Interaction[];
|
|
142
|
+
|
|
143
|
+
edges?: Edge[] | null;
|
|
144
|
+
metaKeys?: MetaKey[] | null;
|
|
145
|
+
userProperties?: UserProperty[] | null;
|
|
146
|
+
tools?: FlowTool[];
|
|
147
|
+
|
|
148
|
+
// Timestamps
|
|
149
|
+
createdAt?: Date;
|
|
150
|
+
updatedAt?: Date;
|
|
151
|
+
};
|