Files
Memoh/internal/db/sqlc/channels.sql.go
T
BBQ 5a35ef34ac feat: channel gateway implementation and multi-bot refactor
- Refactor channel manager with support for Sender/Receiver interfaces and hot-swappable adapters.
- Implement identity routing and pre-authentication logic for inbound messages.
- Update database schema to support bot pre-auth keys and extended channel session metadata.
- Add Telegram and Feishu channel configuration and adapter enhancements.
- Update Swagger documentation and internal handlers for channel management.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-06 14:41:54 +08:00

405 lines
11 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: channels.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteChannelSession = `-- name: DeleteChannelSession :exec
DELETE FROM channel_sessions
WHERE session_id = $1
`
func (q *Queries) DeleteChannelSession(ctx context.Context, sessionID string) error {
_, err := q.db.Exec(ctx, deleteChannelSession, sessionID)
return err
}
const getBotChannelConfig = `-- name: GetBotChannelConfig :one
SELECT id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, status, verified_at, created_at, updated_at
FROM bot_channel_configs
WHERE bot_id = $1 AND channel_type = $2
LIMIT 1
`
type GetBotChannelConfigParams struct {
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
}
func (q *Queries) GetBotChannelConfig(ctx context.Context, arg GetBotChannelConfigParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, getBotChannelConfig, arg.BotID, arg.ChannelType)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Status,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getBotChannelConfigByExternalIdentity = `-- name: GetBotChannelConfigByExternalIdentity :one
SELECT id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, status, verified_at, created_at, updated_at
FROM bot_channel_configs
WHERE channel_type = $1 AND external_identity = $2
LIMIT 1
`
type GetBotChannelConfigByExternalIdentityParams struct {
ChannelType string `json:"channel_type"`
ExternalIdentity pgtype.Text `json:"external_identity"`
}
func (q *Queries) GetBotChannelConfigByExternalIdentity(ctx context.Context, arg GetBotChannelConfigByExternalIdentityParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, getBotChannelConfigByExternalIdentity, arg.ChannelType, arg.ExternalIdentity)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Status,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getChannelSessionByID = `-- name: GetChannelSessionByID :one
SELECT session_id, bot_id, channel_config_id, user_id, contact_id, platform, reply_target, thread_id, metadata, created_at, updated_at
FROM channel_sessions
WHERE session_id = $1
LIMIT 1
`
func (q *Queries) GetChannelSessionByID(ctx context.Context, sessionID string) (ChannelSession, error) {
row := q.db.QueryRow(ctx, getChannelSessionByID, sessionID)
var i ChannelSession
err := row.Scan(
&i.SessionID,
&i.BotID,
&i.ChannelConfigID,
&i.UserID,
&i.ContactID,
&i.Platform,
&i.ReplyTarget,
&i.ThreadID,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getUserChannelBinding = `-- name: GetUserChannelBinding :one
SELECT id, user_id, channel_type, config, created_at, updated_at
FROM user_channel_bindings
WHERE user_id = $1 AND channel_type = $2
LIMIT 1
`
type GetUserChannelBindingParams struct {
UserID pgtype.UUID `json:"user_id"`
ChannelType string `json:"channel_type"`
}
func (q *Queries) GetUserChannelBinding(ctx context.Context, arg GetUserChannelBindingParams) (UserChannelBinding, error) {
row := q.db.QueryRow(ctx, getUserChannelBinding, arg.UserID, arg.ChannelType)
var i UserChannelBinding
err := row.Scan(
&i.ID,
&i.UserID,
&i.ChannelType,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listBotChannelConfigsByType = `-- name: ListBotChannelConfigsByType :many
SELECT id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, status, verified_at, created_at, updated_at
FROM bot_channel_configs
WHERE channel_type = $1
ORDER BY created_at DESC
`
func (q *Queries) ListBotChannelConfigsByType(ctx context.Context, channelType string) ([]BotChannelConfig, error) {
rows, err := q.db.Query(ctx, listBotChannelConfigsByType, channelType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BotChannelConfig
for rows.Next() {
var i BotChannelConfig
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Status,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listChannelSessionsByBotPlatform = `-- name: ListChannelSessionsByBotPlatform :many
SELECT session_id, bot_id, channel_config_id, user_id, contact_id, platform, reply_target, thread_id, metadata, created_at, updated_at
FROM channel_sessions
WHERE bot_id = $1 AND platform = $2
ORDER BY updated_at DESC
`
type ListChannelSessionsByBotPlatformParams struct {
BotID pgtype.UUID `json:"bot_id"`
Platform string `json:"platform"`
}
func (q *Queries) ListChannelSessionsByBotPlatform(ctx context.Context, arg ListChannelSessionsByBotPlatformParams) ([]ChannelSession, error) {
rows, err := q.db.Query(ctx, listChannelSessionsByBotPlatform, arg.BotID, arg.Platform)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ChannelSession
for rows.Next() {
var i ChannelSession
if err := rows.Scan(
&i.SessionID,
&i.BotID,
&i.ChannelConfigID,
&i.UserID,
&i.ContactID,
&i.Platform,
&i.ReplyTarget,
&i.ThreadID,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listUserChannelBindingsByType = `-- name: ListUserChannelBindingsByType :many
SELECT id, user_id, channel_type, config, created_at, updated_at
FROM user_channel_bindings
WHERE channel_type = $1
ORDER BY created_at DESC
`
func (q *Queries) ListUserChannelBindingsByType(ctx context.Context, channelType string) ([]UserChannelBinding, error) {
rows, err := q.db.Query(ctx, listUserChannelBindingsByType, channelType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []UserChannelBinding
for rows.Next() {
var i UserChannelBinding
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.ChannelType,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const upsertBotChannelConfig = `-- name: UpsertBotChannelConfig :one
INSERT INTO bot_channel_configs (
bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, status, verified_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT (bot_id, channel_type)
DO UPDATE SET
credentials = EXCLUDED.credentials,
external_identity = EXCLUDED.external_identity,
self_identity = EXCLUDED.self_identity,
routing = EXCLUDED.routing,
capabilities = EXCLUDED.capabilities,
status = EXCLUDED.status,
verified_at = EXCLUDED.verified_at,
updated_at = now()
RETURNING id, bot_id, channel_type, credentials, external_identity, self_identity, routing, capabilities, status, verified_at, created_at, updated_at
`
type UpsertBotChannelConfigParams struct {
BotID pgtype.UUID `json:"bot_id"`
ChannelType string `json:"channel_type"`
Credentials []byte `json:"credentials"`
ExternalIdentity pgtype.Text `json:"external_identity"`
SelfIdentity []byte `json:"self_identity"`
Routing []byte `json:"routing"`
Capabilities []byte `json:"capabilities"`
Status string `json:"status"`
VerifiedAt pgtype.Timestamptz `json:"verified_at"`
}
func (q *Queries) UpsertBotChannelConfig(ctx context.Context, arg UpsertBotChannelConfigParams) (BotChannelConfig, error) {
row := q.db.QueryRow(ctx, upsertBotChannelConfig,
arg.BotID,
arg.ChannelType,
arg.Credentials,
arg.ExternalIdentity,
arg.SelfIdentity,
arg.Routing,
arg.Capabilities,
arg.Status,
arg.VerifiedAt,
)
var i BotChannelConfig
err := row.Scan(
&i.ID,
&i.BotID,
&i.ChannelType,
&i.Credentials,
&i.ExternalIdentity,
&i.SelfIdentity,
&i.Routing,
&i.Capabilities,
&i.Status,
&i.VerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertChannelSession = `-- name: UpsertChannelSession :one
INSERT INTO channel_sessions (session_id, bot_id, channel_config_id, user_id, contact_id, platform, reply_target, thread_id, metadata)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT (session_id)
DO UPDATE SET
bot_id = EXCLUDED.bot_id,
channel_config_id = EXCLUDED.channel_config_id,
user_id = EXCLUDED.user_id,
contact_id = EXCLUDED.contact_id,
platform = EXCLUDED.platform,
reply_target = EXCLUDED.reply_target,
thread_id = EXCLUDED.thread_id,
metadata = EXCLUDED.metadata,
updated_at = now()
RETURNING session_id, bot_id, channel_config_id, user_id, contact_id, platform, reply_target, thread_id, metadata, created_at, updated_at
`
type UpsertChannelSessionParams struct {
SessionID string `json:"session_id"`
BotID pgtype.UUID `json:"bot_id"`
ChannelConfigID pgtype.UUID `json:"channel_config_id"`
UserID pgtype.UUID `json:"user_id"`
ContactID pgtype.UUID `json:"contact_id"`
Platform string `json:"platform"`
ReplyTarget pgtype.Text `json:"reply_target"`
ThreadID pgtype.Text `json:"thread_id"`
Metadata []byte `json:"metadata"`
}
func (q *Queries) UpsertChannelSession(ctx context.Context, arg UpsertChannelSessionParams) (ChannelSession, error) {
row := q.db.QueryRow(ctx, upsertChannelSession,
arg.SessionID,
arg.BotID,
arg.ChannelConfigID,
arg.UserID,
arg.ContactID,
arg.Platform,
arg.ReplyTarget,
arg.ThreadID,
arg.Metadata,
)
var i ChannelSession
err := row.Scan(
&i.SessionID,
&i.BotID,
&i.ChannelConfigID,
&i.UserID,
&i.ContactID,
&i.Platform,
&i.ReplyTarget,
&i.ThreadID,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertUserChannelBinding = `-- name: UpsertUserChannelBinding :one
INSERT INTO user_channel_bindings (user_id, channel_type, config)
VALUES ($1, $2, $3)
ON CONFLICT (user_id, channel_type)
DO UPDATE SET
config = EXCLUDED.config,
updated_at = now()
RETURNING id, user_id, channel_type, config, created_at, updated_at
`
type UpsertUserChannelBindingParams struct {
UserID pgtype.UUID `json:"user_id"`
ChannelType string `json:"channel_type"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertUserChannelBinding(ctx context.Context, arg UpsertUserChannelBindingParams) (UserChannelBinding, error) {
row := q.db.QueryRow(ctx, upsertUserChannelBinding, arg.UserID, arg.ChannelType, arg.Config)
var i UserChannelBinding
err := row.Scan(
&i.ID,
&i.UserID,
&i.ChannelType,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}