Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
use crate::email::db::address::EmailRecipientType;
use crate::email::service::address::ContactInfo;
use crate::service;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use sqlx::FromRow;
use uuid::Uuid;
#[derive(FromRow, Debug, Clone, Serialize, Deserialize)]
pub struct Message {
// the uuid we generated for the message in our database
pub id: Uuid,
// the id the user's provider (i.e. gmail) uses to identify the message
pub provider_id: Option<String>,
// the uuid we generated for the message's thread in in the database
pub thread_id: Uuid,
// the id the user's provider (i.e. gmail) uses to identify the thread
pub provider_thread_id: Option<String>,
// the db id of the specific message this message is replying to (if any)
pub replying_to_id: Option<Uuid>,
/// The globally unique Message-ID header value generated by the sender's provider to uniquely identify this email
/// Used for threading across all providers (In-Reply-To header, References header)
pub global_id: Option<String>,
pub link_id: Uuid,
pub provider_history_id: Option<String>,
pub internal_date_ts: Option<DateTime<Utc>>,
pub snippet: Option<String>,
pub size_estimate: Option<i64>,
pub subject: Option<String>,
pub from_name: Option<String>,
pub from_contact_id: Option<Uuid>,
pub sent_at: Option<DateTime<Utc>>,
pub has_attachments: bool,
pub is_read: bool,
pub is_starred: bool,
pub is_sent: bool,
pub is_draft: bool,
pub body_text: Option<String>,
pub body_html_sanitized: Option<String>,
pub body_macro: Option<String>,
pub headers_jsonb: Option<JsonValue>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(FromRow, Debug, Clone, Serialize, Deserialize)]
pub struct MessageToSend {
pub db_id: Option<Uuid>,
pub provider_id: Option<String>,
pub thread_db_id: Option<Uuid>,
pub provider_thread_id: Option<String>,
pub replying_to_id: Option<Uuid>,
pub link_id: Uuid,
pub subject: String,
pub to: Option<Vec<ContactInfo>>,
pub cc: Option<Vec<ContactInfo>>,
pub bcc: Option<Vec<ContactInfo>>,
pub body_text: Option<String>,
pub body_html: Option<String>,
pub body_macro: Option<String>,
pub headers_json: Option<JsonValue>,
}
/// Represents a scheduled message that will be sent to the provider at a later time.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScheduledMessage {
/// the id of the link that the message is associated with.
pub link_id: Uuid,
/// the id of the message in our database.
pub message_id: Uuid,
/// the time the message is scheduled to be sent.
pub send_time: DateTime<Utc>,
/// whether the message has been sent to the provider yet.
pub sent: bool,
/// whether the message is currently being processed by the background job.
pub processing: bool,
/// The authenticated user who initiated the send, as a principal string
/// (`macro|…`). `None` for rows created before actor tracking existed.
pub actor_id: Option<String>,
/// Code-mode invocation that scheduled this delivery.
#[serde(default)]
pub agent_correlation_id: Option<Uuid>,
}
impl From<service::message::ScheduledMessage> for ScheduledMessage {
fn from(other: service::message::ScheduledMessage) -> Self {
Self {
link_id: other.link_id,
message_id: other.message_id,
send_time: other.send_time,
sent: other.sent,
processing: other.processing,
actor_id: other.actor_id,
agent_correlation_id: other.agent_correlation_id,
}
}
}
#[derive(FromRow, Debug, Clone, Serialize, Deserialize)]
pub struct MessageRecipient {
pub contact_id: Uuid,
pub recipient_type: EmailRecipientType,
pub name: Option<String>,
}