Integrate Notification Service into Tender Management System
- Added a new notification service to handle various notification types (email, SMS, push, OTP). - Implemented configuration for the notification service, allowing customization via environment variables. - Updated user and customer services to utilize the notification service for sending welcome emails and status updates. - Introduced a builder pattern for constructing notification requests, enhancing usability and flexibility. - Enhanced error handling and logging for notification operations, ensuring robust service integration. - Updated documentation to include usage examples and configuration details for the new notification SDK.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
# Notification SDK - Quick Usage Guide
|
||||
|
||||
## Installation
|
||||
The SDK is already part of your `tm` module. Import it as:
|
||||
```go
|
||||
import "tm/pkg/notification"
|
||||
```
|
||||
|
||||
## Basic Setup
|
||||
```go
|
||||
// 1. Configuration
|
||||
config := notification.DefaultConfig()
|
||||
config.BaseURL = "http://127.0.0.1:9095" // Your notification service URL
|
||||
|
||||
// 2. Logger (using project's logger)
|
||||
loggerConfig := &logger.Config{Level: "info", Format: "json", Output: "stdout"}
|
||||
projectLogger := logger.NewLogger(loggerConfig)
|
||||
loggerAdapter := ¬ification.LoggerAdapter{Logger: projectLogger}
|
||||
|
||||
// 3. Create SDK
|
||||
sdk, err := notification.NewSDK(config, loggerAdapter)
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
```bash
|
||||
export NOTIFICATION_BASE_URL="http://127.0.0.1:9095"
|
||||
export NOTIFICATION_TIMEOUT="30s"
|
||||
export NOTIFICATION_RETRY_ATTEMPTS="3"
|
||||
export NOTIFICATION_RETRY_DELAY="2s"
|
||||
export NOTIFICATION_ENABLE_LOGGING="true"
|
||||
```
|
||||
|
||||
## Quick Examples
|
||||
|
||||
### Simple Email
|
||||
```go
|
||||
err := sdk.QuickEmail(ctx, "user@example.com", "Hello!")
|
||||
```
|
||||
|
||||
### Custom Notification
|
||||
```go
|
||||
request := ¬ification.NotificationRequest{
|
||||
EventType: notification.EventTypeEmail,
|
||||
Message: "Hello Nima",
|
||||
Methods: notification.NotificationMethods{
|
||||
OTP: "09143257416",
|
||||
SMS: "09143257416",
|
||||
Push: "devicefsdgsdgsg6766sdgdsg",
|
||||
Email: "nakhostin.nima1998@gmail.com",
|
||||
},
|
||||
UserID: "",
|
||||
}
|
||||
response, err := sdk.SendNotification(ctx, request)
|
||||
```
|
||||
|
||||
### Fluent Builder
|
||||
```go
|
||||
response, err := sdk.NewBuilder().
|
||||
SetEventType(notification.EventTypeEmail).
|
||||
SetMessage("Hello Nima").
|
||||
SetEmail("nakhostin.nima1998@gmail.com").
|
||||
Send(ctx)
|
||||
```
|
||||
|
||||
### Batch Operations
|
||||
```go
|
||||
requests := []*notification.NotificationRequest{...}
|
||||
batchResponse, err := sdk.SendBatch(ctx, requests)
|
||||
```
|
||||
|
||||
## API Response
|
||||
- **Success**: `{"status": "Notification sent"}`
|
||||
- **Error**: `{"error": "error message"}`
|
||||
|
||||
## Error Handling
|
||||
```go
|
||||
if err != nil {
|
||||
switch e := err.(type) {
|
||||
case notification.ErrHTTP:
|
||||
// HTTP error (400, 500, etc.)
|
||||
case notification.ErrValidation:
|
||||
// Validation error
|
||||
case notification.ErrRetryExhausted:
|
||||
// All retry attempts failed
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user