Skip to main content

Calls Module Documentation - EML Backend

1. Introduction

The Calls module in EML Backend manages call interactions between customers and service agents. It supports real-time calls, recordings, and performance metrics.


2. Code Structure

modules/calls/
├── calls.module.ts # Module definition
├── calls.controller.ts # HTTP Controller for call requests
├── calls.service.ts # Business logic for calls
├── calls.gateway.ts # WebSockets for real-time calls
├── calls.repository.ts # Database access
├── dto/ # Data Transfer Objects (DTOs)
│ ├── start-call.dto.ts
│ ├── end-call.dto.ts
├── entities/ # Database models
│ ├── call.entity.ts

3. Available Endpoints

3.1 Start Call

POST /calls/start - Initiates a new call between a client and an agent.

Request Example:

curl -X POST http://localhost:3000/calls/start      -H "Content-Type: application/json"      -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."      -d '{"clientId": "12345", "agentId": "67890"}'

Response Example:

{
"callId": "abc123",
"clientId": "12345",
"agentId": "67890",
"status": "in-progress"
}

3.2 End Call

POST /calls/end - Ends an active call and stores its details.

Request Example:

curl -X POST http://localhost:3000/calls/end      -H "Content-Type: application/json"      -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."      -d '{"callId": "abc123"}'

Response Example:

{
"callId": "abc123",
"status": "completed",
"duration": 320
}

3.3 Get Call History

GET /calls/history - Retrieves the call history of a user.

Request Example:

curl -X GET http://localhost:3000/calls/history?userId=12345      -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."

Response Example:

[
{
"callId": "abc123",
"clientId": "12345",
"agentId": "67890",
"status": "completed",
"duration": 320,
"timestamp": "2025-03-03T12:34:56Z"
}
]

3.4 WebSockets: Real-Time Call Status

The module allows real-time updates on call status using WebSockets.

Example WebSockets Connection:

const socket = io('http://localhost:3000');
socket.on('connect', () => {
console.log('Connected to the calls server');
});
socket.on('callUpdate', (data) => {
console.log('Call status updated:', data);
});

4. Security and Middleware

  • JWT Authentication: All requests require a valid JWT token.
  • Agent Restrictions: Only authorized agents can accept calls.
  • Call Recording: A log of each call is stored.

Example of middleware for protection:

@UseGuards(AuthGuard('jwt'))
@Post('start')
async startCall(@Body() callDto: StartCallDto) {
return this.callService.startCall(callDto);
}

5. Dependencies with Other Modules

  • Users: To identify clients and agents.
  • Messages: To notify about call status.
  • Reports: To generate statistics on handled calls.

6. Additional Notes

  • Plans to implement call recording support and voice analysis.
  • Considering integration with VoIP providers for external calls.

7. Conclusion

The Calls module in EML Backend enables efficient communication management within the platform, ensuring seamless interaction between clients and agents.

🚀 This document will be updated as the system evolves.