Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
use crate::shared::models::UserSession;
|
|
|
|
|
use crate::shared::state::AppState;
|
|
|
|
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
|
|
|
|
use diesel::prelude::*;
|
|
|
|
|
use log::{debug, error, trace};
|
|
|
|
|
use rhai::{Dynamic, Engine};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
pub fn post_to_at_keyword(state: Arc<AppState>, user: UserSession, engine: &mut Engine) {
|
|
|
|
|
let state_clone = Arc::clone(&state);
|
|
|
|
|
let user_clone = user;
|
|
|
|
|
|
|
|
|
|
engine
|
|
|
|
|
.register_custom_syntax(
|
2025-12-26 08:59:25 -03:00
|
|
|
[
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
"POST", "TO", "$expr$", "AT", "$expr$", "$expr$", ",", "$expr$",
|
|
|
|
|
],
|
|
|
|
|
false,
|
|
|
|
|
move |context, inputs| {
|
|
|
|
|
let platform = context.eval_expression_tree(&inputs[0])?.to_string();
|
|
|
|
|
let schedule_time = context.eval_expression_tree(&inputs[1])?.to_string();
|
|
|
|
|
let media = context.eval_expression_tree(&inputs[2])?.to_string();
|
|
|
|
|
let caption = context.eval_expression_tree(&inputs[3])?.to_string();
|
|
|
|
|
|
|
|
|
|
let platform = platform.trim_matches('"').to_lowercase();
|
|
|
|
|
let schedule_time = schedule_time.trim_matches('"');
|
|
|
|
|
let media = media.trim_matches('"');
|
|
|
|
|
let caption = caption.trim_matches('"');
|
|
|
|
|
|
|
|
|
|
let scheduled_at = parse_schedule_time(schedule_time)?;
|
|
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
|
"POST TO {} AT {}: media={}, caption={}",
|
|
|
|
|
platform,
|
|
|
|
|
scheduled_at,
|
|
|
|
|
media,
|
|
|
|
|
caption
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let state_for_task = Arc::clone(&state_clone);
|
|
|
|
|
let user_for_task = user_clone.clone();
|
2025-12-26 08:59:25 -03:00
|
|
|
let platform_owned = platform;
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
let media_owned = media.to_string();
|
|
|
|
|
let caption_owned = caption.to_string();
|
|
|
|
|
|
|
|
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
|
|
|
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
|
|
|
|
.worker_threads(2)
|
|
|
|
|
.enable_all()
|
|
|
|
|
.build();
|
|
|
|
|
|
feat(autotask): Implement AutoTask system with intent classification and app generation
- Add IntentClassifier with 7 intent types (APP_CREATE, TODO, MONITOR, ACTION, SCHEDULE, GOAL, TOOL)
- Add AppGenerator with LLM-powered app structure analysis
- Add DesignerAI for modifying apps through conversation
- Add app_server for serving generated apps with clean URLs
- Add db_api for CRUD operations on bot database tables
- Add ask_later keyword for pending info collection
- Add migration 6.1.1 with tables: pending_info, auto_tasks, execution_plans, task_approvals, task_decisions, safety_audit_log, generated_apps, intent_classifications, designer_changes
- Write apps to S3 drive and sync to SITE_ROOT for serving
- Clean URL structure: /apps/{app_name}/
- Integrate with DriveMonitor for file sync
Based on Chapter 17 - Autonomous Tasks specification
2025-12-27 21:10:09 -03:00
|
|
|
if let Ok(_rt) = rt {
|
|
|
|
|
let result = execute_scheduled_post(
|
|
|
|
|
&state_for_task,
|
|
|
|
|
&user_for_task,
|
|
|
|
|
&platform_owned,
|
|
|
|
|
&media_owned,
|
|
|
|
|
&caption_owned,
|
|
|
|
|
scheduled_at,
|
|
|
|
|
);
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
let _ = tx.send(result);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
match rx.recv_timeout(std::time::Duration::from_secs(30)) {
|
|
|
|
|
Ok(Ok(post_id)) => Ok(Dynamic::from(post_id)),
|
|
|
|
|
Ok(Err(e)) => Err(Box::new(rhai::EvalAltResult::ErrorRuntime(
|
|
|
|
|
format!("Scheduled POST TO failed: {}", e).into(),
|
|
|
|
|
rhai::Position::NONE,
|
|
|
|
|
))),
|
|
|
|
|
Err(_) => Err(Box::new(rhai::EvalAltResult::ErrorRuntime(
|
|
|
|
|
"Scheduled POST TO timed out".into(),
|
|
|
|
|
rhai::Position::NONE,
|
|
|
|
|
))),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
debug!("Registered POST TO AT keyword");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parse_schedule_time(time_str: &str) -> Result<DateTime<Utc>, Box<rhai::EvalAltResult>> {
|
|
|
|
|
let formats = [
|
|
|
|
|
"%Y-%m-%d %H:%M",
|
|
|
|
|
"%Y-%m-%d %H:%M:%S",
|
|
|
|
|
"%Y-%m-%dT%H:%M:%S",
|
|
|
|
|
"%Y-%m-%dT%H:%M",
|
|
|
|
|
"%d/%m/%Y %H:%M",
|
|
|
|
|
"%m/%d/%Y %H:%M",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for format in formats {
|
|
|
|
|
if let Ok(naive) = NaiveDateTime::parse_from_str(time_str, format) {
|
|
|
|
|
return Ok(DateTime::from_naive_utc_and_offset(naive, Utc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Err(Box::new(rhai::EvalAltResult::ErrorRuntime(
|
|
|
|
|
format!(
|
|
|
|
|
"Invalid date format: {}. Use YYYY-MM-DD HH:MM format.",
|
|
|
|
|
time_str
|
|
|
|
|
)
|
|
|
|
|
.into(),
|
|
|
|
|
rhai::Position::NONE,
|
|
|
|
|
)))
|
|
|
|
|
}
|
|
|
|
|
|
feat(autotask): Implement AutoTask system with intent classification and app generation
- Add IntentClassifier with 7 intent types (APP_CREATE, TODO, MONITOR, ACTION, SCHEDULE, GOAL, TOOL)
- Add AppGenerator with LLM-powered app structure analysis
- Add DesignerAI for modifying apps through conversation
- Add app_server for serving generated apps with clean URLs
- Add db_api for CRUD operations on bot database tables
- Add ask_later keyword for pending info collection
- Add migration 6.1.1 with tables: pending_info, auto_tasks, execution_plans, task_approvals, task_decisions, safety_audit_log, generated_apps, intent_classifications, designer_changes
- Write apps to S3 drive and sync to SITE_ROOT for serving
- Clean URL structure: /apps/{app_name}/
- Integrate with DriveMonitor for file sync
Based on Chapter 17 - Autonomous Tasks specification
2025-12-27 21:10:09 -03:00
|
|
|
fn execute_scheduled_post(
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
state: &AppState,
|
|
|
|
|
user: &UserSession,
|
|
|
|
|
platform: &str,
|
|
|
|
|
media: &str,
|
|
|
|
|
caption: &str,
|
|
|
|
|
scheduled_at: DateTime<Utc>,
|
|
|
|
|
) -> Result<String, String> {
|
|
|
|
|
let platforms: Vec<&str> = platform.split(',').map(|s| s.trim()).collect();
|
|
|
|
|
let mut post_ids = Vec::new();
|
|
|
|
|
|
|
|
|
|
for p in platforms {
|
feat(autotask): Implement AutoTask system with intent classification and app generation
- Add IntentClassifier with 7 intent types (APP_CREATE, TODO, MONITOR, ACTION, SCHEDULE, GOAL, TOOL)
- Add AppGenerator with LLM-powered app structure analysis
- Add DesignerAI for modifying apps through conversation
- Add app_server for serving generated apps with clean URLs
- Add db_api for CRUD operations on bot database tables
- Add ask_later keyword for pending info collection
- Add migration 6.1.1 with tables: pending_info, auto_tasks, execution_plans, task_approvals, task_decisions, safety_audit_log, generated_apps, intent_classifications, designer_changes
- Write apps to S3 drive and sync to SITE_ROOT for serving
- Clean URL structure: /apps/{app_name}/
- Integrate with DriveMonitor for file sync
Based on Chapter 17 - Autonomous Tasks specification
2025-12-27 21:10:09 -03:00
|
|
|
let post_id = save_scheduled_post(state, user, p, media, caption, scheduled_at)?;
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
post_ids.push(post_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(post_ids.join(","))
|
|
|
|
|
}
|
|
|
|
|
|
feat(autotask): Implement AutoTask system with intent classification and app generation
- Add IntentClassifier with 7 intent types (APP_CREATE, TODO, MONITOR, ACTION, SCHEDULE, GOAL, TOOL)
- Add AppGenerator with LLM-powered app structure analysis
- Add DesignerAI for modifying apps through conversation
- Add app_server for serving generated apps with clean URLs
- Add db_api for CRUD operations on bot database tables
- Add ask_later keyword for pending info collection
- Add migration 6.1.1 with tables: pending_info, auto_tasks, execution_plans, task_approvals, task_decisions, safety_audit_log, generated_apps, intent_classifications, designer_changes
- Write apps to S3 drive and sync to SITE_ROOT for serving
- Clean URL structure: /apps/{app_name}/
- Integrate with DriveMonitor for file sync
Based on Chapter 17 - Autonomous Tasks specification
2025-12-27 21:10:09 -03:00
|
|
|
fn save_scheduled_post(
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
state: &AppState,
|
|
|
|
|
user: &UserSession,
|
|
|
|
|
platform: &str,
|
|
|
|
|
media: &str,
|
|
|
|
|
caption: &str,
|
|
|
|
|
scheduled_at: DateTime<Utc>,
|
|
|
|
|
) -> Result<String, String> {
|
|
|
|
|
let mut conn = state.conn.get().map_err(|e| format!("DB error: {}", e))?;
|
|
|
|
|
|
|
|
|
|
let post_id = Uuid::new_v4().to_string();
|
|
|
|
|
let now = Utc::now();
|
|
|
|
|
|
|
|
|
|
let query = diesel::sql_query(
|
|
|
|
|
"INSERT INTO social_posts (id, bot_id, user_id, platform, content, media_url, status, scheduled_at, created_at)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, 'scheduled', $7, $8)",
|
|
|
|
|
)
|
|
|
|
|
.bind::<diesel::sql_types::Text, _>(&post_id)
|
|
|
|
|
.bind::<diesel::sql_types::Uuid, _>(user.bot_id)
|
|
|
|
|
.bind::<diesel::sql_types::Uuid, _>(user.user_id)
|
|
|
|
|
.bind::<diesel::sql_types::Text, _>(platform)
|
|
|
|
|
.bind::<diesel::sql_types::Text, _>(caption)
|
|
|
|
|
.bind::<diesel::sql_types::Text, _>(media)
|
|
|
|
|
.bind::<diesel::sql_types::Timestamptz, _>(&scheduled_at)
|
|
|
|
|
.bind::<diesel::sql_types::Timestamptz, _>(&now);
|
|
|
|
|
|
|
|
|
|
query.execute(&mut *conn).map_err(|e| {
|
|
|
|
|
error!("Failed to save scheduled post: {}", e);
|
|
|
|
|
format!("Failed to save scheduled post: {}", e)
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
|
"Scheduled post saved: {} to {} at {}",
|
|
|
|
|
post_id,
|
|
|
|
|
platform,
|
|
|
|
|
scheduled_at
|
|
|
|
|
);
|
|
|
|
|
Ok(post_id)
|
|
|
|
|
}
|