Channels
A channel connects a chat platform to an agent. The contract is the Channel trait in aidaemon-channels (SDK feature channels). Built-in adapters exist for Telegram, Slack and Discord (features telegram, slack, discord).
Use a built-in adapter
use std::sync::Arc;
use aidaemon_sdk::channels::{AccessPolicy, ChannelRunner};
use aidaemon_sdk::channels::telegram::TelegramChannel;
use aidaemon_sdk::CancellationToken;
let channel = TelegramChannel::new(bot_token);
let runner = ChannelRunner::builder(agent)
.channel(Arc::new(channel))
.access(AccessPolicy::new().owner("telegram", owner_id))
.build()?;
runner.run(CancellationToken::new()).await; // until cancelledThe runner gives you one session per conversation, one run at a time per session, queueing, streamed progress, and approvals as buttons that resume interrupted runs (see Hooks and policies). The channel_bot example runs the whole flow against an in-process TestChannel, so it needs no bot token.
Durable approvals
By default, pending approvals are held in memory. To keep them across a restart, give the runner the SQLite approval store. It needs the channels feature of aidaemon-store-sqlite:
[dependencies]
aidaemon-store-sqlite = { git = "https://github.com/davo20019/aidaemon", features = ["channels"] }use aidaemon_store_sqlite::{SqliteApprovalStore, SqliteStore};
let store = SqliteStore::open("agent.db").await?;
let runner = ChannelRunner::builder(agent)
.channel(Arc::new(channel))
.approval_store(Arc::new(SqliteApprovalStore::new(&store)))
.build()?;A button pressed after a restart still resumes the run, and a double click settles it once.
Write your own channel
Implement four required methods:
use aidaemon_channels::{
Channel, ChannelCapabilities, ChannelError, ChannelEvent, Conversation,
MessageRef, OutboundMessage,
};
use async_trait::async_trait;
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
struct MyChat { /* client handles */ }
#[async_trait]
impl Channel for MyChat {
fn name(&self) -> &str { "mychat" }
fn capabilities(&self) -> ChannelCapabilities {
ChannelCapabilities { max_message_len: 4000, ..Default::default() }
}
// Forward platform updates as ChannelEvent::Message(InboundMessage)
// until `shutdown` is cancelled.
async fn run(
&self,
events: mpsc::Sender<ChannelEvent>,
shutdown: CancellationToken,
) -> Result<(), ChannelError> {
todo!()
}
async fn send(
&self,
conversation: &Conversation,
message: &OutboundMessage,
) -> Result<MessageRef, ChannelError> {
todo!()
}
}edit, ask (buttons), typing, files and commands are optional; declare what you support in ChannelCapabilities and the runner adapts. Enable the crate's conformance feature to run the adapter conformance kit (aidaemon_channels::conformance) against your channel.