Inbound
Here is an architectural overview of the Inbound Service.
Here's a high-level overview documentation for your NestJS service:
Overview
Inbound service provides UCI with inbound and outbound messaging capabilities, user history tracking, and telemetry reporting. The service is designed for robust handling of bot interactions, facilitating both message processing and user feedback integration.
Features
1. Inbound Message Processing
- Receives incoming messages and maps them to the appropriate bot and adapter.
- Processes bot-specific configurations and adapts messages to XMessage format.
- Supports message transformations and sends acknowledgments, feedback, and error messages.
2. Outbound Message Processing
- Sends messages through various channels, such as SMS, email, and whatsapp.
- Supports diverse adapter types (e.g., SMS, chat, email) for flexible message delivery.
- Integrates credentials stored in Hashicorp Vault for secure communication with external APIs.
3. User History Tracking
- Stores and retrieves user messages, enabling a historical view of conversations.
- Provides pagination and filtering options for retrieving user conversations based on bot, tags, and conversation IDs.
- Records feedback provided by users on messages, storing it alongside message history.
4. Telemetry Integration
- Logs telemetry events for incoming and outgoing messages, user feedback, and history tracking.
- Sends event data to a configured telemetry service for monitoring and analytics.
- Supports configurable environments and actor IDs for detailed event data.
5. Health Check
- Provides an endpoint to verify the service status and availability.
Use Cases
Bot Message Processing
- The service is utilized to handle incoming bot messages and translate them into a standardized format for further processing by orchestrator.
User History Access
- Enables tracking of user interactions with a bot, providing insights into user behavior and conversation flow.
Feedback Collection
- Captures user feedback on specific messages, allowing bot administrators to analyze and improve user experience.
Multi-Channel Message Delivery
- Sends outbound messages through various communication channels based on user preference or system configuration.
Telemetry Logging
- Logs events related to bot interactions and user feedback, providing valuable data for monitoring and debugging.
Asynchronous Message Handling with RabbitMQ
- Manages message loads efficiently by queuing incoming requests, enabling asynchronous processing for improved performance.
Implementation Stack
- Framework: NestJS
- Database: Prisma with PostgreSQL for storing user messages and feedback.
- HTTP Client: Axios for making API requests to external services.
- Configuration: @nestjs/config for environment-based configurations.
- Telemetry: Custom telemetry service for logging event data.
- Event Bus: RabbitMQ
- Adapters and Message Handling:
- @samagra-x/xmessage: Handles message transformations.
- @samagra-x/uci-adapters-factory: Provides different adapter types for multi-channel message delivery.
Code Structure
app.module.ts
Main application module, importing essential modules such as:
MessageModule
for message handlingHealthModule
for service health checks- Configuration and other service controllers
message/model/xmessage.model.ts
Defines the XMessageModel
interface for standardized message handling, including attributes like messageType
, to
, from
, channelURI
, and payload
.
message/controllers/inbound/inbound.bot.controller.ts
Handles inbound bot messages. Verifies bot existence and processes incoming data by calling the InboundService
.
message/controllers/outbound/outbound.controller.ts
Manages outbound message requests, handles message states, and calls OutboundService
to send messages through configured channels.
message/controllers/userhistory/userhistory.controller.ts
Provides endpoints for user history:
getUserHistory
: Retrieves user conversation history.getUserConversations
: Retrieves paginated user conversations.getUserFeedbacks
: Fetches user feedback on messages.getByTags
: Allows fetching of messages by specific tags.
message/services
InboundService
: Processes inbound messages, adapts them to XMessage format, and sends feedback as needed.OutboundService
: Sends outgoing messages to configured adapters.UserHistoryService
: Manages user message storage, retrieval, and feedback recording.TelemetryService
: Sends telemetry data to a telemetry service.CredentialService
: Retrieves and manages credentials required for bot adapters.
telemetry.types.ts
Defines data structures for telemetry events, including TelemetryEventData
, FeedbackEventData
, and UserHistoryEventData
.
Running the Service
To run the service, configure the environment variables as required, and use the following command:
npm run start