mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: add email service with multi-adapter support (#146)
* feat: add email service with multi-adapter support Implement a full-stack email service with global provider management, per-bot bindings with granular read/write permissions, outbox audit storage, and MCP tool integration for direct mailbox access. Backend: - Email providers: CRUD with dynamic config schema (generic SMTP/IMAP, Mailgun) - Generic adapter: go-mail (SMTP) + go-imap/v2 (IMAP IDLE real-time push via UnilateralDataHandler + UID-based tracking + periodic check fallback) - Mailgun adapter: mailgun-go/v5 with dual inbound mode (webhook + poll) - Bot email bindings: per-bot provider binding with independent r/w permissions - Outbox: outbound email audit log with status tracking - Trigger: inbound emails push notification to bot_inbox (from/subject only, LLM reads full content on demand via MCP tools) - MailboxReader interface: on-demand IMAP queries for listing/reading emails - MCP tools: email_accounts, email_send, email_list (paginated mailbox), email_read (by UID) — all with multi-binding and provider_id selection - Webhook: /email/mailgun/webhook/:config_id (JWT-skipped, signature-verified) - DB migration: 0019_add_email (email_providers, bot_email_bindings, email_outbox) Frontend: - Email Providers page: /email-providers with MasterDetailSidebarLayout - Dynamic config form rendered from ordered provider meta schema with i18n keys - Bot detail: Email tab with bindings management + outbox audit table - Sidebar navigation entry - Full i18n support (en + zh) - Auto-generated SDK from Swagger Closes #17 * feat(email): trigger bot conversation immediately on inbound email Instead of only storing an inbox item and waiting for the next chat, the email trigger now proactively invokes the conversation resolver so the bot processes new emails right away — aligned with the schedule/heartbeat trigger pattern. * fix: lint --------- Co-authored-by: Acbox <acbox0328@gmail.com>
This commit is contained in:
@@ -0,0 +1,279 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: email_bindings.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createBotEmailBinding = `-- name: CreateBotEmailBinding :one
|
||||
INSERT INTO bot_email_bindings (bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
)
|
||||
RETURNING id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateBotEmailBindingParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
EmailProviderID pgtype.UUID `json:"email_provider_id"`
|
||||
EmailAddress string `json:"email_address"`
|
||||
CanRead bool `json:"can_read"`
|
||||
CanWrite bool `json:"can_write"`
|
||||
CanDelete bool `json:"can_delete"`
|
||||
Config []byte `json:"config"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBotEmailBinding(ctx context.Context, arg CreateBotEmailBindingParams) (BotEmailBinding, error) {
|
||||
row := q.db.QueryRow(ctx, createBotEmailBinding,
|
||||
arg.BotID,
|
||||
arg.EmailProviderID,
|
||||
arg.EmailAddress,
|
||||
arg.CanRead,
|
||||
arg.CanWrite,
|
||||
arg.CanDelete,
|
||||
arg.Config,
|
||||
)
|
||||
var i BotEmailBinding
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteBotEmailBinding = `-- name: DeleteBotEmailBinding :exec
|
||||
DELETE FROM bot_email_bindings WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteBotEmailBinding(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteBotEmailBinding, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getBotEmailBindingByBotAndProvider = `-- name: GetBotEmailBindingByBotAndProvider :one
|
||||
SELECT id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at FROM bot_email_bindings
|
||||
WHERE bot_id = $1 AND email_provider_id = $2
|
||||
`
|
||||
|
||||
type GetBotEmailBindingByBotAndProviderParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
EmailProviderID pgtype.UUID `json:"email_provider_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBotEmailBindingByBotAndProvider(ctx context.Context, arg GetBotEmailBindingByBotAndProviderParams) (BotEmailBinding, error) {
|
||||
row := q.db.QueryRow(ctx, getBotEmailBindingByBotAndProvider, arg.BotID, arg.EmailProviderID)
|
||||
var i BotEmailBinding
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBotEmailBindingByID = `-- name: GetBotEmailBindingByID :one
|
||||
SELECT id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at FROM bot_email_bindings WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBotEmailBindingByID(ctx context.Context, id pgtype.UUID) (BotEmailBinding, error) {
|
||||
row := q.db.QueryRow(ctx, getBotEmailBindingByID, id)
|
||||
var i BotEmailBinding
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBotEmailBindings = `-- name: ListBotEmailBindings :many
|
||||
SELECT id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at FROM bot_email_bindings
|
||||
WHERE bot_id = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListBotEmailBindings(ctx context.Context, botID pgtype.UUID) ([]BotEmailBinding, error) {
|
||||
rows, err := q.db.Query(ctx, listBotEmailBindings, botID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BotEmailBinding
|
||||
for rows.Next() {
|
||||
var i BotEmailBinding
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&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 listBotEmailBindingsByProvider = `-- name: ListBotEmailBindingsByProvider :many
|
||||
SELECT id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at FROM bot_email_bindings
|
||||
WHERE email_provider_id = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListBotEmailBindingsByProvider(ctx context.Context, emailProviderID pgtype.UUID) ([]BotEmailBinding, error) {
|
||||
rows, err := q.db.Query(ctx, listBotEmailBindingsByProvider, emailProviderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BotEmailBinding
|
||||
for rows.Next() {
|
||||
var i BotEmailBinding
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&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 listReadableBindingsByProvider = `-- name: ListReadableBindingsByProvider :many
|
||||
SELECT id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at FROM bot_email_bindings
|
||||
WHERE email_provider_id = $1 AND can_read = TRUE
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListReadableBindingsByProvider(ctx context.Context, emailProviderID pgtype.UUID) ([]BotEmailBinding, error) {
|
||||
rows, err := q.db.Query(ctx, listReadableBindingsByProvider, emailProviderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BotEmailBinding
|
||||
for rows.Next() {
|
||||
var i BotEmailBinding
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&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 updateBotEmailBinding = `-- name: UpdateBotEmailBinding :one
|
||||
UPDATE bot_email_bindings
|
||||
SET
|
||||
email_address = $1,
|
||||
can_read = $2,
|
||||
can_write = $3,
|
||||
can_delete = $4,
|
||||
config = $5,
|
||||
updated_at = now()
|
||||
WHERE id = $6
|
||||
RETURNING id, bot_id, email_provider_id, email_address, can_read, can_write, can_delete, config, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateBotEmailBindingParams struct {
|
||||
EmailAddress string `json:"email_address"`
|
||||
CanRead bool `json:"can_read"`
|
||||
CanWrite bool `json:"can_write"`
|
||||
CanDelete bool `json:"can_delete"`
|
||||
Config []byte `json:"config"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBotEmailBinding(ctx context.Context, arg UpdateBotEmailBindingParams) (BotEmailBinding, error) {
|
||||
row := q.db.QueryRow(ctx, updateBotEmailBinding,
|
||||
arg.EmailAddress,
|
||||
arg.CanRead,
|
||||
arg.CanWrite,
|
||||
arg.CanDelete,
|
||||
arg.Config,
|
||||
arg.ID,
|
||||
)
|
||||
var i BotEmailBinding
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BotID,
|
||||
&i.EmailProviderID,
|
||||
&i.EmailAddress,
|
||||
&i.CanRead,
|
||||
&i.CanWrite,
|
||||
&i.CanDelete,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: email_outbox.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countEmailOutboxByBot = `-- name: CountEmailOutboxByBot :one
|
||||
SELECT count(*) FROM email_outbox
|
||||
WHERE bot_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountEmailOutboxByBot(ctx context.Context, botID pgtype.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countEmailOutboxByBot, botID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createEmailOutbox = `-- name: CreateEmailOutbox :one
|
||||
INSERT INTO email_outbox (provider_id, bot_id, from_address, to_addresses, subject, body_text, body_html, attachments, status)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8,
|
||||
$9
|
||||
)
|
||||
RETURNING id, provider_id, bot_id, message_id, from_address, to_addresses, subject, body_text, body_html, attachments, status, error, sent_at, created_at
|
||||
`
|
||||
|
||||
type CreateEmailOutboxParams struct {
|
||||
ProviderID pgtype.UUID `json:"provider_id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
FromAddress string `json:"from_address"`
|
||||
ToAddresses []byte `json:"to_addresses"`
|
||||
Subject string `json:"subject"`
|
||||
BodyText string `json:"body_text"`
|
||||
BodyHtml string `json:"body_html"`
|
||||
Attachments []byte `json:"attachments"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEmailOutbox(ctx context.Context, arg CreateEmailOutboxParams) (EmailOutbox, error) {
|
||||
row := q.db.QueryRow(ctx, createEmailOutbox,
|
||||
arg.ProviderID,
|
||||
arg.BotID,
|
||||
arg.FromAddress,
|
||||
arg.ToAddresses,
|
||||
arg.Subject,
|
||||
arg.BodyText,
|
||||
arg.BodyHtml,
|
||||
arg.Attachments,
|
||||
arg.Status,
|
||||
)
|
||||
var i EmailOutbox
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProviderID,
|
||||
&i.BotID,
|
||||
&i.MessageID,
|
||||
&i.FromAddress,
|
||||
&i.ToAddresses,
|
||||
&i.Subject,
|
||||
&i.BodyText,
|
||||
&i.BodyHtml,
|
||||
&i.Attachments,
|
||||
&i.Status,
|
||||
&i.Error,
|
||||
&i.SentAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getEmailOutboxByID = `-- name: GetEmailOutboxByID :one
|
||||
SELECT id, provider_id, bot_id, message_id, from_address, to_addresses, subject, body_text, body_html, attachments, status, error, sent_at, created_at FROM email_outbox WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetEmailOutboxByID(ctx context.Context, id pgtype.UUID) (EmailOutbox, error) {
|
||||
row := q.db.QueryRow(ctx, getEmailOutboxByID, id)
|
||||
var i EmailOutbox
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProviderID,
|
||||
&i.BotID,
|
||||
&i.MessageID,
|
||||
&i.FromAddress,
|
||||
&i.ToAddresses,
|
||||
&i.Subject,
|
||||
&i.BodyText,
|
||||
&i.BodyHtml,
|
||||
&i.Attachments,
|
||||
&i.Status,
|
||||
&i.Error,
|
||||
&i.SentAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listEmailOutboxByBot = `-- name: ListEmailOutboxByBot :many
|
||||
SELECT id, provider_id, bot_id, message_id, from_address, to_addresses, subject, body_text, body_html, attachments, status, error, sent_at, created_at FROM email_outbox
|
||||
WHERE bot_id = $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $3 OFFSET $2
|
||||
`
|
||||
|
||||
type ListEmailOutboxByBotParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
Off int32 `json:"off"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListEmailOutboxByBot(ctx context.Context, arg ListEmailOutboxByBotParams) ([]EmailOutbox, error) {
|
||||
rows, err := q.db.Query(ctx, listEmailOutboxByBot, arg.BotID, arg.Off, arg.Lim)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EmailOutbox
|
||||
for rows.Next() {
|
||||
var i EmailOutbox
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProviderID,
|
||||
&i.BotID,
|
||||
&i.MessageID,
|
||||
&i.FromAddress,
|
||||
&i.ToAddresses,
|
||||
&i.Subject,
|
||||
&i.BodyText,
|
||||
&i.BodyHtml,
|
||||
&i.Attachments,
|
||||
&i.Status,
|
||||
&i.Error,
|
||||
&i.SentAt,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateEmailOutboxFailed = `-- name: UpdateEmailOutboxFailed :exec
|
||||
UPDATE email_outbox
|
||||
SET status = 'failed', error = $1
|
||||
WHERE id = $2
|
||||
`
|
||||
|
||||
type UpdateEmailOutboxFailedParams struct {
|
||||
Error string `json:"error"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateEmailOutboxFailed(ctx context.Context, arg UpdateEmailOutboxFailedParams) error {
|
||||
_, err := q.db.Exec(ctx, updateEmailOutboxFailed, arg.Error, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateEmailOutboxSent = `-- name: UpdateEmailOutboxSent :exec
|
||||
UPDATE email_outbox
|
||||
SET message_id = $1, status = 'sent', sent_at = now()
|
||||
WHERE id = $2
|
||||
`
|
||||
|
||||
type UpdateEmailOutboxSentParams struct {
|
||||
MessageID string `json:"message_id"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateEmailOutboxSent(ctx context.Context, arg UpdateEmailOutboxSentParams) error {
|
||||
_, err := q.db.Exec(ctx, updateEmailOutboxSent, arg.MessageID, arg.ID)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: email_providers.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createEmailProvider = `-- name: CreateEmailProvider :one
|
||||
INSERT INTO email_providers (name, provider, config)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
)
|
||||
RETURNING id, name, provider, config, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateEmailProviderParams struct {
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Config []byte `json:"config"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEmailProvider(ctx context.Context, arg CreateEmailProviderParams) (EmailProvider, error) {
|
||||
row := q.db.QueryRow(ctx, createEmailProvider, arg.Name, arg.Provider, arg.Config)
|
||||
var i EmailProvider
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Provider,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteEmailProvider = `-- name: DeleteEmailProvider :exec
|
||||
DELETE FROM email_providers WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteEmailProvider(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteEmailProvider, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getEmailProviderByID = `-- name: GetEmailProviderByID :one
|
||||
SELECT id, name, provider, config, created_at, updated_at FROM email_providers WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetEmailProviderByID(ctx context.Context, id pgtype.UUID) (EmailProvider, error) {
|
||||
row := q.db.QueryRow(ctx, getEmailProviderByID, id)
|
||||
var i EmailProvider
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Provider,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getEmailProviderByName = `-- name: GetEmailProviderByName :one
|
||||
SELECT id, name, provider, config, created_at, updated_at FROM email_providers WHERE name = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetEmailProviderByName(ctx context.Context, name string) (EmailProvider, error) {
|
||||
row := q.db.QueryRow(ctx, getEmailProviderByName, name)
|
||||
var i EmailProvider
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Provider,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listEmailProviders = `-- name: ListEmailProviders :many
|
||||
SELECT id, name, provider, config, created_at, updated_at FROM email_providers
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListEmailProviders(ctx context.Context) ([]EmailProvider, error) {
|
||||
rows, err := q.db.Query(ctx, listEmailProviders)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EmailProvider
|
||||
for rows.Next() {
|
||||
var i EmailProvider
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Provider,
|
||||
&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 listEmailProvidersByProvider = `-- name: ListEmailProvidersByProvider :many
|
||||
SELECT id, name, provider, config, created_at, updated_at FROM email_providers
|
||||
WHERE provider = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListEmailProvidersByProvider(ctx context.Context, provider string) ([]EmailProvider, error) {
|
||||
rows, err := q.db.Query(ctx, listEmailProvidersByProvider, provider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EmailProvider
|
||||
for rows.Next() {
|
||||
var i EmailProvider
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Provider,
|
||||
&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 updateEmailProvider = `-- name: UpdateEmailProvider :one
|
||||
UPDATE email_providers
|
||||
SET
|
||||
name = $1,
|
||||
provider = $2,
|
||||
config = $3,
|
||||
updated_at = now()
|
||||
WHERE id = $4
|
||||
RETURNING id, name, provider, config, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateEmailProviderParams struct {
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Config []byte `json:"config"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateEmailProvider(ctx context.Context, arg UpdateEmailProviderParams) (EmailProvider, error) {
|
||||
row := q.db.QueryRow(ctx, updateEmailProvider,
|
||||
arg.Name,
|
||||
arg.Provider,
|
||||
arg.Config,
|
||||
arg.ID,
|
||||
)
|
||||
var i EmailProvider
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Provider,
|
||||
&i.Config,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -65,6 +65,19 @@ type BotChannelRoute struct {
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type BotEmailBinding struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
EmailProviderID pgtype.UUID `json:"email_provider_id"`
|
||||
EmailAddress string `json:"email_address"`
|
||||
CanRead bool `json:"can_read"`
|
||||
CanWrite bool `json:"can_write"`
|
||||
CanDelete bool `json:"can_delete"`
|
||||
Config []byte `json:"config"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type BotHeartbeatLog struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
@@ -187,6 +200,32 @@ type ContainerVersion struct {
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type EmailOutbox struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProviderID pgtype.UUID `json:"provider_id"`
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
MessageID string `json:"message_id"`
|
||||
FromAddress string `json:"from_address"`
|
||||
ToAddresses []byte `json:"to_addresses"`
|
||||
Subject string `json:"subject"`
|
||||
BodyText string `json:"body_text"`
|
||||
BodyHtml string `json:"body_html"`
|
||||
Attachments []byte `json:"attachments"`
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error"`
|
||||
SentAt pgtype.Timestamptz `json:"sent_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type EmailProvider struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Config []byte `json:"config"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LifecycleEvent struct {
|
||||
ID string `json:"id"`
|
||||
ContainerID string `json:"container_id"`
|
||||
|
||||
Reference in New Issue
Block a user