#![allow(clippy::all, unused_imports, dead_code)]
use crate::{Actor, ActorBehavior, Message, Port};
use anyhow::{Error, Result};
use reflow_actor::{message::EncodableValue, ActorContext};
use reflow_actor_macro::actor;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::time::Duration;
const BASE_URL: &str = "https://api.clickup.com/api/v2";
const ENV_KEY: &str = "CLICKUP_API_KEY";
fn apply_auth(
config: &reflow_actor::ActorConfig,
mut builder: reqwest::RequestBuilder,
) -> Result<reqwest::RequestBuilder> {
let credential = config
.get_config_or_env(ENV_KEY)
.ok_or_else(|| anyhow::anyhow!("Missing env var: {}", ENV_KEY))?;
builder = builder.header("Authorization", format!("Bearer {}", credential));
Ok(builder)
}
#[actor(
ClickupCreateTaskActor,
inports::<100>(list_id, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_task(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/list/{list_id}/task".to_string();
if let Some(val) = inputs.get("list_id") {
endpoint = endpoint.replace("{{list_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("POST /list/{{list_id}}/task failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
ClickupListTasksActor,
inports::<100>(list_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_list_tasks(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/list/{list_id}/task".to_string();
if let Some(val) = inputs.get("list_id") {
endpoint = endpoint.replace("{{list_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("GET /list/{{list_id}}/task failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
ClickupCreateAuditlogsActor,
inports::<100>(workspace_id, filter, applicability, pagination),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_auditlogs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/auditlogs".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("filter") {
body.insert("filter".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("applicability") {
body.insert("applicability".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pagination") {
body.insert("pagination".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"POST /api/v3/workspaces/{{workspace_id}}/auditlogs failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupReadChatChannelsActor,
inports::<100>(workspace_id, description_format, cursor, limit, is_follower, include_closed, with_message_since, channel_types),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_channels(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("description_format") {
query_pairs.push(("description_format", super::message_to_str(val)));
}
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("is_follower") {
query_pairs.push(("is_follower", super::message_to_str(val)));
}
if let Some(val) = inputs.get("include_closed") {
query_pairs.push(("include_closed", super::message_to_str(val)));
}
if let Some(val) = inputs.get("with_message_since") {
query_pairs.push(("with_message_since", super::message_to_str(val)));
}
if let Some(val) = inputs.get("channel_types") {
query_pairs.push(("channel_types", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /api/v3/workspaces/{{workspace_id}}/chat/channels failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupCreateChatChannelActor,
inports::<100>(workspace_id, visibility, name, topic, description, user_ids),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_chat_channel(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("visibility") {
body.insert("visibility".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("topic") {
body.insert("topic".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_ids") {
body.insert("user_ids".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"POST /api/v3/workspaces/{{workspace_id}}/chat/channels failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupCreateDirectMessageChatChannelActor,
inports::<100>(workspace_id, user_ids),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_direct_message_chat_channel(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels/direct_message".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("user_ids") {
body.insert("user_ids".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /api/v3/workspaces/{{workspace_id}}/chat/channels/direct_message failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupCreateLocationChatChannelActor,
inports::<100>(workspace_id, topic, description, visibility, user_ids, location),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_location_chat_channel(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels/location".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("topic") {
body.insert("topic".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("visibility") {
body.insert("visibility".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_ids") {
body.insert("user_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("location") {
body.insert("location".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /api/v3/workspaces/{{workspace_id}}/chat/channels/location failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupUpdateChatChannelActor,
inports::<100>(workspace_id, channel_id, topic, name, visibility, location, content_format, description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_update_chat_channel(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.patch(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("topic") {
body.insert("topic".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("visibility") {
body.insert("visibility".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("location") {
body.insert("location".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_format") {
body.insert("content_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("description") {
body.insert("description".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("PATCH /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupDeleteChatChannelActor,
inports::<100>(workspace_id, channel_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_delete_chat_channel(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatChannelActor,
inports::<100>(workspace_id, channel_id, description_format),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_channel(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("description_format") {
query_pairs.push(("description_format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatChannelFollowersActor,
inports::<100>(workspace_id, channel_id, cursor, limit),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_channel_followers(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}/followers".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}}/followers failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatChannelMembersActor,
inports::<100>(workspace_id, channel_id, cursor, limit),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_channel_members(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}/members".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}}/members failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatMessagesActor,
inports::<100>(workspace_id, channel_id, cursor, limit, content_format),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_messages(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}/messages".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("content_format") {
query_pairs.push(("content_format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}}/messages failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupCreateChatMessageActor,
inports::<100>(workspace_id, channel_id, post_data, followers, content, group_assignee, type_, assignee, triaged_action, reactions, content_format, triaged_object_type, triaged_object_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_chat_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/channels/{channel_id}/messages".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("channel_id") {
endpoint = endpoint.replace("{{channel_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("post_data") {
body.insert("post_data".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("followers") {
body.insert("followers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_assignee") {
body.insert("group_assignee".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("type_") {
body.insert("type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("assignee") {
body.insert("assignee".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("triaged_action") {
body.insert("triaged_action".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("reactions") {
body.insert("reactions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_format") {
body.insert("content_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("triaged_object_type") {
body.insert("triaged_object_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("triaged_object_id") {
body.insert("triaged_object_id".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /api/v3/workspaces/{{workspace_id}}/chat/channels/{{channel_id}}/messages failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupDeleteChatMessageActor,
inports::<100>(workspace_id, message_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_delete_chat_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupUpdateChatMessageActor,
inports::<100>(workspace_id, message_id, assignee, content_format, group_assignee, post_data, content, resolved),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_update_chat_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.patch(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("assignee") {
body.insert("assignee".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_format") {
body.insert("content_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_assignee") {
body.insert("group_assignee".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("post_data") {
body.insert("post_data".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resolved") {
body.insert("resolved".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("PATCH /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatMessageReactionsActor,
inports::<100>(workspace_id, message_id, cursor, limit),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_message_reactions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}/reactions".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}}/reactions failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupCreateChatReactionActor,
inports::<100>(workspace_id, message_id, reaction),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_chat_reaction(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}/reactions".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("reaction") {
body.insert("reaction".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}}/reactions failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupDeleteChatReactionActor,
inports::<100>(workspace_id, message_id, reaction),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_delete_chat_reaction(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}/reactions/{reaction}"
.to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("reaction") {
endpoint = endpoint.replace("{{reaction}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}}/reactions/{{reaction}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupCreateReplyMessageActor,
inports::<100>(workspace_id, message_id, triaged_object_id, reactions, assignee, followers, content, triaged_action, post_data, triaged_object_type, content_format, type_, group_assignee),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_reply_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}/replies".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("triaged_object_id") {
body.insert("triaged_object_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("reactions") {
body.insert("reactions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("assignee") {
body.insert("assignee".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("followers") {
body.insert("followers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("triaged_action") {
body.insert("triaged_action".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("post_data") {
body.insert("post_data".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("triaged_object_type") {
body.insert("triaged_object_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_format") {
body.insert("content_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("type_") {
body.insert("type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_assignee") {
body.insert("group_assignee".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}}/replies failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatMessageRepliesActor,
inports::<100>(workspace_id, message_id, cursor, limit, content_format),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_message_replies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}/replies".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("content_format") {
query_pairs.push(("content_format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}}/replies failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadChatMessageTaggedUsersActor,
inports::<100>(workspace_id, message_id, cursor, limit),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_chat_message_tagged_users(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/chat/messages/{message_id}/tagged_users".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("message_id") {
endpoint = endpoint.replace("{{message_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/chat/messages/{{message_id}}/tagged_users failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadSubtypesActor,
inports::<100>(workspace_id, comment_type),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_subtypes(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/comments/types/{comment_type}/subtypes".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("comment_type") {
endpoint = endpoint.replace("{{comment_type}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/comments/types/{{comment_type}}/subtypes failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupCreateDocPublicActor,
inports::<100>(workspace_id, create_page, name, parent, visibility),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_doc_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/docs".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("create_page") {
body.insert("create_page".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("parent") {
body.insert("parent".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("visibility") {
body.insert("visibility".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"POST /api/v3/workspaces/{{workspace_id}}/docs failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupSearchDocsPublicActor,
inports::<100>(workspace_id, id, creator, deleted, archived, parent_id, parent_type, limit, cursor, next_cursor),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_search_docs_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/docs".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("id") {
query_pairs.push(("id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("creator") {
query_pairs.push(("creator", super::message_to_str(val)));
}
if let Some(val) = inputs.get("deleted") {
query_pairs.push(("deleted", super::message_to_str(val)));
}
if let Some(val) = inputs.get("archived") {
query_pairs.push(("archived", super::message_to_str(val)));
}
if let Some(val) = inputs.get("parent_id") {
query_pairs.push(("parent_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("parent_type") {
query_pairs.push(("parent_type", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("next_cursor") {
query_pairs.push(("next_cursor", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!("GET /api/v3/workspaces/{{workspace_id}}/docs failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupReadDocPublicActor,
inports::<100>(workspace_id, doc_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_doc_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/docs/{doc_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("doc_id") {
endpoint = endpoint.replace("{{doc_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /api/v3/workspaces/{{workspace_id}}/docs/{{doc_id}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupReadDocPageListingPublicActor,
inports::<100>(workspace_id, doc_id, max_page_depth),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_doc_page_listing_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/docs/{doc_id}/page_listing".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("doc_id") {
endpoint = endpoint.replace("{{doc_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("max_page_depth") {
query_pairs.push(("max_page_depth", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/docs/{{doc_id}}/page_listing failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadDocPagesPublicActor,
inports::<100>(workspace_id, doc_id, max_page_depth, content_format),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_doc_pages_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/docs/{doc_id}/pages".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("doc_id") {
endpoint = endpoint.replace("{{doc_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("max_page_depth") {
query_pairs.push(("max_page_depth", super::message_to_str(val)));
}
if let Some(val) = inputs.get("content_format") {
query_pairs.push(("content_format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /api/v3/workspaces/{{workspace_id}}/docs/{{doc_id}}/pages failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupCreatePagePublicActor,
inports::<100>(workspace_id, doc_id, name, sub_title, content, parent_page_id, content_format),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_page_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/v3/workspaces/{workspace_id}/docs/{doc_id}/pages".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("doc_id") {
endpoint = endpoint.replace("{{doc_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sub_title") {
body.insert("sub_title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("parent_page_id") {
body.insert("parent_page_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_format") {
body.insert("content_format".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"POST /api/v3/workspaces/{{workspace_id}}/docs/{{doc_id}}/pages failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
ClickupReadPagePublicActor,
inports::<100>(workspace_id, doc_id, page_id, content_format),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_page_public(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/docs/{doc_id}/pages/{page_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("doc_id") {
endpoint = endpoint.replace("{{doc_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("page_id") {
endpoint = endpoint.replace("{{page_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("content_format") {
query_pairs.push(("content_format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/docs/{{doc_id}}/pages/{{page_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupUpdateDocsActor,
inports::<100>(workspace_id, doc_id, page_id, sub_title, name, content, content_format, content_edit_mode),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_update_docs(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/docs/{doc_id}/pages/{page_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("doc_id") {
endpoint = endpoint.replace("{{doc_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("page_id") {
endpoint = endpoint.replace("{{page_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("sub_title") {
body.insert("sub_title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_format") {
body.insert("content_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content_edit_mode") {
body.insert("content_edit_mode".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("PUT /api/v3/workspaces/{{workspace_id}}/docs/{{doc_id}}/pages/{{page_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupUpdateTasksActor,
inports::<100>(workspace_id, task_id, list_id, move_custom_fields, status_mappings, custom_fields_to_move),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_update_tasks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/tasks/{task_id}/home_list/{list_id}".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("task_id") {
endpoint = endpoint.replace("{{task_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("list_id") {
endpoint = endpoint.replace("{{list_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("move_custom_fields") {
body.insert("move_custom_fields".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status_mappings") {
body.insert("status_mappings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("custom_fields_to_move") {
body.insert("custom_fields_to_move".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("PUT /api/v3/workspaces/{{workspace_id}}/tasks/{{task_id}}/home_list/{{list_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupUpdateTimeEstimatesByUserActor,
inports::<100>(workspace_id, task_id, body),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_update_time_estimates_by_user(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/tasks/{task_id}/time_estimates_by_user".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("task_id") {
endpoint = endpoint.replace("{{task_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.patch(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("body") {
body.insert("body".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("PATCH /api/v3/workspaces/{{workspace_id}}/tasks/{{task_id}}/time_estimates_by_user failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupReadParentEntityAttachmentsActor,
inports::<100>(workspace_id, entity_type, entity_id, cursor, limit),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_read_parent_entity_attachments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/{entity_type}/{entity_id}/attachments".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("entity_type") {
endpoint = endpoint.replace("{{entity_type}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("entity_id") {
endpoint = endpoint.replace("{{entity_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("cursor") {
query_pairs.push(("cursor", super::message_to_str(val)));
}
if let Some(val) = inputs.get("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /api/v3/workspaces/{{workspace_id}}/{{entity_type}}/{{entity_id}}/attachments failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupCreateEntityAttachmentActor,
inports::<100>(workspace_id, entity_type, entity_id, filename),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_create_entity_attachment(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/{entity_type}/{entity_id}/attachments".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("entity_type") {
endpoint = endpoint.replace("{{entity_type}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("entity_id") {
endpoint = endpoint.replace("{{entity_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("filename") {
body.insert("filename".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /api/v3/workspaces/{{workspace_id}}/{{entity_type}}/{{entity_id}}/attachments failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
ClickupUpdateAclsActor,
inports::<100>(workspace_id, object_type, object_id, entries, private),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn clickup_update_acls(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/v3/workspaces/{workspace_id}/{object_type}/{object_id}/acls".to_string();
if let Some(val) = inputs.get("workspace_id") {
endpoint = endpoint.replace("{{workspace_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("object_type") {
endpoint = endpoint.replace("{{object_type}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("object_id") {
endpoint = endpoint.replace("{{object_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.patch(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("entries") {
body.insert("entries".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("private") {
body.insert("private".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("PATCH /api/v3/workspaces/{{workspace_id}}/{{object_type}}/{{object_id}}/acls failed: {}", e).into()));
}
}
Ok(output)
}