初步集成消息通道,支持Telegram + Lark机器人

This commit is contained in:
xintaofei
2026-03-30 22:51:49 +08:00
parent 544abbd15d
commit d18cec33bf
44 changed files with 4106 additions and 11 deletions

View File

@@ -0,0 +1,179 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// ─── chat_channel ───
manager
.create_table(
Table::create()
.table(ChatChannel::Table)
.if_not_exists()
.col(
ColumnDef::new(ChatChannel::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(ChatChannel::Name).string().not_null())
.col(
ColumnDef::new(ChatChannel::ChannelType)
.string()
.not_null(),
)
.col(
ColumnDef::new(ChatChannel::Enabled)
.boolean()
.not_null()
.default(true),
)
.col(
ColumnDef::new(ChatChannel::ConfigJson)
.text()
.not_null(),
)
.col(ColumnDef::new(ChatChannel::EventFilterJson).text().null())
.col(
ColumnDef::new(ChatChannel::DailyReportEnabled)
.boolean()
.not_null()
.default(false),
)
.col(
ColumnDef::new(ChatChannel::DailyReportTime)
.string()
.null(),
)
.col(
ColumnDef::new(ChatChannel::CreatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(ChatChannel::UpdatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.to_owned(),
)
.await?;
// ─── chat_channel_message_log ───
manager
.create_table(
Table::create()
.table(ChatChannelMessageLog::Table)
.if_not_exists()
.col(
ColumnDef::new(ChatChannelMessageLog::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::ChannelId)
.integer()
.not_null(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::Direction)
.string()
.not_null(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::MessageType)
.string()
.not_null(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::ContentPreview)
.text()
.not_null(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::Status)
.string()
.not_null(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::ErrorDetail)
.text()
.null(),
)
.col(
ColumnDef::new(ChatChannelMessageLog::CreatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("fk_ccml_channel_id")
.from(
ChatChannelMessageLog::Table,
ChatChannelMessageLog::ChannelId,
)
.to(ChatChannel::Table, ChatChannel::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_ccml_channel_created")
.table(ChatChannelMessageLog::Table)
.col(ChatChannelMessageLog::ChannelId)
.col(ChatChannelMessageLog::CreatedAt)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(
Table::drop()
.table(ChatChannelMessageLog::Table)
.to_owned(),
)
.await?;
manager
.drop_table(Table::drop().table(ChatChannel::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum ChatChannel {
Table,
Id,
Name,
ChannelType,
Enabled,
ConfigJson,
EventFilterJson,
DailyReportEnabled,
DailyReportTime,
CreatedAt,
UpdatedAt,
}
#[derive(DeriveIden)]
enum ChatChannelMessageLog {
Table,
Id,
ChannelId,
Direction,
MessageType,
ContentPreview,
Status,
ErrorDetail,
CreatedAt,
}

View File

@@ -5,6 +5,7 @@ mod m20260219_000001_folder_command;
mod m20260221_000001_folder_is_open;
mod m20260226_000001_agent_setting;
mod m20260227_000001_folder_parent_branch;
mod m20260330_000001_chat_channel;
pub struct Migrator;
#[async_trait::async_trait]
@@ -16,6 +17,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260221_000001_folder_is_open::Migration),
Box::new(m20260226_000001_agent_setting::Migration),
Box::new(m20260227_000001_folder_parent_branch::Migration),
Box::new(m20260330_000001_chat_channel::Migration),
]
}
}