feat: initial commit
This commit is contained in:
25
internal/domain/apperror/errors.go
Normal file
25
internal/domain/apperror/errors.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package apperror
|
||||
|
||||
import "errors"
|
||||
|
||||
type AppError struct {
|
||||
Code string
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
var (
|
||||
ErrMessageEmpty = &AppError{Code: "MSG_EMPTY", Message: "message text is empty"}
|
||||
ErrRouteNotFound = &AppError{Code: "ROUTE_NOT_FOUND", Message: "no route found for message"}
|
||||
ErrWorkflowTimeout = &AppError{Code: "WORKFLOW_TIMEOUT", Message: "workflow call timed out"}
|
||||
ErrTranscriptionFailed = &AppError{Code: "TRANSCRIPTION_FAILED", Message: "voice transcription failed"}
|
||||
ErrSessionNotFound = &AppError{Code: "SESSION_NOT_FOUND", Message: "session not found"}
|
||||
ErrDownloadFailed = &AppError{Code: "DOWNLOAD_FAILED", Message: "file download failed"}
|
||||
)
|
||||
|
||||
func Is(err, target error) bool {
|
||||
return errors.Is(err, target)
|
||||
}
|
||||
28
internal/domain/entity/intent.go
Normal file
28
internal/domain/entity/intent.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package entity
|
||||
|
||||
type Intent struct {
|
||||
Name string
|
||||
Confidence float64
|
||||
Entities map[string]any
|
||||
}
|
||||
|
||||
type RouteTargetType string
|
||||
|
||||
const (
|
||||
RouteTargetN8n RouteTargetType = "n8n"
|
||||
RouteTargetAIAgent RouteTargetType = "ai_agent"
|
||||
RouteTargetBuiltin RouteTargetType = "builtin"
|
||||
)
|
||||
|
||||
type RouteTarget struct {
|
||||
Type RouteTargetType
|
||||
WorkflowID string
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
Pattern string
|
||||
IntentName string
|
||||
Target RouteTarget
|
||||
Priority int
|
||||
}
|
||||
29
internal/domain/entity/message.go
Normal file
29
internal/domain/entity/message.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type MessageType string
|
||||
|
||||
const (
|
||||
MessageTypeText MessageType = "text"
|
||||
MessageTypeVoice MessageType = "voice"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
MessageID int64
|
||||
ChatID int64
|
||||
UserID int64
|
||||
Username string
|
||||
Type MessageType
|
||||
Text string
|
||||
VoiceFileID string
|
||||
Timestamp time.Time
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type VoiceMessage struct {
|
||||
FileID string
|
||||
Duration int
|
||||
MimeType string
|
||||
FileSize int
|
||||
}
|
||||
22
internal/domain/entity/user.go
Normal file
22
internal/domain/entity/user.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
TelegramID int64
|
||||
Username string
|
||||
FirstName string
|
||||
LastName string
|
||||
Language string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
UserID int64
|
||||
ChatID int64
|
||||
CurrentWorkflow string
|
||||
History []Message
|
||||
Data map[string]any
|
||||
UpdatedAt time.Time
|
||||
TTL int // hours
|
||||
}
|
||||
29
internal/domain/entity/workflow.go
Normal file
29
internal/domain/entity/workflow.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type WorkflowRequest struct {
|
||||
RequestID string
|
||||
ChatID int64
|
||||
UserID int64
|
||||
Username string
|
||||
MessageText string
|
||||
Intent Intent
|
||||
Session Session
|
||||
Timestamp time.Time
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
Type string
|
||||
Key string
|
||||
Value any
|
||||
}
|
||||
|
||||
type WorkflowResponse struct {
|
||||
RequestID string
|
||||
ReplyText string
|
||||
Actions []Action
|
||||
NextWorkflow string
|
||||
Error error
|
||||
}
|
||||
7
internal/domain/port/file_downloader.go
Normal file
7
internal/domain/port/file_downloader.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package port
|
||||
|
||||
import "context"
|
||||
|
||||
type FileDownloader interface {
|
||||
Download(ctx context.Context, fileID string) ([]byte, string, error) // bytes, mimeType, error
|
||||
}
|
||||
10
internal/domain/port/intent_router.go
Normal file
10
internal/domain/port/intent_router.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package port
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/paramah/gw_telegram/internal/domain/entity"
|
||||
)
|
||||
|
||||
type IntentRouter interface {
|
||||
Route(ctx context.Context, msg entity.Message) (entity.Route, error)
|
||||
}
|
||||
8
internal/domain/port/message_gateway.go
Normal file
8
internal/domain/port/message_gateway.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package port
|
||||
|
||||
import "context"
|
||||
|
||||
type MessageGateway interface {
|
||||
SendText(ctx context.Context, chatID int64, text string) error
|
||||
SendTyping(ctx context.Context, chatID int64) error
|
||||
}
|
||||
12
internal/domain/port/session_store.go
Normal file
12
internal/domain/port/session_store.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package port
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/paramah/gw_telegram/internal/domain/entity"
|
||||
)
|
||||
|
||||
type SessionStore interface {
|
||||
Get(ctx context.Context, userID int64) (entity.Session, error)
|
||||
Set(ctx context.Context, session entity.Session) error
|
||||
Delete(ctx context.Context, userID int64) error
|
||||
}
|
||||
7
internal/domain/port/speech_transcriber.go
Normal file
7
internal/domain/port/speech_transcriber.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package port
|
||||
|
||||
import "context"
|
||||
|
||||
type SpeechTranscriber interface {
|
||||
Transcribe(ctx context.Context, audioData []byte, mimeType string) (string, error)
|
||||
}
|
||||
10
internal/domain/port/workflow_dispatcher.go
Normal file
10
internal/domain/port/workflow_dispatcher.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package port
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/paramah/gw_telegram/internal/domain/entity"
|
||||
)
|
||||
|
||||
type WorkflowDispatcher interface {
|
||||
Dispatch(ctx context.Context, req entity.WorkflowRequest) (entity.WorkflowResponse, error)
|
||||
}
|
||||
Reference in New Issue
Block a user