#![allow(clippy::all, unused_imports, dead_code)]
//! Auto-generated API actors for PostHog
//!
//! Service: PostHog (posthog)
//! Open-source product analytics platform
//!
//! Required env var: POSTHOG_API_KEY (Bearer token)
//!
//! Generated by api-schema-gen codegen — do not edit manually.
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://app.posthog.com/api";
const ENV_KEY: &str = "POSTHOG_API_KEY";
/// Apply authentication to the request builder.
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)
}
/// send event via PostHog API
///
/// Method: POST /capture/
#[actor(
PosthogSendEventActor,
inports::<100>(event, distinct_id, properties),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_send_event(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/capture/".to_string();
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("event") {
body.insert("event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("distinct_id") {
body.insert("distinct_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("properties") {
body.insert("properties".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 /capture/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// read events via PostHog API
///
/// Method: GET /projects/{project_id}/events/
#[actor(
PosthogReadEventsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_events(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/projects/{project_id}/events/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 /projects/{{project_id}}/events/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Check access
///
/// Method: GET /api/code/invites/check-access/
#[actor(
PosthogListCodeInvitesActor,
inports::<100>(trigger),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_list_code_invites(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/api/code/invites/check-access/".to_string();
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/code/invites/check-access/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Redeem invite code
///
/// Method: POST /api/code/invites/redeem/
#[actor(
PosthogCreateCodeInvitesActor,
inports::<100>(code),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_code_invites(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/api/code/invites/redeem/".to_string();
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("code") {
body.insert("code".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/code/invites/redeem/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Unified endpoint that handles both conversation creation and streaming.\n\n- If message is provided: Start new conversation processing\n- If no message: Stream from existing conversation
///
/// Method: POST /api/environments/{project_id}/conversations/
#[actor(
PosthogCreateMaxActor,
inports::<100>(project_id, content, conversation, is_sandbox, trace_id, ui_context, session_id, agent_mode, resume_payload, contextual_tools, billing_context),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_max(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/conversations/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("content") {
body.insert("content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversation") {
body.insert("conversation".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_sandbox") {
body.insert("is_sandbox".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("trace_id") {
body.insert("trace_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ui_context") {
body.insert("ui_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_id") {
body.insert("session_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("agent_mode") {
body.insert("agent_mode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resume_payload") {
body.insert("resume_payload".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("contextual_tools") {
body.insert("contextual_tools".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("billing_context") {
body.insert("billing_context".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/environments/{{project_id}}/conversations/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read max
///
/// Method: GET /api/environments/{project_id}/conversations/
#[actor(
PosthogReadMaxActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_max(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/conversations/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/conversations/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// cancel max
///
/// Method: PATCH /api/environments/{project_id}/conversations/{conversation}/cancel/
#[actor(
PosthogCancelMaxActor,
inports::<100>(conversation, project_id, agent_mode, slack_workspace_domain, status, title, updated_at, user, has_unsupported_content, messages, is_sandbox, pending_approvals, type_, created_at, slack_thread_key, id, is_internal),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_cancel_max(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/conversations/{conversation}/cancel/".to_string();
if let Some(val) = inputs.get("conversation") {
endpoint = endpoint.replace("{{conversation}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("agent_mode") {
body.insert("agent_mode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_workspace_domain") {
body.insert("slack_workspace_domain".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user") {
body.insert("user".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_unsupported_content") {
body.insert("has_unsupported_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("messages") {
body.insert("messages".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_sandbox") {
body.insert("is_sandbox".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pending_approvals") {
body.insert("pending_approvals".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_thread_key") {
body.insert("slack_thread_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_internal") {
body.insert("is_internal".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/environments/{{project_id}}/conversations/{{conversation}}/cancel/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update max
///
/// Method: PATCH /api/environments/{project_id}/conversations/{conversation}/queue/{queue_id}/
#[actor(
PosthogUpdateMaxActor,
inports::<100>(conversation, project_id, queue_id, updated_at, is_sandbox, is_internal, created_at, user, title, slack_workspace_domain, type_, status, id, agent_mode, messages, pending_approvals, slack_thread_key, has_unsupported_content),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_max(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/conversations/{conversation}/queue/{queue_id}/".to_string();
if let Some(val) = inputs.get("conversation") {
endpoint = endpoint.replace("{{conversation}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("queue_id") {
endpoint = endpoint.replace("{{queue_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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_sandbox") {
body.insert("is_sandbox".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_internal") {
body.insert("is_internal".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user") {
body.insert("user".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_workspace_domain") {
body.insert("slack_workspace_domain".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("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("agent_mode") {
body.insert("agent_mode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("messages") {
body.insert("messages".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pending_approvals") {
body.insert("pending_approvals".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_thread_key") {
body.insert("slack_thread_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_unsupported_content") {
body.insert("has_unsupported_content".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/environments/{{project_id}}/conversations/{{conversation}}/queue/{{queue_id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete max
///
/// Method: DELETE /api/environments/{project_id}/conversations/{conversation}/queue/{queue_id}/
#[actor(
PosthogDeleteMaxActor,
inports::<100>(conversation, project_id, queue_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_max(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/conversations/{conversation}/queue/{queue_id}/".to_string();
if let Some(val) = inputs.get("conversation") {
endpoint = endpoint.replace("{{conversation}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("queue_id") {
endpoint = endpoint.replace("{{queue_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/environments/{{project_id}}/conversations/{{conversation}}/queue/{{queue_id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read customer profile configs
///
/// Method: GET /api/environments/{project_id}/customer_profile_configs/
#[actor(
PosthogReadCustomerProfileConfigsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_customer_profile_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/customer_profile_configs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/customer_profile_configs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create customer profile configs
///
/// Method: POST /api/environments/{project_id}/customer_profile_configs/
#[actor(
PosthogCreateCustomerProfileConfigsActor,
inports::<100>(project_id, scope, created_at, updated_at, id, sidebar, content),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_customer_profile_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/customer_profile_configs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("scope") {
body.insert("scope".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sidebar") {
body.insert("sidebar".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".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/environments/{{project_id}}/customer_profile_configs/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete customer profile configs
///
/// Method: DELETE /api/environments/{project_id}/customer_profile_configs/{id}/
#[actor(
PosthogDeleteCustomerProfileConfigsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_customer_profile_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/customer_profile_configs/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/customer_profile_configs/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update customer profile configs
///
/// Method: PUT /api/environments/{project_id}/customer_profile_configs/{id}/
#[actor(
PosthogUpdateCustomerProfileConfigsActor,
inports::<100>(id, project_id, updated_at, created_at, content, scope, sidebar),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_customer_profile_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/customer_profile_configs/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("scope") {
body.insert("scope".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sidebar") {
body.insert("sidebar".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("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!("PUT /api/environments/{{project_id}}/customer_profile_configs/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read dashboards
///
/// Method: GET /api/environments/{project_id}/dashboards/{dashboard_id}/collaborators/
#[actor(
PosthogReadDashboardsActor,
inports::<100>(dashboard_id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_dashboards(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/dashboards/{dashboard_id}/collaborators/".to_string();
if let Some(val) = inputs.get("dashboard_id") {
endpoint = endpoint.replace("{{dashboard_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/dashboards/{{dashboard_id}}/collaborators/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create dashboards
///
/// Method: POST /api/environments/{project_id}/dashboards/{dashboard_id}/collaborators/
#[actor(
PosthogCreateDashboardsActor,
inports::<100>(dashboard_id, project_id, user, added_at, user_uuid, id, level, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_dashboards(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/dashboards/{dashboard_id}/collaborators/".to_string();
if let Some(val) = inputs.get("dashboard_id") {
endpoint = endpoint.replace("{{dashboard_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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") {
body.insert("user".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("added_at") {
body.insert("added_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_uuid") {
body.insert("user_uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dashboard_id") {
body.insert("dashboard_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("level") {
body.insert("level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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/environments/{{project_id}}/dashboards/{{dashboard_id}}/collaborators/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete dashboards
///
/// Method: DELETE /api/environments/{project_id}/dashboards/{dashboard_id}/collaborators/{user__uuid}/
#[actor(
PosthogDeleteDashboardsActor,
inports::<100>(dashboard_id, project_id, user_uuid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_dashboards(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/dashboards/{dashboard_id}/collaborators/{user__uuid}/"
.to_string();
if let Some(val) = inputs.get("dashboard_id") {
endpoint = endpoint.replace("{{dashboard_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("user_uuid") {
endpoint = endpoint.replace("{{user__uuid}}", &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/environments/{{project_id}}/dashboards/{{dashboard_id}}/collaborators/{{user__uuid}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// RESTful API for managing desktop meeting recordings.\n\nStandard CRUD operations plus transcript management as a subresource.
///
/// Method: GET /api/environments/{project_id}/desktop_recordings/
#[actor(
PosthogReadDesktopRecordingsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_desktop_recordings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/desktop_recordings/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/desktop_recordings/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create a new recording and get Recall.ai upload token for the desktop SDK
///
/// Method: POST /api/environments/{project_id}/desktop_recordings/
#[actor(
PosthogCreateDesktopRecordingsActor,
inports::<100>(project_id, platform),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_desktop_recordings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/desktop_recordings/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("platform") {
body.insert("platform".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/environments/{{project_id}}/desktop_recordings/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// RESTful API for managing desktop meeting recordings.\n\nStandard CRUD operations plus transcript management as a subresource.
///
/// Method: PUT /api/environments/{project_id}/desktop_recordings/{id}/
#[actor(
PosthogUpdateDesktopRecordingsActor,
inports::<100>(id, project_id, created_by, created_at, platform, summary, sdk_upload_id, recall_recording_id, duration_seconds, completed_at, meeting_title, meeting_url, summary_generated_at, started_at, error_message, team, notes, participants, transcript_segments, transcript_text, video_size_bytes, extracted_tasks, tasks_generated_at, video_url, updated_at, status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_desktop_recordings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/desktop_recordings/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("platform") {
body.insert("platform".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("summary") {
body.insert("summary".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sdk_upload_id") {
body.insert("sdk_upload_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recall_recording_id") {
body.insert("recall_recording_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("duration_seconds") {
body.insert("duration_seconds".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("completed_at") {
body.insert("completed_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("meeting_title") {
body.insert("meeting_title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("meeting_url") {
body.insert("meeting_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("summary_generated_at") {
body.insert("summary_generated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("started_at") {
body.insert("started_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("error_message") {
body.insert("error_message".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("team") {
body.insert("team".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("notes") {
body.insert("notes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("participants") {
body.insert("participants".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("transcript_segments") {
body.insert("transcript_segments".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("transcript_text") {
body.insert("transcript_text".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("video_size_bytes") {
body.insert("video_size_bytes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extracted_tasks") {
body.insert("extracted_tasks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tasks_generated_at") {
body.insert("tasks_generated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("video_url") {
body.insert("video_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".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/environments/{{project_id}}/desktop_recordings/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// RESTful API for managing desktop meeting recordings.\n\nStandard CRUD operations plus transcript management as a subresource.
///
/// Method: DELETE /api/environments/{project_id}/desktop_recordings/{id}/
#[actor(
PosthogDeleteDesktopRecordingsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_desktop_recordings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/desktop_recordings/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/desktop_recordings/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create error tracking
///
/// Method: POST /api/environments/{project_id}/error_tracking/assignment_rules/
#[actor(
PosthogCreateErrorTrackingActor,
inports::<100>(project_id, assignee, id, filters, order_key, disabled_data),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/assignment_rules/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("assignee") {
body.insert("assignee".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("order_key") {
body.insert("order_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("disabled_data") {
body.insert("disabled_data".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/environments/{{project_id}}/error_tracking/assignment_rules/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read error tracking
///
/// Method: GET /api/environments/{project_id}/error_tracking/assignment_rules/
#[actor(
PosthogReadErrorTrackingActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/assignment_rules/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/error_tracking/assignment_rules/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update error tracking
///
/// Method: PATCH /api/environments/{project_id}/error_tracking/assignment_rules/reorder/
#[actor(
PosthogUpdateErrorTrackingActor,
inports::<100>(project_id, id, order_key, disabled_data, assignee, filters),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/assignment_rules/reorder/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("order_key") {
body.insert("order_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("disabled_data") {
body.insert("disabled_data".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("filters") {
body.insert("filters".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/environments/{{project_id}}/error_tracking/assignment_rules/reorder/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete error tracking
///
/// Method: DELETE /api/environments/{project_id}/error_tracking/assignment_rules/{id}/
#[actor(
PosthogDeleteErrorTrackingActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/assignment_rules/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/error_tracking/assignment_rules/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// assign error tracking
///
/// Method: PATCH /api/environments/{project_id}/error_tracking/issues/{id}/assign/
#[actor(
PosthogAssignErrorTrackingActor,
inports::<100>(id, project_id, name, status, assignee, first_seen, cohort, external_issues, description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_assign_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/issues/{id}/assign/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("first_seen") {
body.insert("first_seen".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cohort") {
body.insert("cohort".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_issues") {
body.insert("external_issues".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/environments/{{project_id}}/error_tracking/issues/{{id}}/assign/ failed: {}", e).into()));
}
}
Ok(output)
}
/// merge error tracking
///
/// Method: POST /api/environments/{project_id}/error_tracking/issues/{id}/merge/
#[actor(
PosthogMergeErrorTrackingActor,
inports::<100>(id, project_id, status, external_issues, name, first_seen, cohort, description, assignee),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_merge_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/issues/{id}/merge/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_issues") {
body.insert("external_issues".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("first_seen") {
body.insert("first_seen".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cohort") {
body.insert("cohort".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("assignee") {
body.insert("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/environments/{{project_id}}/error_tracking/issues/{{id}}/merge/ failed: {}", e).into()));
}
}
Ok(output)
}
/// split error tracking
///
/// Method: POST /api/environments/{project_id}/error_tracking/issues/{id}/split/
#[actor(
PosthogSplitErrorTrackingActor,
inports::<100>(id, project_id, external_issues, name, assignee, cohort, description, first_seen, status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_split_error_tracking(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/error_tracking/issues/{id}/split/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("external_issues") {
body.insert("external_issues".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("id") {
body.insert("id".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("cohort") {
body.insert("cohort".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("first_seen") {
body.insert("first_seen".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".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/environments/{{project_id}}/error_tracking/issues/{{id}}/split/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new evaluation run.\n\nThis endpoint validates the request and enqueues a Temporal workflow\nto asynchronously execute the evaluation.
///
/// Method: POST /api/environments/{project_id}/evaluation_runs/
#[actor(
PosthogCreateEvaluationRunsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_evaluation_runs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/evaluation_runs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 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/environments/{{project_id}}/evaluation_runs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read evaluations
///
/// Method: GET /api/environments/{project_id}/evaluations/
#[actor(
PosthogReadEvaluationsActor,
inports::<100>(enabled, id_in, limit, offset, order_by, project_id, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_evaluations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/evaluations/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("enabled") {
query_pairs.push(("enabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("id_in") {
query_pairs.push(("id__in", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("order_by") {
query_pairs.push(("order_by", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/environments/{{project_id}}/evaluations/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create evaluations
///
/// Method: POST /api/environments/{project_id}/evaluations/
#[actor(
PosthogCreateEvaluationsActor,
inports::<100>(project_id, updated_at, evaluation_config, evaluation_type, name, id, output_config, created_at, model_configuration, created_by, output_type, description, conditions, deleted, enabled),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_evaluations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/evaluations/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_config") {
body.insert("evaluation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_type") {
body.insert("evaluation_type".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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("output_config") {
body.insert("output_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("model_configuration") {
body.insert("model_configuration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("output_type") {
body.insert("output_type".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("conditions") {
body.insert("conditions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".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/environments/{{project_id}}/evaluations/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/environments/{project_id}/evaluations/{id}/
#[actor(
PosthogDeleteEvaluationsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_evaluations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/evaluations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/evaluations/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update evaluations
///
/// Method: PATCH /api/environments/{project_id}/evaluations/{id}/
#[actor(
PosthogUpdateEvaluationsActor,
inports::<100>(id, project_id, name, conditions, description, evaluation_config, created_by, model_configuration, evaluation_type, created_at, deleted, enabled, output_config, output_type, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_evaluations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/evaluations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conditions") {
body.insert("conditions".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("evaluation_config") {
body.insert("evaluation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("model_configuration") {
body.insert("model_configuration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_type") {
body.insert("evaluation_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("output_config") {
body.insert("output_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("output_type") {
body.insert("output_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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/environments/{{project_id}}/evaluations/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read health issues
///
/// Method: GET /api/environments/{project_id}/health_issues/
#[actor(
PosthogReadHealthIssuesActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_health_issues(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/health_issues/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/health_issues/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update health issues
///
/// Method: PATCH /api/environments/{project_id}/health_issues/{id}/
#[actor(
PosthogUpdateHealthIssuesActor,
inports::<100>(id, project_id, kind, created_at, updated_at, payload, resolved_at, status, dismissed, severity),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_health_issues(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/health_issues/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("kind") {
body.insert("kind".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("payload") {
body.insert("payload".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resolved_at") {
body.insert("resolved_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dismissed") {
body.insert("dismissed".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("severity") {
body.insert("severity".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/environments/{{project_id}}/health_issues/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create health issues
///
/// Method: POST /api/environments/{project_id}/health_issues/{id}/resolve/
#[actor(
PosthogCreateHealthIssuesActor,
inports::<100>(id, project_id, severity, kind, resolved_at, status, created_at, dismissed, updated_at, payload),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_health_issues(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/health_issues/{id}/resolve/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("severity") {
body.insert("severity".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("kind") {
body.insert("kind".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resolved_at") {
body.insert("resolved_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dismissed") {
body.insert("dismissed".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("payload") {
body.insert("payload".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/environments/{{project_id}}/health_issues/{{id}}/resolve/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Get the evaluation config for this team
///
/// Method: GET /api/environments/{project_id}/llm_analytics/evaluation_config/
#[actor(
PosthogReadLlmAnalyticsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/llm_analytics/evaluation_config/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/llm_analytics/evaluation_config/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Set the active provider key for evaluations
///
/// Method: POST /api/environments/{project_id}/llm_analytics/evaluation_config/set_active_key/
#[actor(
PosthogCreateLlmAnalyticsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/llm_analytics/evaluation_config/set_active_key/"
.to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 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/environments/{{project_id}}/llm_analytics/evaluation_config/set_active_key/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update llm analytics
///
/// Method: PATCH /api/environments/{project_id}/llm_analytics/provider_keys/{id}/
#[actor(
PosthogUpdateLlmAnalyticsActor,
inports::<100>(id, project_id, provider, error_message, api_key, created_at, name, created_by, last_used_at, set_as_active, state, api_key_masked),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/llm_analytics/provider_keys/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("provider") {
body.insert("provider".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("error_message") {
body.insert("error_message".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_key") {
body.insert("api_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_used_at") {
body.insert("last_used_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("set_as_active") {
body.insert("set_as_active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_key_masked") {
body.insert("api_key_masked".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/environments/{{project_id}}/llm_analytics/provider_keys/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete llm analytics
///
/// Method: DELETE /api/environments/{project_id}/llm_analytics/provider_keys/{id}/
#[actor(
PosthogDeleteLlmAnalyticsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/llm_analytics/provider_keys/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/llm_analytics/provider_keys/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// validate llm analytics
///
/// Method: POST /api/environments/{project_id}/llm_analytics/provider_keys/{id}/validate/
#[actor(
PosthogValidateLlmAnalyticsActor,
inports::<100>(id, project_id, set_as_active, last_used_at, state, api_key, provider, created_at, created_by, error_message, api_key_masked, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_validate_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/llm_analytics/provider_keys/{id}/validate/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("set_as_active") {
body.insert("set_as_active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_used_at") {
body.insert("last_used_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_key") {
body.insert("api_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("provider") {
body.insert("provider".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("error_message") {
body.insert("error_message".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_key_masked") {
body.insert("api_key_masked".to_string(), val.clone().into());
}
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 /api/environments/{{project_id}}/llm_analytics/provider_keys/{{id}}/validate/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Translate text to target language.
///
/// Method: POST /api/environments/{project_id}/llm_analytics/translate/
#[actor(
PosthogTranslateLlmAnalyticsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_translate_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/llm_analytics/translate/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 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/environments/{{project_id}}/llm_analytics/translate/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// archive llm analytics
///
/// Method: POST /api/environments/{project_id}/llm_prompts/name/{prompt_name}/archive/
#[actor(
PosthogArchiveLlmAnalyticsActor,
inports::<100>(project_id, prompt_name, id, deleted, name, created_by, version, latest_version, version_count, is_latest, first_version_created_at, prompt, created_at, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_archive_llm_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/llm_prompts/name/{prompt_name}/archive/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("prompt_name") {
endpoint = endpoint.replace("{{prompt_name}}", &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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_version") {
body.insert("latest_version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version_count") {
body.insert("version_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_latest") {
body.insert("is_latest".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("first_version_created_at") {
body.insert("first_version_created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("prompt") {
body.insert("prompt".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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/environments/{{project_id}}/llm_prompts/name/{{prompt_name}}/archive/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Explain a log entry using AI.\n\nPOST /api/environments/:id/logs/explainLogWithAI/
///
/// Method: POST /api/environments/{project_id}/logs/explainLogWithAI/
#[actor(
PosthogCreateLogsActor,
inports::<100>(project_id, force_refresh, timestamp, uuid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_logs(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/logs/explainLogWithAI/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("force_refresh") {
body.insert("force_refresh".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timestamp") {
body.insert("timestamp".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".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/environments/{{project_id}}/logs/explainLogWithAI/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create max tools
///
/// Method: POST /api/environments/{project_id}/max_tools/create_and_query_insight/
#[actor(
PosthogCreateMaxToolsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_max_tools(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/max_tools/create_and_query_insight/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 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/environments/{{project_id}}/max_tools/create_and_query_insight/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read mcp store
///
/// Method: GET /api/environments/{project_id}/mcp_server_installations/
#[actor(
PosthogReadMcpStoreActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_mcp_store(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/mcp_server_installations/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/mcp_server_installations/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create mcp store
///
/// Method: POST /api/environments/{project_id}/mcp_server_installations/
#[actor(
PosthogCreateMcpStoreActor,
inports::<100>(project_id, server_id, is_enabled, description, id, created_at, name, display_name, needs_reauth, updated_at, auth_type, url, pending_oauth, proxy_url),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_mcp_store(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/mcp_server_installations/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("server_id") {
body.insert("server_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_enabled") {
body.insert("is_enabled".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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("display_name") {
body.insert("display_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("needs_reauth") {
body.insert("needs_reauth".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("auth_type") {
body.insert("auth_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("url") {
body.insert("url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pending_oauth") {
body.insert("pending_oauth".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proxy_url") {
body.insert("proxy_url".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/environments/{{project_id}}/mcp_server_installations/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update mcp store
///
/// Method: PUT /api/environments/{project_id}/mcp_server_installations/{id}/
#[actor(
PosthogUpdateMcpStoreActor,
inports::<100>(id, project_id, auth_type, description, display_name, needs_reauth, pending_oauth, proxy_url, server_id, updated_at, url, name, created_at, is_enabled),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_mcp_store(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/mcp_server_installations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("auth_type") {
body.insert("auth_type".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("display_name") {
body.insert("display_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("needs_reauth") {
body.insert("needs_reauth".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pending_oauth") {
body.insert("pending_oauth".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proxy_url") {
body.insert("proxy_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("server_id") {
body.insert("server_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("url") {
body.insert("url".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_enabled") {
body.insert("is_enabled".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/environments/{{project_id}}/mcp_server_installations/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete mcp store
///
/// Method: DELETE /api/environments/{project_id}/mcp_server_installations/{id}/
#[actor(
PosthogDeleteMcpStoreActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_mcp_store(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/mcp_server_installations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/mcp_server_installations/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Invoke an MCP tool by name.\n\nThis endpoint allows MCP callers to invoke Max AI tools directly\nwithout going through the full LangChain conversation flow.\n\nScopes are resolved dynamically per tool via dangerously_get_required_scopes.
///
/// Method: POST /api/environments/{project_id}/mcp_tools/{tool_name}/
#[actor(
PosthogCreateMcpToolsActor,
inports::<100>(project_id, tool_name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_mcp_tools(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/mcp_tools/{tool_name}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("tool_name") {
endpoint = endpoint.replace("{{tool_name}}", &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 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/environments/{{project_id}}/mcp_tools/{{tool_name}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Generate AI summary for a group of session recordings to find patterns and generate a notebook.
///
/// Method: POST /api/environments/{project_id}/session_summaries/create_session_summaries/
#[actor(
PosthogCreateSessionSummariesActor,
inports::<100>(project_id, session_ids, focus_area),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_session_summaries(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/session_summaries/create_session_summaries/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("session_ids") {
body.insert("session_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("focus_area") {
body.insert("focus_area".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/environments/{{project_id}}/session_summaries/create_session_summaries/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Generate AI individual summary for each session, without grouping.
///
/// Method: POST /api/environments/{project_id}/session_summaries/create_session_summaries_individually/
#[actor(
PosthogCreateSessionSummariesIndividuallyActor,
inports::<100>(project_id, focus_area, session_ids),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_session_summaries_individually(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/environments/{project_id}/session_summaries/create_session_summaries_individually/"
.to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("focus_area") {
body.insert("focus_area".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_ids") {
body.insert("session_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/environments/{{project_id}}/session_summaries/create_session_summaries_individually/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create user interviews
///
/// Method: POST /api/environments/{project_id}/user_interviews/
#[actor(
PosthogCreateUserInterviewsActor,
inports::<100>(project_id, audio, created_by, created_at, interviewee_emails, id, summary, transcript),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_user_interviews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/user_interviews/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("audio") {
body.insert("audio".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("interviewee_emails") {
body.insert("interviewee_emails".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("summary") {
body.insert("summary".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("transcript") {
body.insert("transcript".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/environments/{{project_id}}/user_interviews/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read user interviews
///
/// Method: GET /api/environments/{project_id}/user_interviews/
#[actor(
PosthogReadUserInterviewsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_user_interviews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/user_interviews/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/environments/{{project_id}}/user_interviews/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update user interviews
///
/// Method: PATCH /api/environments/{project_id}/user_interviews/{id}/
#[actor(
PosthogUpdateUserInterviewsActor,
inports::<100>(id, project_id, created_by, interviewee_emails, created_at, audio, transcript, summary),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_user_interviews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/user_interviews/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("interviewee_emails") {
body.insert("interviewee_emails".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("audio") {
body.insert("audio".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("transcript") {
body.insert("transcript".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("summary") {
body.insert("summary".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/environments/{{project_id}}/user_interviews/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete user interviews
///
/// Method: DELETE /api/environments/{project_id}/user_interviews/{id}/
#[actor(
PosthogDeleteUserInterviewsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_user_interviews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/user_interviews/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/environments/{{project_id}}/user_interviews/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Get web vitals for a specific pathname.\nToolbar accesses this via OAuth (handled by TeamAndOrgViewSetMixin.get_authenticators).
///
/// Method: GET /api/environments/{project_id}/web_vitals/
#[actor(
PosthogReadWebVitalsActor,
inports::<100>(pathname, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_web_vitals(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/environments/{project_id}/web_vitals/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("pathname") {
query_pairs.push(("pathname", 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/environments/{{project_id}}/web_vitals/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create organizations
///
/// Method: POST /api/organizations/
#[actor(
PosthogCreateOrganizationsActor,
inports::<100>(created_at, available_product_features, default_anonymize_ips, membership_level, is_active, is_ai_data_processing_approved, default_experiment_stats_method, name, slug, is_member_join_email_enabled, default_role_id, projects, teams, logo_media_id, customer_id, allow_publicly_shared_resources, members_can_invite, members_can_use_personal_api_keys, id, is_not_active_reason, metadata, plugins_access_level, updated_at, member_count, enforce_2fa),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_organizations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/api/organizations/".to_string();
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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("available_product_features") {
body.insert("available_product_features".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_anonymize_ips") {
body.insert("default_anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("membership_level") {
body.insert("membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_active") {
body.insert("is_active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_ai_data_processing_approved") {
body.insert(
"is_ai_data_processing_approved".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_experiment_stats_method") {
body.insert(
"default_experiment_stats_method".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("slug") {
body.insert("slug".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_member_join_email_enabled") {
body.insert(
"is_member_join_email_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_role_id") {
body.insert("default_role_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("projects") {
body.insert("projects".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("teams") {
body.insert("teams".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logo_media_id") {
body.insert("logo_media_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("customer_id") {
body.insert("customer_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("allow_publicly_shared_resources") {
body.insert(
"allow_publicly_shared_resources".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("members_can_invite") {
body.insert("members_can_invite".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("members_can_use_personal_api_keys") {
body.insert(
"members_can_use_personal_api_keys".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_not_active_reason") {
body.insert("is_not_active_reason".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("metadata") {
body.insert("metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("plugins_access_level") {
body.insert("plugins_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("member_count") {
body.insert("member_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enforce_2fa") {
body.insert("enforce_2fa".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/organizations/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// list organizations
///
/// Method: GET /api/organizations/
#[actor(
PosthogListOrganizationsActor,
inports::<100>(limit, offset),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_list_organizations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/api/organizations/".to_string();
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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/organizations/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// delete organizations
///
/// Method: DELETE /api/organizations/{id}/
#[actor(
PosthogDeleteOrganizationsActor,
inports::<100>(id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_organizations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{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/organizations/{{id}}/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// update organizations
///
/// Method: PUT /api/organizations/{id}/
#[actor(
PosthogUpdateOrganizationsActor,
inports::<100>(id, is_member_join_email_enabled, name, metadata, enforce_2fa, default_anonymize_ips, updated_at, available_product_features, default_experiment_stats_method, default_role_id, member_count, allow_publicly_shared_resources, is_ai_data_processing_approved, created_at, is_not_active_reason, members_can_use_personal_api_keys, slug, members_can_invite, is_active, teams, membership_level, plugins_access_level, logo_media_id, customer_id, projects),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_organizations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{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("is_member_join_email_enabled") {
body.insert(
"is_member_join_email_enabled".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("metadata") {
body.insert("metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enforce_2fa") {
body.insert("enforce_2fa".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_anonymize_ips") {
body.insert("default_anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("available_product_features") {
body.insert("available_product_features".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_stats_method") {
body.insert(
"default_experiment_stats_method".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_role_id") {
body.insert("default_role_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("member_count") {
body.insert("member_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("allow_publicly_shared_resources") {
body.insert(
"allow_publicly_shared_resources".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("is_ai_data_processing_approved") {
body.insert(
"is_ai_data_processing_approved".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_not_active_reason") {
body.insert("is_not_active_reason".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("members_can_use_personal_api_keys") {
body.insert(
"members_can_use_personal_api_keys".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("slug") {
body.insert("slug".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("members_can_invite") {
body.insert("members_can_invite".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_active") {
body.insert("is_active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("teams") {
body.insert("teams".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("membership_level") {
body.insert("membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("plugins_access_level") {
body.insert("plugins_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logo_media_id") {
body.insert("logo_media_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("customer_id") {
body.insert("customer_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("projects") {
body.insert("projects".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/organizations/{{id}}/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// read organizations
///
/// Method: GET /api/organizations/{id}/
#[actor(
PosthogReadOrganizationsActor,
inports::<100>(id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_organizations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{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/organizations/{{id}}/ failed: {}", e).into()),
);
}
}
Ok(output)
}
/// create batch exports
///
/// Method: POST /api/organizations/{organization_id}/batch_exports/
#[actor(
PosthogCreateBatchExportsActor,
inports::<100>(organization_id, end_at, start_at, filters, team_id, name, timezone, destination, id, paused, latest_runs, created_at, offset_hour, last_updated_at, interval, schema, model, hogql_query, offset_day, last_paused_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/batch_exports/".to_string();
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("end_at") {
body.insert("end_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("start_at") {
body.insert("start_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("team_id") {
body.insert("team_id".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("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("destination") {
body.insert("destination".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("paused") {
body.insert("paused".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_runs") {
body.insert("latest_runs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("offset_hour") {
body.insert("offset_hour".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_updated_at") {
body.insert("last_updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("interval") {
body.insert("interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("schema") {
body.insert("schema".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("model") {
body.insert("model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hogql_query") {
body.insert("hogql_query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("offset_day") {
body.insert("offset_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_paused_at") {
body.insert("last_paused_at".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/organizations/{{organization_id}}/batch_exports/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read batch exports
///
/// Method: GET /api/organizations/{organization_id}/batch_exports/
#[actor(
PosthogReadBatchExportsActor,
inports::<100>(limit, offset, organization_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/batch_exports/".to_string();
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/organizations/{{organization_id}}/batch_exports/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update batch exports
///
/// Method: PATCH /api/organizations/{organization_id}/batch_exports/{id}/
#[actor(
PosthogUpdateBatchExportsActor,
inports::<100>(id, organization_id, timezone, filters, offset_day, interval, last_updated_at, destination, latest_runs, created_at, last_paused_at, end_at, model, name, offset_hour, paused, start_at, schema, team_id, hogql_query),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/batch_exports/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("offset_day") {
body.insert("offset_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("interval") {
body.insert("interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_updated_at") {
body.insert("last_updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("destination") {
body.insert("destination".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_runs") {
body.insert("latest_runs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_paused_at") {
body.insert("last_paused_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("end_at") {
body.insert("end_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("model") {
body.insert("model".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("offset_hour") {
body.insert("offset_hour".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("paused") {
body.insert("paused".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("start_at") {
body.insert("start_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("schema") {
body.insert("schema".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("team_id") {
body.insert("team_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hogql_query") {
body.insert("hogql_query".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/organizations/{{organization_id}}/batch_exports/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete batch exports
///
/// Method: DELETE /api/organizations/{organization_id}/batch_exports/{id}/
#[actor(
PosthogDeleteBatchExportsActor,
inports::<100>(id, organization_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/batch_exports/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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/organizations/{{organization_id}}/batch_exports/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Pause a BatchExport.
///
/// Method: POST /api/organizations/{organization_id}/batch_exports/{id}/pause/
#[actor(
PosthogPauseBatchExportsActor,
inports::<100>(id, organization_id, start_at, created_at, destination, latest_runs, offset_day, last_updated_at, paused, interval, team_id, filters, end_at, model, offset_hour, timezone, hogql_query, schema, name, last_paused_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_pause_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/batch_exports/{id}/pause/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("start_at") {
body.insert("start_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("destination") {
body.insert("destination".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_runs") {
body.insert("latest_runs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("offset_day") {
body.insert("offset_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_updated_at") {
body.insert("last_updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("paused") {
body.insert("paused".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("interval") {
body.insert("interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("team_id") {
body.insert("team_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("end_at") {
body.insert("end_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("model") {
body.insert("model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("offset_hour") {
body.insert("offset_hour".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hogql_query") {
body.insert("hogql_query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("schema") {
body.insert("schema".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("last_paused_at") {
body.insert("last_paused_at".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/organizations/{{organization_id}}/batch_exports/{{id}}/pause/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create core
///
/// Method: POST /api/organizations/{organization_id}/domains/
#[actor(
PosthogCreateCoreActor,
inports::<100>(organization_id, sso_enforcement, is_verified, scim_enabled, id, scim_bearer_token, verified_at, has_scim, jit_provisioning_enabled, saml_entity_id, saml_acs_url, domain, has_saml, saml_x509_cert, scim_base_url, verification_challenge),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/domains/".to_string();
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("sso_enforcement") {
body.insert("sso_enforcement".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_verified") {
body.insert("is_verified".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_enabled") {
body.insert("scim_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_bearer_token") {
body.insert("scim_bearer_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("verified_at") {
body.insert("verified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_scim") {
body.insert("has_scim".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("jit_provisioning_enabled") {
body.insert("jit_provisioning_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_entity_id") {
body.insert("saml_entity_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_acs_url") {
body.insert("saml_acs_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("domain") {
body.insert("domain".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_saml") {
body.insert("has_saml".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_x509_cert") {
body.insert("saml_x509_cert".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_base_url") {
body.insert("scim_base_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("verification_challenge") {
body.insert("verification_challenge".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/organizations/{{organization_id}}/domains/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read core
///
/// Method: GET /api/organizations/{organization_id}/domains/
#[actor(
PosthogReadCoreActor,
inports::<100>(limit, offset, organization_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/domains/".to_string();
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/organizations/{{organization_id}}/domains/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update core
///
/// Method: PATCH /api/organizations/{organization_id}/domains/{id}/
#[actor(
PosthogUpdateCoreActor,
inports::<100>(id, organization_id, is_verified, has_saml, saml_x509_cert, verification_challenge, scim_base_url, domain, scim_enabled, verified_at, has_scim, saml_entity_id, jit_provisioning_enabled, sso_enforcement, scim_bearer_token, saml_acs_url),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/domains/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("is_verified") {
body.insert("is_verified".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_saml") {
body.insert("has_saml".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_x509_cert") {
body.insert("saml_x509_cert".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("verification_challenge") {
body.insert("verification_challenge".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_base_url") {
body.insert("scim_base_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("domain") {
body.insert("domain".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_enabled") {
body.insert("scim_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("verified_at") {
body.insert("verified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_scim") {
body.insert("has_scim".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_entity_id") {
body.insert("saml_entity_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("jit_provisioning_enabled") {
body.insert("jit_provisioning_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sso_enforcement") {
body.insert("sso_enforcement".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_bearer_token") {
body.insert("scim_bearer_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_acs_url") {
body.insert("saml_acs_url".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/organizations/{{organization_id}}/domains/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete core
///
/// Method: DELETE /api/organizations/{organization_id}/domains/{id}/
#[actor(
PosthogDeleteCoreActor,
inports::<100>(id, organization_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/domains/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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/organizations/{{organization_id}}/domains/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// verify core
///
/// Method: POST /api/organizations/{organization_id}/domains/{id}/verify/
#[actor(
PosthogVerifyCoreActor,
inports::<100>(id, organization_id, scim_enabled, verified_at, jit_provisioning_enabled, saml_acs_url, domain, saml_x509_cert, has_saml, has_scim, saml_entity_id, scim_base_url, sso_enforcement, verification_challenge, scim_bearer_token, is_verified),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_verify_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/domains/{id}/verify/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("scim_enabled") {
body.insert("scim_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("verified_at") {
body.insert("verified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("jit_provisioning_enabled") {
body.insert("jit_provisioning_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_acs_url") {
body.insert("saml_acs_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("domain") {
body.insert("domain".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_x509_cert") {
body.insert("saml_x509_cert".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_saml") {
body.insert("has_saml".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_scim") {
body.insert("has_scim".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("saml_entity_id") {
body.insert("saml_entity_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_base_url") {
body.insert("scim_base_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sso_enforcement") {
body.insert("sso_enforcement".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("verification_challenge") {
body.insert("verification_challenge".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scim_bearer_token") {
body.insert("scim_bearer_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_verified") {
body.insert("is_verified".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/organizations/{{organization_id}}/domains/{{id}}/verify/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Projects for the current organization.
///
/// Method: POST /api/organizations/{organization_id}/projects/
#[actor(
PosthogCreate2Actor,
inports::<100>(organization_id, group_types, path_cleaning_filters, test_account_filters, capture_performance_opt_in, app_urls, autocapture_exceptions_errors_to_ignore, api_token, autocapture_web_vitals_opt_in, has_completed_onboarding_for, heatmaps_opt_in, live_events_columns, live_events_token, session_recording_opt_in, autocapture_opt_out, surveys_opt_in, timezone, week_start_day, autocapture_exceptions_opt_in, business_model, inject_web_apps, effective_membership_level, id, is_demo, secret_api_token, secret_api_token_backup, receive_org_level_activity_logs, ingested_event, logs_settings, available_setup_task_ids, anonymize_ips, completed_snippet_onboarding, session_recording_minimum_duration_milliseconds, product_description, session_recording_sample_rate, uuid, session_recording_linked_flag, extra_settings, access_control, name, data_attributes, recording_domains, session_replay_config, session_recording_network_payload_capture_config, has_group_types, proactive_tasks_enabled, session_recording_masking_config, autocapture_web_vitals_allowed_metrics, updated_at, conversations_enabled, test_account_filters_default_checked, primary_dashboard, flags_persistence_default, correlation_config, modifiers, capture_console_log_opt_in, default_modifiers, created_at, conversations_settings, organization, person_on_events_querying_enabled, person_display_name_properties, slack_incoming_webhook, survey_config, product_intents),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_2(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/projects/".to_string();
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("product_description") {
body.insert("product_description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".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("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".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/organizations/{{organization_id}}/projects/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Projects for the current organization.
///
/// Method: GET /api/organizations/{organization_id}/projects/
#[actor(
PosthogList2Actor,
inports::<100>(limit, offset, organization_id, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_list_2(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/projects/".to_string();
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/organizations/{{organization_id}}/projects/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Projects for the current organization.
///
/// Method: PUT /api/organizations/{organization_id}/projects/{id}/
#[actor(
PosthogUpdate2Actor,
inports::<100>(id, organization_id, api_token, completed_snippet_onboarding, session_recording_masking_config, live_events_columns, data_attributes, anonymize_ips, session_recording_linked_flag, capture_console_log_opt_in, name, surveys_opt_in, created_at, test_account_filters, session_recording_network_payload_capture_config, path_cleaning_filters, default_modifiers, product_intents, updated_at, conversations_enabled, recording_domains, business_model, receive_org_level_activity_logs, extra_settings, autocapture_opt_out, survey_config, secret_api_token, capture_performance_opt_in, autocapture_web_vitals_opt_in, secret_api_token_backup, proactive_tasks_enabled, product_description, app_urls, effective_membership_level, logs_settings, ingested_event, conversations_settings, correlation_config, session_recording_sample_rate, person_display_name_properties, access_control, has_completed_onboarding_for, slack_incoming_webhook, available_setup_task_ids, inject_web_apps, session_recording_opt_in, primary_dashboard, test_account_filters_default_checked, week_start_day, autocapture_web_vitals_allowed_metrics, group_types, session_replay_config, session_recording_minimum_duration_milliseconds, live_events_token, modifiers, flags_persistence_default, autocapture_exceptions_errors_to_ignore, has_group_types, is_demo, organization, timezone, person_on_events_querying_enabled, autocapture_exceptions_opt_in, heatmaps_opt_in, uuid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_2(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/projects/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("api_token") {
body.insert("api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".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("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_description") {
body.insert("product_description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".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/organizations/{{organization_id}}/projects/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Projects for the current organization.
///
/// Method: PATCH /api/organizations/{organization_id}/projects/{id}/delete_secret_token_backup/
#[actor(
PosthogDeleteSecretTokenBackupPartialUpdateActor,
inports::<100>(id, organization_id, inject_web_apps, autocapture_exceptions_errors_to_ignore, available_setup_task_ids, secret_api_token, extra_settings, live_events_columns, logs_settings, capture_performance_opt_in, uuid, business_model, has_completed_onboarding_for, default_modifiers, session_replay_config, timezone, week_start_day, autocapture_web_vitals_opt_in, heatmaps_opt_in, test_account_filters_default_checked, conversations_enabled, session_recording_sample_rate, created_at, primary_dashboard, session_recording_opt_in, surveys_opt_in, conversations_settings, capture_console_log_opt_in, autocapture_opt_out, flags_persistence_default, updated_at, session_recording_masking_config, live_events_token, session_recording_linked_flag, group_types, receive_org_level_activity_logs, test_account_filters, person_on_events_querying_enabled, is_demo, correlation_config, completed_snippet_onboarding, session_recording_network_payload_capture_config, person_display_name_properties, access_control, effective_membership_level, recording_domains, autocapture_exceptions_opt_in, organization, proactive_tasks_enabled, name, app_urls, ingested_event, product_intents, anonymize_ips, autocapture_web_vitals_allowed_metrics, path_cleaning_filters, secret_api_token_backup, data_attributes, slack_incoming_webhook, modifiers, product_description, survey_config, has_group_types, session_recording_minimum_duration_milliseconds, api_token),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_secret_token_backup_partial_update(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/organizations/{organization_id}/projects/{id}/delete_secret_token_backup/"
.to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".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("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_description") {
body.insert("product_description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".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/organizations/{{organization_id}}/projects/{{id}}/delete_secret_token_backup/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Projects for the current organization.
///
/// Method: POST /api/organizations/{organization_id}/projects/{id}/generate_conversations_public_token/
#[actor(
PosthogGenerateConversationsPublicTokenCreateActor,
inports::<100>(id, organization_id, effective_membership_level, api_token, primary_dashboard, week_start_day, live_events_token, session_recording_minimum_duration_milliseconds, app_urls, autocapture_opt_out, anonymize_ips, autocapture_web_vitals_opt_in, autocapture_exceptions_opt_in, data_attributes, capture_performance_opt_in, ingested_event, capture_console_log_opt_in, is_demo, session_recording_linked_flag, conversations_settings, survey_config, uuid, has_group_types, surveys_opt_in, has_completed_onboarding_for, created_at, secret_api_token_backup, inject_web_apps, session_recording_opt_in, recording_domains, slack_incoming_webhook, session_recording_network_payload_capture_config, default_modifiers, extra_settings, access_control, organization, session_replay_config, session_recording_sample_rate, live_events_columns, secret_api_token, session_recording_masking_config, logs_settings, product_description, correlation_config, test_account_filters, modifiers, proactive_tasks_enabled, autocapture_exceptions_errors_to_ignore, test_account_filters_default_checked, timezone, path_cleaning_filters, updated_at, product_intents, autocapture_web_vitals_allowed_metrics, completed_snippet_onboarding, available_setup_task_ids, receive_org_level_activity_logs, name, group_types, person_display_name_properties, heatmaps_opt_in, conversations_enabled, flags_persistence_default, person_on_events_querying_enabled, business_model),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_generate_conversations_public_token_create(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/organizations/{organization_id}/projects/{id}/generate_conversations_public_token/"
.to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_description") {
body.insert("product_description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".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("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".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/organizations/{{organization_id}}/projects/{{id}}/generate_conversations_public_token/ failed: {}", e).into()));
}
}
Ok(output)
}
/// retry organizations
///
/// Method: POST /api/organizations/{organization_id}/proxy_records/{id}/retry/
#[actor(
PosthogRetryOrganizationsActor,
inports::<100>(id, organization_id, target_cname, created_by, updated_at, created_at, domain, status, message),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_retry_organizations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/organizations/{organization_id}/proxy_records/{id}/retry/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("organization_id") {
endpoint = endpoint.replace("{{organization_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("target_cname") {
body.insert("target_cname".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("domain") {
body.insert("domain".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("message") {
body.insert("message".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/organizations/{{organization_id}}/proxy_records/{{id}}/retry/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create actions
///
/// Method: POST /api/projects/{project_id}/actions/
#[actor(
PosthogCreateActionsActor,
inports::<100>(format, project_id, description, bytecode_error, id, user_access_level, last_calculated_at, steps, deleted, create_in_folder, created_at, creation_context, slack_message_format, tags, is_action, name, team_id, is_calculating, created_by, pinned_at, post_to_slack),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_actions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/actions/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("bytecode_error") {
body.insert("bytecode_error".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_calculated_at") {
body.insert("last_calculated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("steps") {
body.insert("steps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("creation_context") {
body.insert("creation_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_message_format") {
body.insert("slack_message_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_action") {
body.insert("is_action".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("team_id") {
body.insert("team_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_calculating") {
body.insert("is_calculating".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pinned_at") {
body.insert("pinned_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("post_to_slack") {
body.insert("post_to_slack".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/projects/{{project_id}}/actions/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read actions
///
/// Method: GET /api/projects/{project_id}/actions/
#[actor(
PosthogReadActionsActor,
inports::<100>(format, limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_actions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/actions/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("format") {
query_pairs.push(("format", 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("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/actions/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/actions/{id}/
#[actor(
PosthogDeleteActionsActor,
inports::<100>(format, id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_actions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/actions/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("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!(
"DELETE /api/projects/{{project_id}}/actions/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update actions
///
/// Method: PUT /api/projects/{project_id}/actions/{id}/
#[actor(
PosthogUpdateActionsActor,
inports::<100>(format, id, project_id, is_calculating, pinned_at, name, post_to_slack, is_action, last_calculated_at, bytecode_error, steps, created_at, tags, created_by, create_in_folder, team_id, user_access_level, description, deleted, slack_message_format, creation_context),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_actions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/actions/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("is_calculating") {
body.insert("is_calculating".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pinned_at") {
body.insert("pinned_at".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("post_to_slack") {
body.insert("post_to_slack".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_action") {
body.insert("is_action".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_calculated_at") {
body.insert("last_calculated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("bytecode_error") {
body.insert("bytecode_error".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("steps") {
body.insert("steps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("team_id") {
body.insert("team_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".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("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_message_format") {
body.insert("slack_message_format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("creation_context") {
body.insert("creation_context".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/projects/{{project_id}}/actions/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read activity log
///
/// Method: GET /api/projects/{project_id}/activity_log/
#[actor(
PosthogReadActivityLogActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_activity_log(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/activity_log/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/activity_log/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read advanced activity logs
///
/// Method: GET /api/projects/{project_id}/advanced_activity_logs/
#[actor(
PosthogReadAdvancedActivityLogsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_advanced_activity_logs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/advanced_activity_logs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/advanced_activity_logs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// export advanced activity logs
///
/// Method: POST /api/projects/{project_id}/advanced_activity_logs/export/
#[actor(
PosthogExportAdvancedActivityLogsActor,
inports::<100>(project_id, created_at, user, organization_id, was_impersonated, id, detail, activity, is_system, item_id, scope, unread),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_export_advanced_activity_logs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/advanced_activity_logs/export/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user") {
body.insert("user".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("organization_id") {
body.insert("organization_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("was_impersonated") {
body.insert("was_impersonated".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("detail") {
body.insert("detail".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("activity") {
body.insert("activity".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_system") {
body.insert("is_system".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("item_id") {
body.insert("item_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("scope") {
body.insert("scope".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("unread") {
body.insert("unread".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/projects/{{project_id}}/advanced_activity_logs/export/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create alerts
///
/// Method: POST /api/projects/{project_id}/alerts/
#[actor(
PosthogCreateAlertsActor,
inports::<100>(project_id, condition, config, checks, created_by, id, last_checked_at, created_at, last_value, name, state, threshold, last_notified_at, subscribed_users, skip_weekend, snoozed_until, calculation_interval, insight, enabled, next_check_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_alerts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/alerts/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("condition") {
body.insert("condition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("config") {
body.insert("config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("checks") {
body.insert("checks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_checked_at") {
body.insert("last_checked_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_value") {
body.insert("last_value".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("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("threshold") {
body.insert("threshold".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_notified_at") {
body.insert("last_notified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("subscribed_users") {
body.insert("subscribed_users".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("skip_weekend") {
body.insert("skip_weekend".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("snoozed_until") {
body.insert("snoozed_until".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("calculation_interval") {
body.insert("calculation_interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("insight") {
body.insert("insight".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("next_check_at") {
body.insert("next_check_at".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/projects/{{project_id}}/alerts/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read alerts
///
/// Method: GET /api/projects/{project_id}/alerts/
#[actor(
PosthogReadAlertsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_alerts(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/alerts/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/alerts/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// delete alerts
///
/// Method: DELETE /api/projects/{project_id}/alerts/{id}/
#[actor(
PosthogDeleteAlertsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_alerts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/alerts/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/alerts/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update alerts
///
/// Method: PATCH /api/projects/{project_id}/alerts/{id}/
#[actor(
PosthogUpdateAlertsActor,
inports::<100>(id, project_id, calculation_interval, threshold, checks, created_at, condition, last_value, next_check_at, last_notified_at, created_by, subscribed_users, config, enabled, name, snoozed_until, state, skip_weekend, last_checked_at, insight),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_alerts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/alerts/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("calculation_interval") {
body.insert("calculation_interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("threshold") {
body.insert("threshold".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("checks") {
body.insert("checks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("condition") {
body.insert("condition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_value") {
body.insert("last_value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("next_check_at") {
body.insert("next_check_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_notified_at") {
body.insert("last_notified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("subscribed_users") {
body.insert("subscribed_users".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("config") {
body.insert("config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".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("snoozed_until") {
body.insert("snoozed_until".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("skip_weekend") {
body.insert("skip_weekend".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_checked_at") {
body.insert("last_checked_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("insight") {
body.insert("insight".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/projects/{{project_id}}/alerts/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read app metrics
///
/// Method: GET /api/projects/{project_id}/app_metrics/{id}/
#[actor(
PosthogReadAppMetricsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_app_metrics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/app_metrics/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/app_metrics/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Cancel a batch export backfill.
///
/// Method: POST /api/projects/{project_id}/batch_exports/{batch_export_id}/backfills/{id}/cancel/
#[actor(
PosthogCancelBatchExportsActor,
inports::<100>(batch_export_id, id, project_id, team, progress, last_updated_at, end_at, adjusted_start_at, batch_export, created_at, status, total_records_count, finished_at, start_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_cancel_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/batch_exports/{batch_export_id}/backfills/{id}/cancel/"
.to_string();
if let Some(val) = inputs.get("batch_export_id") {
endpoint = endpoint.replace("{{batch_export_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("team") {
body.insert("team".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("progress") {
body.insert("progress".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_updated_at") {
body.insert("last_updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("end_at") {
body.insert("end_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("adjusted_start_at") {
body.insert("adjusted_start_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("batch_export") {
body.insert("batch_export".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("total_records_count") {
body.insert("total_records_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("finished_at") {
body.insert("finished_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("start_at") {
body.insert("start_at".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/projects/{{project_id}}/batch_exports/{{batch_export_id}}/backfills/{{id}}/cancel/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Retry a batch export run.\n\nWe use the same underlying mechanism as when backfilling a batch export, as retrying\na run is the same as backfilling one run.
///
/// Method: POST /api/projects/{project_id}/batch_exports/{batch_export_id}/runs/{id}/retry/
#[actor(
PosthogRetryBatchExportsActor,
inports::<100>(batch_export_id, id, project_id, last_updated_at, records_completed, data_interval_start, finished_at, batch_export, records_total_count, latest_error, status, data_interval_end, backfill, cursor, bytes_exported, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_retry_batch_exports(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/batch_exports/{batch_export_id}/runs/{id}/retry/".to_string();
if let Some(val) = inputs.get("batch_export_id") {
endpoint = endpoint.replace("{{batch_export_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("last_updated_at") {
body.insert("last_updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("records_completed") {
body.insert("records_completed".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_interval_start") {
body.insert("data_interval_start".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("finished_at") {
body.insert("finished_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("batch_export") {
body.insert("batch_export".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("records_total_count") {
body.insert("records_total_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_error") {
body.insert("latest_error".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_interval_end") {
body.insert("data_interval_end".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("backfill") {
body.insert("backfill".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cursor") {
body.insert("cursor".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("bytes_exported") {
body.insert("bytes_exported".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/batch_exports/{{batch_export_id}}/runs/{{id}}/retry/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create conversations
///
/// Method: POST /api/projects/{project_id}/conversations/tickets/
#[actor(
PosthogCreateConversationsActor,
inports::<100>(project_id, session_id, status, message_count, escalation_reason, assignee, created_at, id, sla_due_at, session_context, tags, last_message_at, anonymous_traits, unread_customer_count, slack_channel_id, unread_team_count, ticket_number, priority, ai_resolved, person, last_message_text, distinct_id, slack_thread_ts, channel_source, slack_team_id, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/conversations/tickets/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("session_id") {
body.insert("session_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("message_count") {
body.insert("message_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("escalation_reason") {
body.insert("escalation_reason".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sla_due_at") {
body.insert("sla_due_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_context") {
body.insert("session_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_message_at") {
body.insert("last_message_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymous_traits") {
body.insert("anonymous_traits".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("unread_customer_count") {
body.insert("unread_customer_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_channel_id") {
body.insert("slack_channel_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("unread_team_count") {
body.insert("unread_team_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ticket_number") {
body.insert("ticket_number".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("priority") {
body.insert("priority".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ai_resolved") {
body.insert("ai_resolved".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person") {
body.insert("person".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_message_text") {
body.insert("last_message_text".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("distinct_id") {
body.insert("distinct_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_thread_ts") {
body.insert("slack_thread_ts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("channel_source") {
body.insert("channel_source".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_team_id") {
body.insert("slack_team_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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/projects/{{project_id}}/conversations/tickets/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// List tickets with person data attached.
///
/// Method: GET /api/projects/{project_id}/conversations/tickets/
#[actor(
PosthogReadConversationsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/conversations/tickets/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/conversations/tickets/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update conversations
///
/// Method: PATCH /api/projects/{project_id}/conversations/tickets/{id}/
#[actor(
PosthogUpdateConversationsActor,
inports::<100>(id, project_id, updated_at, ticket_number, created_at, status, distinct_id, last_message_text, priority, channel_source, person, session_id, session_context, sla_due_at, slack_team_id, slack_thread_ts, anonymous_traits, assignee, message_count, escalation_reason, ai_resolved, last_message_at, slack_channel_id, tags, unread_team_count, unread_customer_count),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/conversations/tickets/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ticket_number") {
body.insert("ticket_number".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("distinct_id") {
body.insert("distinct_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_message_text") {
body.insert("last_message_text".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("priority") {
body.insert("priority".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("channel_source") {
body.insert("channel_source".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person") {
body.insert("person".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_id") {
body.insert("session_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_context") {
body.insert("session_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sla_due_at") {
body.insert("sla_due_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_team_id") {
body.insert("slack_team_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_thread_ts") {
body.insert("slack_thread_ts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymous_traits") {
body.insert("anonymous_traits".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("message_count") {
body.insert("message_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("escalation_reason") {
body.insert("escalation_reason".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ai_resolved") {
body.insert("ai_resolved".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_message_at") {
body.insert("last_message_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_channel_id") {
body.insert("slack_channel_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("unread_team_count") {
body.insert("unread_team_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("unread_customer_count") {
body.insert("unread_customer_count".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/projects/{{project_id}}/conversations/tickets/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete conversations
///
/// Method: DELETE /api/projects/{project_id}/conversations/tickets/{id}/
#[actor(
PosthogDeleteConversationsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/conversations/tickets/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/conversations/tickets/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// refresh core
///
/// Method: POST /api/projects/{project_id}/dashboards/{dashboard_id}/sharing/refresh/
#[actor(
PosthogRefreshCoreActor,
inports::<100>(dashboard_id, project_id, password_required, created_at, share_passwords, settings, access_token, enabled),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_refresh_core(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/dashboards/{dashboard_id}/sharing/refresh/".to_string();
if let Some(val) = inputs.get("dashboard_id") {
endpoint = endpoint.replace("{{dashboard_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("password_required") {
body.insert("password_required".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("share_passwords") {
body.insert("share_passwords".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("settings") {
body.insert("settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_token") {
body.insert("access_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".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/projects/{{project_id}}/dashboards/{{dashboard_id}}/sharing/refresh/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update dashboards
///
/// Method: PUT /api/projects/{project_id}/data_color_themes/{id}/
#[actor(
PosthogUpdateDashboardsActor,
inports::<100>(id, project_id, is_global, name, colors, created_at, created_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_dashboards(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/data_color_themes/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("is_global") {
body.insert("is_global".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("colors") {
body.insert("colors".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("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!(
"PUT /api/projects/{{project_id}}/data_color_themes/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read early access features
///
/// Method: GET /api/projects/{project_id}/early_access_feature/
#[actor(
PosthogReadEarlyAccessFeaturesActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_early_access_features(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/early_access_feature/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/early_access_feature/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create early access features
///
/// Method: POST /api/projects/{project_id}/early_access_feature/
#[actor(
PosthogCreateEarlyAccessFeaturesActor,
inports::<100>(project_id, id, stage, documentation_url, create_in_folder, name, feature_flag, payload, description, created_at, feature_flag_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_early_access_features(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/early_access_feature/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("stage") {
body.insert("stage".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("documentation_url") {
body.insert("documentation_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".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("feature_flag") {
body.insert("feature_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("payload") {
body.insert("payload".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_id") {
body.insert("feature_flag_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/projects/{{project_id}}/early_access_feature/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update early access features
///
/// Method: PATCH /api/projects/{project_id}/early_access_feature/{id}/
#[actor(
PosthogUpdateEarlyAccessFeaturesActor,
inports::<100>(id, project_id, created_at, description, name, documentation_url, stage, feature_flag, payload),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_early_access_features(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/early_access_feature/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
body.insert("created_at".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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("documentation_url") {
body.insert("documentation_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("stage") {
body.insert("stage".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag") {
body.insert("feature_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("payload") {
body.insert("payload".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/projects/{{project_id}}/early_access_feature/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete early access features
///
/// Method: DELETE /api/projects/{project_id}/early_access_feature/{id}/
#[actor(
PosthogDeleteEarlyAccessFeaturesActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_early_access_features(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/early_access_feature/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/early_access_feature/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create product analytics
///
/// Method: POST /api/projects/{project_id}/elements/
#[actor(
PosthogCreateProductAnalyticsActor,
inports::<100>(project_id, nth_child, attr_id, tag_name, nth_of_type, order, attr_class, href, attributes, text),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_product_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/elements/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("nth_child") {
body.insert("nth_child".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("attr_id") {
body.insert("attr_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tag_name") {
body.insert("tag_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("nth_of_type") {
body.insert("nth_of_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("order") {
body.insert("order".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("attr_class") {
body.insert("attr_class".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("href") {
body.insert("href".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("attributes") {
body.insert("attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("text") {
body.insert("text".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/projects/{{project_id}}/elements/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read product analytics
///
/// Method: GET /api/projects/{project_id}/elements/
#[actor(
PosthogReadProductAnalyticsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_product_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/elements/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/elements/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// update product analytics
///
/// Method: PUT /api/projects/{project_id}/elements/{id}/
#[actor(
PosthogUpdateProductAnalyticsActor,
inports::<100>(id, project_id, order, text, href, attr_id, nth_of_type, attr_class, attributes, tag_name, nth_child),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_product_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/elements/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("order") {
body.insert("order".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("text") {
body.insert("text".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("href") {
body.insert("href".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("attr_id") {
body.insert("attr_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("nth_of_type") {
body.insert("nth_of_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("attr_class") {
body.insert("attr_class".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("attributes") {
body.insert("attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tag_name") {
body.insert("tag_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("nth_child") {
body.insert("nth_child".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/projects/{{project_id}}/elements/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete product analytics
///
/// Method: DELETE /api/projects/{project_id}/elements/{id}/
#[actor(
PosthogDeleteProductAnalyticsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_product_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/elements/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/elements/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// List all endpoints for the team.
///
/// Method: GET /api/projects/{project_id}/endpoints/
#[actor(
PosthogReadEndpointsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_endpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/endpoints/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/endpoints/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Create a new endpoint
///
/// Method: POST /api/projects/{project_id}/endpoints/
#[actor(
PosthogCreateEndpointsActor,
inports::<100>(project_id, bucket_overrides, version, is_materialized, derived_from_insight, sync_frequency, cache_age_seconds, name, query, description, is_active),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_endpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/endpoints/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("bucket_overrides") {
body.insert("bucket_overrides".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_materialized") {
body.insert("is_materialized".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_from_insight") {
body.insert("derived_from_insight".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sync_frequency") {
body.insert("sync_frequency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cache_age_seconds") {
body.insert("cache_age_seconds".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("query") {
body.insert("query".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("is_active") {
body.insert("is_active".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/projects/{{project_id}}/endpoints/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Update an existing endpoint. Parameters are optional. Pass version in body or ?version=N query param to target a specific version.
///
/// Method: PUT /api/projects/{project_id}/endpoints/{name}/
#[actor(
PosthogUpdateEndpointsActor,
inports::<100>(name, project_id, description, is_active, is_materialized, bucket_overrides, derived_from_insight, query, sync_frequency, version, cache_age_seconds),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_endpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/endpoints/{name}/".to_string();
if let Some(val) = inputs.get("name") {
endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_active") {
body.insert("is_active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_materialized") {
body.insert("is_materialized".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("bucket_overrides") {
body.insert("bucket_overrides".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_from_insight") {
body.insert("derived_from_insight".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sync_frequency") {
body.insert("sync_frequency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cache_age_seconds") {
body.insert("cache_age_seconds".to_string(), val.clone().into());
}
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!(
"PUT /api/projects/{{project_id}}/endpoints/{{name}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Delete an endpoint and clean up materialized query.
///
/// Method: DELETE /api/projects/{project_id}/endpoints/{name}/
#[actor(
PosthogDeleteEndpointsActor,
inports::<100>(name, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_endpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/endpoints/{name}/".to_string();
if let Some(val) = inputs.get("name") {
endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/endpoints/{{name}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Deprecated: use /api/environments/{id}/ instead.
///
/// Method: GET /api/projects/{project_id}/environments/{id}/activity/
#[actor(
PosthogReadEnvironmentsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_environments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/environments/{id}/activity/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/environments/{{id}}/activity/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Deprecated: use /api/environments/{id}/ instead.
///
/// Method: PATCH /api/projects/{project_id}/environments/{id}/add_product_intent/
#[actor(
PosthogUpdateEnvironmentsActor,
inports::<100>(id, project_id, completed_snippet_onboarding, flags_persistence_default, feature_flag_confirmation_message, group_types, inject_web_apps, capture_performance_opt_in, default_experiment_confidence_level, marketing_analytics_config, organization, effective_membership_level, autocapture_web_vitals_allowed_metrics, name, recording_domains, receive_org_level_activity_logs, conversations_settings, default_data_theme, session_recording_linked_flag, session_replay_config, survey_config, surveys_opt_in, user_access_level, cookieless_server_hash_mode, product_intents, session_recording_event_trigger_config, logs_settings, autocapture_exceptions_errors_to_ignore, business_model, session_recording_opt_in, modifiers, person_display_name_properties, session_recording_url_trigger_config, secret_api_token, slack_incoming_webhook, test_account_filters_default_checked, timezone, week_start_day, has_completed_onboarding_for, app_urls, conversations_enabled, available_setup_task_ids, require_evaluation_contexts, proactive_tasks_enabled, autocapture_exceptions_opt_in, customer_analytics_config, ingested_event, has_group_types, is_demo, session_recording_retention_period, correlation_config, default_evaluation_contexts_enabled, revenue_analytics_config, session_recording_sample_rate, session_recording_url_blocklist_config, test_account_filters, managed_viewsets, session_recording_trigger_match_type_config, updated_at, primary_dashboard, default_experiment_stats_method, web_analytics_pre_aggregated_tables_enabled, human_friendly_comparison_periods, path_cleaning_filters, data_attributes, default_modifiers, anonymize_ips, autocapture_web_vitals_opt_in, live_events_token, feature_flag_confirmation_enabled, live_events_columns, access_control, experiment_recalculation_time, session_recording_minimum_duration_milliseconds, onboarding_tasks, uuid, session_recording_masking_config, secret_api_token_backup, base_currency, extra_settings, autocapture_opt_out, capture_dead_clicks, heatmaps_opt_in, session_recording_network_payload_capture_config, created_at, capture_console_log_opt_in, person_on_events_querying_enabled, api_token),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_environments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/environments/{id}/add_product_intent/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_confirmation_message") {
body.insert(
"feature_flag_confirmation_message".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_confidence_level") {
body.insert(
"default_experiment_confidence_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("marketing_analytics_config") {
body.insert("marketing_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".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("project_id") {
body.insert("project_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_data_theme") {
body.insert("default_data_theme".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cookieless_server_hash_mode") {
body.insert(
"cookieless_server_hash_mode".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_event_trigger_config") {
body.insert(
"session_recording_event_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_url_trigger_config") {
body.insert(
"session_recording_url_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("require_evaluation_contexts") {
body.insert(
"require_evaluation_contexts".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("customer_analytics_config") {
body.insert("customer_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_retention_period") {
body.insert(
"session_recording_retention_period".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_evaluation_contexts_enabled") {
body.insert(
"default_evaluation_contexts_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("revenue_analytics_config") {
body.insert("revenue_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_url_blocklist_config") {
body.insert(
"session_recording_url_blocklist_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("managed_viewsets") {
body.insert("managed_viewsets".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_trigger_match_type_config") {
body.insert(
"session_recording_trigger_match_type_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_stats_method") {
body.insert(
"default_experiment_stats_method".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("web_analytics_pre_aggregated_tables_enabled") {
body.insert(
"web_analytics_pre_aggregated_tables_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("human_friendly_comparison_periods") {
body.insert(
"human_friendly_comparison_periods".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_confirmation_enabled") {
body.insert(
"feature_flag_confirmation_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("experiment_recalculation_time") {
body.insert(
"experiment_recalculation_time".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("onboarding_tasks") {
body.insert("onboarding_tasks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("base_currency") {
body.insert("base_currency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_dead_clicks") {
body.insert("capture_dead_clicks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".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/projects/{{project_id}}/environments/{{id}}/add_product_intent/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Manage default evaluation contexts for a team.
///
/// Method: DELETE /api/projects/{project_id}/environments/{id}/default_evaluation_contexts/
#[actor(
PosthogDeleteEnvironmentsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_environments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/environments/{id}/default_evaluation_contexts/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/environments/{{id}}/default_evaluation_contexts/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Manage default evaluation contexts for a team.
///
/// Method: POST /api/projects/{project_id}/environments/{id}/default_evaluation_contexts/
#[actor(
PosthogCreateEnvironmentsActor,
inports::<100>(id, project_id, recording_domains, managed_viewsets, has_completed_onboarding_for, session_recording_minimum_duration_milliseconds, app_urls, is_demo, secret_api_token, onboarding_tasks, web_analytics_pre_aggregated_tables_enabled, week_start_day, extra_settings, session_recording_sample_rate, available_setup_task_ids, feature_flag_confirmation_message, logs_settings, api_token, autocapture_opt_out, person_display_name_properties, session_recording_network_payload_capture_config, default_modifiers, ingested_event, session_recording_event_trigger_config, autocapture_web_vitals_opt_in, base_currency, experiment_recalculation_time, session_recording_url_blocklist_config, conversations_enabled, conversations_settings, secret_api_token_backup, business_model, default_experiment_confidence_level, inject_web_apps, group_types, product_intents, autocapture_exceptions_opt_in, heatmaps_opt_in, default_evaluation_contexts_enabled, session_recording_masking_config, session_recording_url_trigger_config, session_replay_config, flags_persistence_default, name, uuid, correlation_config, session_recording_linked_flag, test_account_filters, require_evaluation_contexts, customer_analytics_config, has_group_types, slack_incoming_webhook, modifiers, receive_org_level_activity_logs, completed_snippet_onboarding, timezone, capture_performance_opt_in, live_events_columns, proactive_tasks_enabled, survey_config, cookieless_server_hash_mode, autocapture_web_vitals_allowed_metrics, session_recording_trigger_match_type_config, revenue_analytics_config, data_attributes, test_account_filters_default_checked, anonymize_ips, live_events_token, effective_membership_level, user_access_level, person_on_events_querying_enabled, autocapture_exceptions_errors_to_ignore, access_control, feature_flag_confirmation_enabled, human_friendly_comparison_periods, organization, surveys_opt_in, session_recording_retention_period, default_data_theme, path_cleaning_filters, primary_dashboard, capture_dead_clicks, marketing_analytics_config, session_recording_opt_in, default_experiment_stats_method, capture_console_log_opt_in, updated_at, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_environments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/environments/{id}/default_evaluation_contexts/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("managed_viewsets") {
body.insert("managed_viewsets".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("onboarding_tasks") {
body.insert("onboarding_tasks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("web_analytics_pre_aggregated_tables_enabled") {
body.insert(
"web_analytics_pre_aggregated_tables_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_confirmation_message") {
body.insert(
"feature_flag_confirmation_message".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_event_trigger_config") {
body.insert(
"session_recording_event_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("base_currency") {
body.insert("base_currency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("experiment_recalculation_time") {
body.insert(
"experiment_recalculation_time".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_url_blocklist_config") {
body.insert(
"session_recording_url_blocklist_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_confidence_level") {
body.insert(
"default_experiment_confidence_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("project_id") {
body.insert("project_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_evaluation_contexts_enabled") {
body.insert(
"default_evaluation_contexts_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_url_trigger_config") {
body.insert(
"session_recording_url_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".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("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("require_evaluation_contexts") {
body.insert(
"require_evaluation_contexts".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("customer_analytics_config") {
body.insert("customer_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cookieless_server_hash_mode") {
body.insert(
"cookieless_server_hash_mode".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_trigger_match_type_config") {
body.insert(
"session_recording_trigger_match_type_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("revenue_analytics_config") {
body.insert("revenue_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_confirmation_enabled") {
body.insert(
"feature_flag_confirmation_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("human_friendly_comparison_periods") {
body.insert(
"human_friendly_comparison_periods".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_retention_period") {
body.insert(
"session_recording_retention_period".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_data_theme") {
body.insert("default_data_theme".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_dead_clicks") {
body.insert("capture_dead_clicks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("marketing_analytics_config") {
body.insert("marketing_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_stats_method") {
body.insert(
"default_experiment_stats_method".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/environments/{{id}}/default_evaluation_contexts/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Deprecated: use /api/environments/{id}/ instead.
///
/// Method: PATCH /api/projects/{project_id}/environments/{id}/delete_secret_token_backup/
#[actor(
PosthogDeleteSecretTokenBackupPartialUpdate2Actor,
inports::<100>(id, project_id, customer_analytics_config, api_token, conversations_settings, flags_persistence_default, web_analytics_pre_aggregated_tables_enabled, person_on_events_querying_enabled, onboarding_tasks, person_display_name_properties, session_recording_event_trigger_config, anonymize_ips, default_experiment_confidence_level, updated_at, autocapture_exceptions_opt_in, completed_snippet_onboarding, session_recording_sample_rate, capture_performance_opt_in, data_attributes, revenue_analytics_config, recording_domains, app_urls, extra_settings, autocapture_web_vitals_allowed_metrics, group_types, surveys_opt_in, has_group_types, uuid, cookieless_server_hash_mode, inject_web_apps, available_setup_task_ids, base_currency, managed_viewsets, product_intents, live_events_token, week_start_day, logs_settings, conversations_enabled, marketing_analytics_config, live_events_columns, effective_membership_level, default_data_theme, capture_console_log_opt_in, human_friendly_comparison_periods, is_demo, proactive_tasks_enabled, default_evaluation_contexts_enabled, receive_org_level_activity_logs, session_recording_trigger_match_type_config, feature_flag_confirmation_message, organization, primary_dashboard, modifiers, access_control, capture_dead_clicks, session_recording_masking_config, heatmaps_opt_in, session_recording_network_payload_capture_config, session_recording_url_trigger_config, secret_api_token, autocapture_exceptions_errors_to_ignore, session_recording_minimum_duration_milliseconds, require_evaluation_contexts, business_model, test_account_filters_default_checked, default_modifiers, session_recording_opt_in, timezone, feature_flag_confirmation_enabled, ingested_event, path_cleaning_filters, experiment_recalculation_time, has_completed_onboarding_for, slack_incoming_webhook, secret_api_token_backup, user_access_level, name, created_at, session_recording_linked_flag, autocapture_opt_out, autocapture_web_vitals_opt_in, session_recording_url_blocklist_config, session_recording_retention_period, session_replay_config, correlation_config, test_account_filters, default_experiment_stats_method, survey_config),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_secret_token_backup_partial_update_2(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/environments/{id}/delete_secret_token_backup/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("customer_analytics_config") {
body.insert("customer_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("web_analytics_pre_aggregated_tables_enabled") {
body.insert(
"web_analytics_pre_aggregated_tables_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("onboarding_tasks") {
body.insert("onboarding_tasks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_event_trigger_config") {
body.insert(
"session_recording_event_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_confidence_level") {
body.insert(
"default_experiment_confidence_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("revenue_analytics_config") {
body.insert("revenue_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cookieless_server_hash_mode") {
body.insert(
"cookieless_server_hash_mode".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("base_currency") {
body.insert("base_currency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("managed_viewsets") {
body.insert("managed_viewsets".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("marketing_analytics_config") {
body.insert("marketing_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_data_theme") {
body.insert("default_data_theme".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("human_friendly_comparison_periods") {
body.insert(
"human_friendly_comparison_periods".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_evaluation_contexts_enabled") {
body.insert(
"default_evaluation_contexts_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_trigger_match_type_config") {
body.insert(
"session_recording_trigger_match_type_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("feature_flag_confirmation_message") {
body.insert(
"feature_flag_confirmation_message".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_dead_clicks") {
body.insert("capture_dead_clicks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_url_trigger_config") {
body.insert(
"session_recording_url_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("require_evaluation_contexts") {
body.insert(
"require_evaluation_contexts".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_confirmation_enabled") {
body.insert(
"feature_flag_confirmation_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("experiment_recalculation_time") {
body.insert(
"experiment_recalculation_time".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("project_id") {
body.insert("project_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_url_blocklist_config") {
body.insert(
"session_recording_url_blocklist_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_retention_period") {
body.insert(
"session_recording_retention_period".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_stats_method") {
body.insert(
"default_experiment_stats_method".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".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/projects/{{project_id}}/environments/{{id}}/delete_secret_token_backup/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Deprecated: use /api/environments/{id}/ instead.
///
/// Method: POST /api/projects/{project_id}/environments/{id}/generate_conversations_public_token/
#[actor(
PosthogGenerateConversationsPublicTokenCreate2Actor,
inports::<100>(id, project_id, session_recording_trigger_match_type_config, session_recording_opt_in, autocapture_web_vitals_allowed_metrics, surveys_opt_in, default_evaluation_contexts_enabled, human_friendly_comparison_periods, onboarding_tasks, autocapture_opt_out, receive_org_level_activity_logs, slack_incoming_webhook, anonymize_ips, created_at, base_currency, data_attributes, proactive_tasks_enabled, default_experiment_confidence_level, session_recording_network_payload_capture_config, capture_console_log_opt_in, recording_domains, autocapture_exceptions_opt_in, test_account_filters_default_checked, autocapture_web_vitals_opt_in, name, conversations_enabled, product_intents, marketing_analytics_config, session_replay_config, default_experiment_stats_method, session_recording_sample_rate, ingested_event, path_cleaning_filters, secret_api_token, test_account_filters, timezone, completed_snippet_onboarding, live_events_token, correlation_config, logs_settings, is_demo, flags_persistence_default, app_urls, session_recording_linked_flag, feature_flag_confirmation_enabled, has_group_types, inject_web_apps, secret_api_token_backup, session_recording_url_trigger_config, available_setup_task_ids, person_display_name_properties, session_recording_retention_period, revenue_analytics_config, user_access_level, capture_dead_clicks, capture_performance_opt_in, session_recording_event_trigger_config, default_modifiers, group_types, week_start_day, session_recording_url_blocklist_config, conversations_settings, extra_settings, heatmaps_opt_in, modifiers, primary_dashboard, require_evaluation_contexts, uuid, experiment_recalculation_time, has_completed_onboarding_for, session_recording_masking_config, web_analytics_pre_aggregated_tables_enabled, managed_viewsets, updated_at, cookieless_server_hash_mode, person_on_events_querying_enabled, access_control, api_token, default_data_theme, session_recording_minimum_duration_milliseconds, organization, survey_config, autocapture_exceptions_errors_to_ignore, customer_analytics_config, feature_flag_confirmation_message, live_events_columns, effective_membership_level, business_model),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_generate_conversations_public_token_create_2(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/environments/{id}/generate_conversations_public_token/"
.to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("session_recording_trigger_match_type_config") {
body.insert(
"session_recording_trigger_match_type_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_opt_in") {
body.insert("session_recording_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_web_vitals_allowed_metrics") {
body.insert(
"autocapture_web_vitals_allowed_metrics".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("surveys_opt_in") {
body.insert("surveys_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_evaluation_contexts_enabled") {
body.insert(
"default_evaluation_contexts_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("human_friendly_comparison_periods") {
body.insert(
"human_friendly_comparison_periods".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("onboarding_tasks") {
body.insert("onboarding_tasks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_opt_out") {
body.insert("autocapture_opt_out".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("receive_org_level_activity_logs") {
body.insert(
"receive_org_level_activity_logs".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("slack_incoming_webhook") {
body.insert("slack_incoming_webhook".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("anonymize_ips") {
body.insert("anonymize_ips".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("base_currency") {
body.insert("base_currency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_attributes") {
body.insert("data_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("proactive_tasks_enabled") {
body.insert("proactive_tasks_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_confidence_level") {
body.insert(
"default_experiment_confidence_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_network_payload_capture_config") {
body.insert(
"session_recording_network_payload_capture_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("capture_console_log_opt_in") {
body.insert("capture_console_log_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recording_domains") {
body.insert("recording_domains".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_opt_in") {
body.insert(
"autocapture_exceptions_opt_in".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("test_account_filters_default_checked") {
body.insert(
"test_account_filters_default_checked".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("autocapture_web_vitals_opt_in") {
body.insert(
"autocapture_web_vitals_opt_in".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("conversations_enabled") {
body.insert("conversations_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("product_intents") {
body.insert("product_intents".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("marketing_analytics_config") {
body.insert("marketing_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_replay_config") {
body.insert("session_replay_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_experiment_stats_method") {
body.insert(
"default_experiment_stats_method".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_sample_rate") {
body.insert(
"session_recording_sample_rate".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ingested_event") {
body.insert("ingested_event".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path_cleaning_filters") {
body.insert("path_cleaning_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token") {
body.insert("secret_api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("test_account_filters") {
body.insert("test_account_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("completed_snippet_onboarding") {
body.insert(
"completed_snippet_onboarding".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_token") {
body.insert("live_events_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("correlation_config") {
body.insert("correlation_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("logs_settings") {
body.insert("logs_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_demo") {
body.insert("is_demo".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("flags_persistence_default") {
body.insert("flags_persistence_default".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("app_urls") {
body.insert("app_urls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_linked_flag") {
body.insert(
"session_recording_linked_flag".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("feature_flag_confirmation_enabled") {
body.insert(
"feature_flag_confirmation_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("has_group_types") {
body.insert("has_group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inject_web_apps") {
body.insert("inject_web_apps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("secret_api_token_backup") {
body.insert("secret_api_token_backup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_url_trigger_config") {
body.insert(
"session_recording_url_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("available_setup_task_ids") {
body.insert("available_setup_task_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("person_display_name_properties") {
body.insert(
"person_display_name_properties".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_retention_period") {
body.insert(
"session_recording_retention_period".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("project_id") {
body.insert("project_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("revenue_analytics_config") {
body.insert("revenue_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_dead_clicks") {
body.insert("capture_dead_clicks".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("capture_performance_opt_in") {
body.insert("capture_performance_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_event_trigger_config") {
body.insert(
"session_recording_event_trigger_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("default_modifiers") {
body.insert("default_modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_types") {
body.insert("group_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("week_start_day") {
body.insert("week_start_day".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_url_blocklist_config") {
body.insert(
"session_recording_url_blocklist_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("conversations_settings") {
body.insert("conversations_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_settings") {
body.insert("extra_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("heatmaps_opt_in") {
body.insert("heatmaps_opt_in".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("modifiers") {
body.insert("modifiers".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("primary_dashboard") {
body.insert("primary_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("require_evaluation_contexts") {
body.insert(
"require_evaluation_contexts".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("experiment_recalculation_time") {
body.insert(
"experiment_recalculation_time".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("has_completed_onboarding_for") {
body.insert(
"has_completed_onboarding_for".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("session_recording_masking_config") {
body.insert(
"session_recording_masking_config".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("web_analytics_pre_aggregated_tables_enabled") {
body.insert(
"web_analytics_pre_aggregated_tables_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("managed_viewsets") {
body.insert("managed_viewsets".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cookieless_server_hash_mode") {
body.insert(
"cookieless_server_hash_mode".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("person_on_events_querying_enabled") {
body.insert(
"person_on_events_querying_enabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("access_control") {
body.insert("access_control".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("api_token") {
body.insert("api_token".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("default_data_theme") {
body.insert("default_data_theme".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_recording_minimum_duration_milliseconds") {
body.insert(
"session_recording_minimum_duration_milliseconds".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("organization") {
body.insert("organization".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("survey_config") {
body.insert("survey_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("autocapture_exceptions_errors_to_ignore") {
body.insert(
"autocapture_exceptions_errors_to_ignore".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("customer_analytics_config") {
body.insert("customer_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_confirmation_message") {
body.insert(
"feature_flag_confirmation_message".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("live_events_columns") {
body.insert("live_events_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_membership_level") {
body.insert("effective_membership_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("business_model") {
body.insert("business_model".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/projects/{{project_id}}/environments/{{id}}/generate_conversations_public_token/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read event schemas
///
/// Method: GET /api/projects/{project_id}/event_schemas/
#[actor(
PosthogReadEventSchemasActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_event_schemas(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/event_schemas/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/event_schemas/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create event schemas
///
/// Method: POST /api/projects/{project_id}/event_schemas/
#[actor(
PosthogCreateEventSchemasActor,
inports::<100>(project_id, property_group, created_at, property_group_id, updated_at, id, event_definition),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_event_schemas(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/event_schemas/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("property_group") {
body.insert("property_group".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("property_group_id") {
body.insert("property_group_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("event_definition") {
body.insert("event_definition".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/projects/{{project_id}}/event_schemas/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update event schemas
///
/// Method: PUT /api/projects/{project_id}/event_schemas/{id}/
#[actor(
PosthogUpdateEventSchemasActor,
inports::<100>(id, project_id, event_definition, updated_at, created_at, property_group, property_group_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_event_schemas(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/event_schemas/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("event_definition") {
body.insert("event_definition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("property_group") {
body.insert("property_group".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("property_group_id") {
body.insert("property_group_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!(
"PUT /api/projects/{{project_id}}/event_schemas/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete event schemas
///
/// Method: DELETE /api/projects/{project_id}/event_schemas/{id}/
#[actor(
PosthogDeleteEventSchemasActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_event_schemas(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/event_schemas/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/event_schemas/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create experiments
///
/// Method: POST /api/projects/{project_id}/experiment_holdouts/
#[actor(
PosthogCreateExperimentsActor,
inports::<100>(project_id, created_by, id, filters, name, created_at, updated_at, description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_holdouts/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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!(
"POST /api/projects/{{project_id}}/experiment_holdouts/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read experiments
///
/// Method: GET /api/projects/{project_id}/experiment_holdouts/
#[actor(
PosthogReadExperimentsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_holdouts/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/experiment_holdouts/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update experiments
///
/// Method: PATCH /api/projects/{project_id}/experiment_holdouts/{id}/
#[actor(
PosthogUpdateExperimentsActor,
inports::<100>(id, project_id, filters, description, name, created_at, updated_at, created_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_holdouts/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("filters") {
body.insert("filters".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("id") {
body.insert("id".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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/projects/{{project_id}}/experiment_holdouts/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete experiments
///
/// Method: DELETE /api/projects/{project_id}/experiment_holdouts/{id}/
#[actor(
PosthogDeleteExperimentsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_holdouts/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/experiment_holdouts/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read experiment saved metrics
///
/// Method: GET /api/projects/{project_id}/experiment_saved_metrics/
#[actor(
PosthogReadExperimentSavedMetricsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_experiment_saved_metrics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_saved_metrics/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/experiment_saved_metrics/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create experiment saved metrics
///
/// Method: POST /api/projects/{project_id}/experiment_saved_metrics/
#[actor(
PosthogCreateExperimentSavedMetricsActor,
inports::<100>(project_id, id, query, user_access_level, name, description, created_by, updated_at, tags, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_experiment_saved_metrics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_saved_metrics/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".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("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/experiment_saved_metrics/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update experiment saved metrics
///
/// Method: PUT /api/projects/{project_id}/experiment_saved_metrics/{id}/
#[actor(
PosthogUpdateExperimentSavedMetricsActor,
inports::<100>(id, project_id, query, created_by, updated_at, user_access_level, tags, name, created_at, description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_experiment_saved_metrics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_saved_metrics/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".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("created_at") {
body.insert("created_at".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!("PUT /api/projects/{{project_id}}/experiment_saved_metrics/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete experiment saved metrics
///
/// Method: DELETE /api/projects/{project_id}/experiment_saved_metrics/{id}/
#[actor(
PosthogDeleteExperimentSavedMetricsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_experiment_saved_metrics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/experiment_saved_metrics/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/experiment_saved_metrics/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Create, Read, Update and Delete External data Sources.
///
/// Method: POST /api/projects/{project_id}/external_data_sources/
#[actor(
PosthogCreateDataWarehouseActor,
inports::<100>(project_id, latest_error, created_by, account_id, job_inputs, source_type, last_run_at, status, id, created_at, client_secret, description, user_access_level, revenue_analytics_config, schemas, prefix, access_method),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_data_warehouse(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/external_data_sources/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("latest_error") {
body.insert("latest_error".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("account_id") {
body.insert("account_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("job_inputs") {
body.insert("job_inputs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("source_type") {
body.insert("source_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_run_at") {
body.insert("last_run_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("client_secret") {
body.insert("client_secret".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_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("revenue_analytics_config") {
body.insert("revenue_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("schemas") {
body.insert("schemas".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("prefix") {
body.insert("prefix".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_method") {
body.insert("access_method".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/projects/{{project_id}}/external_data_sources/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete External data Sources.
///
/// Method: GET /api/projects/{project_id}/external_data_sources/
#[actor(
PosthogReadDataWarehouseActor,
inports::<100>(limit, offset, project_id, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_data_warehouse(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/external_data_sources/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/projects/{{project_id}}/external_data_sources/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete External data Sources.
///
/// Method: PATCH /api/projects/{project_id}/external_data_sources/{id}/
#[actor(
PosthogUpdateDataWarehouseActor,
inports::<100>(id, project_id, client_secret, description, job_inputs, account_id, user_access_level, status, created_by, latest_error, prefix, created_at, revenue_analytics_config, schemas, last_run_at, source_type, access_method),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_data_warehouse(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/external_data_sources/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("client_secret") {
body.insert("client_secret".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("job_inputs") {
body.insert("job_inputs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("account_id") {
body.insert("account_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_error") {
body.insert("latest_error".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("prefix") {
body.insert("prefix".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("revenue_analytics_config") {
body.insert("revenue_analytics_config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("schemas") {
body.insert("schemas".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_run_at") {
body.insert("last_run_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("source_type") {
body.insert("source_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("access_method") {
body.insert("access_method".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/projects/{{project_id}}/external_data_sources/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Create, Read, Update and Delete External data Sources.
///
/// Method: DELETE /api/projects/{project_id}/external_data_sources/{id}/
#[actor(
PosthogDeleteDataWarehouseActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_data_warehouse(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/external_data_sources/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/external_data_sources/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Create, read, update and delete feature flags. [See docs](https://posthog.com/docs/feature-flags) for more information on feature flags.\n\nIf you're looking to use feature flags on your application, you can either use our JavaScript Library or our dedicated endpoint to check if feature flags are enabled for a given user.
///
/// Method: GET /api/projects/{project_id}/feature_flags/
#[actor(
PosthogReadFeatureFlagsActor,
inports::<100>(active, created_by_id, evaluation_runtime, excluded_properties, has_evaluation_tags, limit, offset, project_id, search, tags, type_),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_feature_flags(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/feature_flags/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("active") {
query_pairs.push(("active", super::message_to_str(val)));
}
if let Some(val) = inputs.get("created_by_id") {
query_pairs.push(("created_by_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("evaluation_runtime") {
query_pairs.push(("evaluation_runtime", super::message_to_str(val)));
}
if let Some(val) = inputs.get("excluded_properties") {
query_pairs.push(("excluded_properties", super::message_to_str(val)));
}
if let Some(val) = inputs.get("has_evaluation_tags") {
query_pairs.push(("has_evaluation_tags", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", super::message_to_str(val)));
}
if let Some(val) = inputs.get("tags") {
query_pairs.push(("tags", super::message_to_str(val)));
}
if let Some(val) = inputs.get("type_") {
query_pairs.push(("type", 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/projects/{{project_id}}/feature_flags/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, read, update and delete feature flags. [See docs](https://posthog.com/docs/feature-flags) for more information on feature flags.\n\nIf you're looking to use feature flags on your application, you can either use our JavaScript Library or our dedicated endpoint to check if feature flags are enabled for a given user.
///
/// Method: POST /api/projects/{project_id}/feature_flags/
#[actor(
PosthogCreateFeatureFlagsActor,
inports::<100>(project_id, filters, active, key, name, tags, evaluation_tags),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_feature_flags(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/feature_flags/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("active") {
body.insert("active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("key") {
body.insert("key".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("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_tags") {
body.insert("evaluation_tags".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/projects/{{project_id}}/feature_flags/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/feature_flags/{id}/
#[actor(
PosthogDeleteFeatureFlagsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_feature_flags(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/feature_flags/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/feature_flags/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, read, update and delete feature flags. [See docs](https://posthog.com/docs/feature-flags) for more information on feature flags.\n\nIf you're looking to use feature flags on your application, you can either use our JavaScript Library or our dedicated endpoint to check if feature flags are enabled for a given user.
///
/// Method: PUT /api/projects/{project_id}/feature_flags/{id}/
#[actor(
PosthogUpdateFeatureFlagsActor,
inports::<100>(id, project_id, ensure_experience_continuity, has_enriched_analytics, updated_at, bucketing_identifier, is_used_in_replay_settings, filters, should_create_usage_dashboard, rollback_conditions, is_remote_configuration, user_access_level, version, created_at, usage_dashboard, key, has_encrypted_payloads, evaluation_runtime, experiment_set, last_called_at, status, create_in_folder, deleted, performed_rollback, evaluation_tags, analytics_dashboards, features, created_by, creation_context, surveys, active, can_edit, name, tags, last_modified_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_feature_flags(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/feature_flags/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("ensure_experience_continuity") {
body.insert(
"ensure_experience_continuity".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_enriched_analytics") {
body.insert("has_enriched_analytics".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("bucketing_identifier") {
body.insert("bucketing_identifier".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_used_in_replay_settings") {
body.insert("is_used_in_replay_settings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("should_create_usage_dashboard") {
body.insert(
"_should_create_usage_dashboard".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("rollback_conditions") {
body.insert("rollback_conditions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_remote_configuration") {
body.insert("is_remote_configuration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("usage_dashboard") {
body.insert("usage_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("key") {
body.insert("key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_encrypted_payloads") {
body.insert("has_encrypted_payloads".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_runtime") {
body.insert("evaluation_runtime".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("experiment_set") {
body.insert("experiment_set".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_called_at") {
body.insert("last_called_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("performed_rollback") {
body.insert("performed_rollback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_tags") {
body.insert("evaluation_tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("analytics_dashboards") {
body.insert("analytics_dashboards".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("features") {
body.insert("features".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("creation_context") {
body.insert("creation_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("surveys") {
body.insert("surveys".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("active") {
body.insert("active".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("can_edit") {
body.insert("can_edit".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("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".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/projects/{{project_id}}/feature_flags/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// move core
///
/// Method: POST /api/projects/{project_id}/file_system/{id}/move/
#[actor(
PosthogMoveCoreActor,
inports::<100>(id, project_id, meta, shortcut, ref_, href, type_, path, last_viewed_at, depth, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_move_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/file_system/{id}/move/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("meta") {
body.insert("meta".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("shortcut") {
body.insert("shortcut".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ref_") {
body.insert("ref".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("href") {
body.insert("href".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("path") {
body.insert("path".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_viewed_at") {
body.insert("last_viewed_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("depth") {
body.insert("depth".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/file_system/{{id}}/move/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read file system shortcut
///
/// Method: GET /api/projects/{project_id}/file_system_shortcut/
#[actor(
PosthogReadFileSystemShortcutActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_file_system_shortcut(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/file_system_shortcut/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/file_system_shortcut/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create file system shortcut
///
/// Method: POST /api/projects/{project_id}/file_system_shortcut/
#[actor(
PosthogCreateFileSystemShortcutActor,
inports::<100>(project_id, href, ref_, id, path, created_at, type_),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_file_system_shortcut(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/file_system_shortcut/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("href") {
body.insert("href".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ref_") {
body.insert("ref".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path") {
body.insert("path".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("type_") {
body.insert("type".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/projects/{{project_id}}/file_system_shortcut/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update file system shortcut
///
/// Method: PUT /api/projects/{project_id}/file_system_shortcut/{id}/
#[actor(
PosthogUpdateFileSystemShortcutActor,
inports::<100>(id, project_id, href, path, ref_, created_at, type_),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_file_system_shortcut(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/file_system_shortcut/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("href") {
body.insert("href".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path") {
body.insert("path".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ref_") {
body.insert("ref".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("type_") {
body.insert("type".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/projects/{{project_id}}/file_system_shortcut/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete file system shortcut
///
/// Method: DELETE /api/projects/{project_id}/file_system_shortcut/{id}/
#[actor(
PosthogDeleteFileSystemShortcutActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_file_system_shortcut(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/file_system_shortcut/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/file_system_shortcut/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Get possible values for a feature flag.\n\nQuery parameters:\n- key: The flag ID (required)\nReturns:\n\n- Array of objects with 'name' field containing possible values
///
/// Method: GET /api/projects/{project_id}/flag_value/values/
#[actor(
PosthogReadFlagValueActor,
inports::<100>(key, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_flag_value(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/flag_value/values/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("key") {
query_pairs.push(("key", 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/projects/{{project_id}}/flag_value/values/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read groups types
///
/// Method: GET /api/projects/{project_id}/groups_types/
#[actor(
PosthogReadGroupsTypesActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_groups_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/groups_types/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/groups_types/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update groups types
///
/// Method: PUT /api/projects/{project_id}/groups_types/create_detail_dashboard/
#[actor(
PosthogUpdateGroupsTypesActor,
inports::<100>(project_id, default_columns, created_at, detail_dashboard, group_type, group_type_index, name_plural, name_singular),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_groups_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/groups_types/create_detail_dashboard/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("default_columns") {
body.insert("default_columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("detail_dashboard") {
body.insert("detail_dashboard".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_type") {
body.insert("group_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("group_type_index") {
body.insert("group_type_index".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name_plural") {
body.insert("name_plural".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name_singular") {
body.insert("name_singular".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/projects/{{project_id}}/groups_types/create_detail_dashboard/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete groups types
///
/// Method: DELETE /api/projects/{project_id}/groups_types/{group_type_index}/
#[actor(
PosthogDeleteGroupsTypesActor,
inports::<100>(group_type_index, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_groups_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/groups_types/{group_type_index}/".to_string();
if let Some(val) = inputs.get("group_type_index") {
endpoint = endpoint.replace("{{group_type_index}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/groups_types/{{group_type_index}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create groups types
///
/// Method: POST /api/projects/{project_id}/groups_types/{group_type_index}/metrics/
#[actor(
PosthogCreateGroupsTypesActor,
inports::<100>(group_type_index, project_id, id, interval, name, display, format, filters),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_groups_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/groups_types/{group_type_index}/metrics/".to_string();
if let Some(val) = inputs.get("group_type_index") {
endpoint = endpoint.replace("{{group_type_index}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("interval") {
body.insert("interval".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("display") {
body.insert("display".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("format") {
body.insert("format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".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/projects/{{project_id}}/groups_types/{{group_type_index}}/metrics/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read heatmap screenshots
///
/// Method: GET /api/projects/{project_id}/heatmap_screenshots/{id}/content/
#[actor(
PosthogReadHeatmapScreenshotsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_heatmap_screenshots(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/heatmap_screenshots/{id}/content/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/heatmap_screenshots/{{id}}/content/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read heatmaps
///
/// Method: GET /api/projects/{project_id}/heatmaps/
#[actor(
PosthogReadHeatmapsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_heatmaps(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/heatmaps/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/heatmaps/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read workflows
///
/// Method: GET /api/projects/{project_id}/hog_flows/
#[actor(
PosthogReadWorkflowsActor,
inports::<100>(created_at, created_by, id, limit, offset, project_id, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_workflows(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_flows/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
query_pairs.push(("created_at", super::message_to_str(val)));
}
if let Some(val) = inputs.get("created_by") {
query_pairs.push(("created_by", super::message_to_str(val)));
}
if let Some(val) = inputs.get("id") {
query_pairs.push(("id", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("updated_at") {
query_pairs.push(("updated_at", 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/projects/{{project_id}}/hog_flows/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// create workflows
///
/// Method: POST /api/projects/{project_id}/hog_flows/
#[actor(
PosthogCreateWorkflowsActor,
inports::<100>(project_id, actions, status, conversion, trigger, exit_condition, abort_action, description, created_by, trigger_masking, version, billable_action_types, edges, name, id, updated_at, variables, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_workflows(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_flows/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("actions") {
body.insert("actions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversion") {
body.insert("conversion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("trigger") {
body.insert("trigger".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("exit_condition") {
body.insert("exit_condition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("abort_action") {
body.insert("abort_action".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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("trigger_masking") {
body.insert("trigger_masking".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("billable_action_types") {
body.insert("billable_action_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("edges") {
body.insert("edges".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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("variables") {
body.insert("variables".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/hog_flows/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// delete workflows
///
/// Method: DELETE /api/projects/{project_id}/hog_flows/{id}/
#[actor(
PosthogDeleteWorkflowsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_workflows(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_flows/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/hog_flows/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update workflows
///
/// Method: PUT /api/projects/{project_id}/hog_flows/{id}/
#[actor(
PosthogUpdateWorkflowsActor,
inports::<100>(id, project_id, abort_action, edges, actions, description, name, status, trigger, version, updated_at, billable_action_types, exit_condition, trigger_masking, created_by, created_at, conversion, variables),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_workflows(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_flows/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("abort_action") {
body.insert("abort_action".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("edges") {
body.insert("edges".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("actions") {
body.insert("actions".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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("trigger") {
body.insert("trigger".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("billable_action_types") {
body.insert("billable_action_types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("exit_condition") {
body.insert("exit_condition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("trigger_masking") {
body.insert("trigger_masking".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conversion") {
body.insert("conversion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("variables") {
body.insert("variables".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/projects/{{project_id}}/hog_flows/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read hog function templates
///
/// Method: GET /api/projects/{project_id}/hog_function_templates/
#[actor(
PosthogReadHogFunctionTemplatesActor,
inports::<100>(limit, offset, project_id, template_id, type_, types),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_hog_function_templates(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_function_templates/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("template_id") {
query_pairs.push(("template_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("type_") {
query_pairs.push(("type", super::message_to_str(val)));
}
if let Some(val) = inputs.get("types") {
query_pairs.push(("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/projects/{{project_id}}/hog_function_templates/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read hog functions
///
/// Method: GET /api/projects/{project_id}/hog_functions/
#[actor(
PosthogReadHogFunctionsActor,
inports::<100>(created_at, created_by, enabled, id, limit, offset, project_id, search, type_, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_hog_functions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_functions/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
query_pairs.push(("created_at", super::message_to_str(val)));
}
if let Some(val) = inputs.get("created_by") {
query_pairs.push(("created_by", super::message_to_str(val)));
}
if let Some(val) = inputs.get("enabled") {
query_pairs.push(("enabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("id") {
query_pairs.push(("id", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", super::message_to_str(val)));
}
if let Some(val) = inputs.get("type_") {
query_pairs.push(("type", super::message_to_str(val)));
}
if let Some(val) = inputs.get("updated_at") {
query_pairs.push(("updated_at", 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/projects/{{project_id}}/hog_functions/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create hog functions
///
/// Method: POST /api/projects/{project_id}/hog_functions/
#[actor(
PosthogCreateHogFunctionsActor,
inports::<100>(project_id, deleted, execution_order, created_by, bytecode, enabled, hog, inputs_schema, masking, create_in_folder, created_at, mappings, transpiled, icon_url, inputs, status, id, batch_export_id, description, name, template, filters, template_id, updated_at, type_),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_hog_functions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_functions/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("execution_order") {
body.insert("execution_order".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("bytecode") {
body.insert("bytecode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hog") {
body.insert("hog".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inputs_schema") {
body.insert("inputs_schema".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("masking") {
body.insert("masking".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("mappings") {
body.insert("mappings".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("transpiled") {
body.insert("transpiled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("icon_url") {
body.insert("icon_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("inputs") {
body.insert("inputs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("batch_export_id") {
body.insert("batch_export_id".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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("template") {
body.insert("template".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("template_id") {
body.insert("template_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("type_") {
body.insert("type".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/projects/{{project_id}}/hog_functions/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update the execution order of multiple HogFunctions.
///
/// Method: PATCH /api/projects/{project_id}/hog_functions/rearrange/
#[actor(
PosthogUpdateHogFunctionsActor,
inports::<100>(project_id, orders),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_hog_functions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_functions/rearrange/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("orders") {
body.insert("orders".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/projects/{{project_id}}/hog_functions/rearrange/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/hog_functions/{id}/
#[actor(
PosthogDeleteHogFunctionsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_hog_functions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/hog_functions/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/hog_functions/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create insight variables
///
/// Method: POST /api/projects/{project_id}/insight_variables/
#[actor(
PosthogCreateInsightVariablesActor,
inports::<100>(project_id, created_at, id, created_by, name, default_value, type_, values, code_name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_insight_variables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insight_variables/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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("default_value") {
body.insert("default_value".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("values") {
body.insert("values".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("code_name") {
body.insert("code_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 /api/projects/{{project_id}}/insight_variables/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read insight variables
///
/// Method: GET /api/projects/{project_id}/insight_variables/
#[actor(
PosthogReadInsightVariablesActor,
inports::<100>(page, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_insight_variables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insight_variables/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("page") {
query_pairs.push(("page", 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/projects/{{project_id}}/insight_variables/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update insight variables
///
/// Method: PUT /api/projects/{project_id}/insight_variables/{id}/
#[actor(
PosthogUpdateInsightVariablesActor,
inports::<100>(id, project_id, name, created_at, created_by, values, type_, default_value, code_name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_insight_variables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insight_variables/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("values") {
body.insert("values".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("default_value") {
body.insert("default_value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("code_name") {
body.insert("code_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!(
"PUT /api/projects/{{project_id}}/insight_variables/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete insight variables
///
/// Method: DELETE /api/projects/{project_id}/insight_variables/{id}/
#[actor(
PosthogDeleteInsightVariablesActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_insight_variables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insight_variables/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/insight_variables/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create insights
///
/// Method: POST /api/projects/{project_id}/insights/
#[actor(
PosthogCreateInsightsActor,
inports::<100>(format, project_id, next_allowed_client_refresh, updated_at, user_access_level, result, dashboard_tiles, create_in_folder, order, last_refresh, short_id, last_viewed_at, hogql, derived_name, types, name, last_modified_by, hasMore, created_at, query_status, columns, is_cached, resolved_date_range, timezone, dashboards, favorited, description, last_modified_at, tags, is_sample, effective_restriction_level, cache_target_age, id, deleted, alerts, effective_privilege_level, query, created_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_insights(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insights/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("next_allowed_client_refresh") {
body.insert(
"next_allowed_client_refresh".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("result") {
body.insert("result".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dashboard_tiles") {
body.insert("dashboard_tiles".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("order") {
body.insert("order".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_refresh") {
body.insert("last_refresh".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_viewed_at") {
body.insert("last_viewed_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hogql") {
body.insert("hogql".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_name") {
body.insert("derived_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("types") {
body.insert("types".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("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hasMore") {
body.insert("hasMore".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query_status") {
body.insert("query_status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("columns") {
body.insert("columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_cached") {
body.insert("is_cached".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resolved_date_range") {
body.insert("resolved_date_range".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dashboards") {
body.insert("dashboards".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("favorited") {
body.insert("favorited".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("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_sample") {
body.insert("is_sample".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_restriction_level") {
body.insert(
"effective_restriction_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("cache_target_age") {
body.insert("cache_target_age".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("alerts") {
body.insert("alerts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_privilege_level") {
body.insert("effective_privilege_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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/projects/{{project_id}}/insights/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read insights
///
/// Method: GET /api/projects/{project_id}/insights/
#[actor(
PosthogReadInsightsActor,
inports::<100>(basic, format, limit, offset, project_id, refresh, short_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_insights(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insights/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("basic") {
query_pairs.push(("basic", super::message_to_str(val)));
}
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("refresh") {
query_pairs.push(("refresh", super::message_to_str(val)));
}
if let Some(val) = inputs.get("short_id") {
query_pairs.push(("short_id", 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/projects/{{project_id}}/insights/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// cancel insights
///
/// Method: POST /api/projects/{project_id}/insights/cancel/
#[actor(
PosthogCancelInsightsActor,
inports::<100>(format, project_id, effective_privilege_level, query_status, short_id, last_refresh, hogql, created_at, favorited, dashboards, description, user_access_level, resolved_date_range, dashboard_tiles, derived_name, create_in_folder, types, columns, next_allowed_client_refresh, last_modified_by, id, is_sample, last_viewed_at, cache_target_age, name, query, hasMore, created_by, updated_at, alerts, tags, last_modified_at, deleted, order, is_cached, effective_restriction_level, result, timezone),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_cancel_insights(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insights/cancel/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("effective_privilege_level") {
body.insert("effective_privilege_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query_status") {
body.insert("query_status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_refresh") {
body.insert("last_refresh".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hogql") {
body.insert("hogql".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("favorited") {
body.insert("favorited".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dashboards") {
body.insert("dashboards".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_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resolved_date_range") {
body.insert("resolved_date_range".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dashboard_tiles") {
body.insert("dashboard_tiles".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_name") {
body.insert("derived_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("types") {
body.insert("types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("columns") {
body.insert("columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("next_allowed_client_refresh") {
body.insert(
"next_allowed_client_refresh".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_sample") {
body.insert("is_sample".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_viewed_at") {
body.insert("last_viewed_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cache_target_age") {
body.insert("cache_target_age".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("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hasMore") {
body.insert("hasMore".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("alerts") {
body.insert("alerts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("order") {
body.insert("order".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_cached") {
body.insert("is_cached".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_restriction_level") {
body.insert(
"effective_restriction_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("result") {
body.insert("result".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".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/projects/{{project_id}}/insights/cancel/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update insights
///
/// Method: PATCH /api/projects/{project_id}/insights/{id}/
#[actor(
PosthogUpdateInsightsActor,
inports::<100>(format, id, project_id, name, description, derived_name, types, tags, order, last_refresh, short_id, updated_at, user_access_level, favorited, hogql, created_at, last_viewed_at, hasMore, next_allowed_client_refresh, created_by, create_in_folder, is_sample, last_modified_by, cache_target_age, columns, is_cached, alerts, query_status, effective_privilege_level, deleted, resolved_date_range, result, query, timezone, effective_restriction_level, dashboards, dashboard_tiles, last_modified_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_insights(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insights/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
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("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_name") {
body.insert("derived_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("types") {
body.insert("types".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tags") {
body.insert("tags".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("order") {
body.insert("order".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_refresh") {
body.insert("last_refresh".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("favorited") {
body.insert("favorited".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hogql") {
body.insert("hogql".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_viewed_at") {
body.insert("last_viewed_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("hasMore") {
body.insert("hasMore".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("next_allowed_client_refresh") {
body.insert(
"next_allowed_client_refresh".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_sample") {
body.insert("is_sample".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cache_target_age") {
body.insert("cache_target_age".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("columns") {
body.insert("columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_cached") {
body.insert("is_cached".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("alerts") {
body.insert("alerts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query_status") {
body.insert("query_status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_privilege_level") {
body.insert("effective_privilege_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("resolved_date_range") {
body.insert("resolved_date_range".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("result") {
body.insert("result".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("timezone") {
body.insert("timezone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("effective_restriction_level") {
body.insert(
"effective_restriction_level".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("dashboards") {
body.insert("dashboards".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("dashboard_tiles") {
body.insert("dashboard_tiles".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_at") {
body.insert("last_modified_at".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/projects/{{project_id}}/insights/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/insights/{id}/
#[actor(
PosthogDeleteInsightsActor,
inports::<100>(format, id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_insights(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insights/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("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!(
"DELETE /api/projects/{{project_id}}/insights/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// analyze insights
///
/// Method: GET /api/projects/{project_id}/insights/{id}/analyze/
#[actor(
PosthogAnalyzeInsightsActor,
inports::<100>(format, id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_analyze_insights(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/insights/{id}/analyze/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("format") {
query_pairs.push(("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/projects/{{project_id}}/insights/{{id}}/analyze/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete breakpoints for live debugging.
///
/// Method: POST /api/projects/{project_id}/live_debugger_breakpoints/
#[actor(
PosthogCreateLiveDebuggerBreakpointsActor,
inports::<100>(project_id, id, enabled, updated_at, filename, condition, line_number, created_at, repository),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_live_debugger_breakpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/live_debugger_breakpoints/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filename") {
body.insert("filename".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("condition") {
body.insert("condition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("line_number") {
body.insert("line_number".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("repository") {
body.insert("repository".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/projects/{{project_id}}/live_debugger_breakpoints/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete breakpoints for live debugging.
///
/// Method: GET /api/projects/{project_id}/live_debugger_breakpoints/
#[actor(
PosthogReadLiveDebuggerBreakpointsActor,
inports::<100>(filename, limit, offset, project_id, repository),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_live_debugger_breakpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/live_debugger_breakpoints/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("filename") {
query_pairs.push(("filename", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("repository") {
query_pairs.push(("repository", 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/projects/{{project_id}}/live_debugger_breakpoints/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete breakpoints for live debugging.
///
/// Method: PUT /api/projects/{project_id}/live_debugger_breakpoints/{id}/
#[actor(
PosthogUpdateLiveDebuggerBreakpointsActor,
inports::<100>(id, project_id, line_number, condition, repository, enabled, filename, created_at, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_live_debugger_breakpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/live_debugger_breakpoints/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("line_number") {
body.insert("line_number".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("condition") {
body.insert("condition".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("repository") {
body.insert("repository".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filename") {
body.insert("filename".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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/projects/{{project_id}}/live_debugger_breakpoints/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Create, Read, Update and Delete breakpoints for live debugging.
///
/// Method: DELETE /api/projects/{project_id}/live_debugger_breakpoints/{id}/
#[actor(
PosthogDeleteLiveDebuggerBreakpointsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_live_debugger_breakpoints(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/live_debugger_breakpoints/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/live_debugger_breakpoints/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read logs
///
/// Method: GET /api/projects/{project_id}/logs/alerts/
#[actor(
PosthogReadLogsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_logs(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/logs/alerts/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/logs/alerts/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update logs
///
/// Method: PUT /api/projects/{project_id}/logs/alerts/{id}/
#[actor(
PosthogUpdateLogsActor,
inports::<100>(id, project_id, check_interval_minutes, created_at, next_check_at, datapoints_to_alarm, filters, last_checked_at, threshold_count, created_by, enabled, cooldown_minutes, evaluation_periods, state, name, updated_at, consecutive_failures, threshold_operator, last_notified_at, window_minutes, snooze_until),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_logs(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/logs/alerts/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("check_interval_minutes") {
body.insert("check_interval_minutes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("next_check_at") {
body.insert("next_check_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("datapoints_to_alarm") {
body.insert("datapoints_to_alarm".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_checked_at") {
body.insert("last_checked_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("threshold_count") {
body.insert("threshold_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("cooldown_minutes") {
body.insert("cooldown_minutes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("evaluation_periods") {
body.insert("evaluation_periods".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("consecutive_failures") {
body.insert("consecutive_failures".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("threshold_operator") {
body.insert("threshold_operator".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_notified_at") {
body.insert("last_notified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("window_minutes") {
body.insert("window_minutes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("snooze_until") {
body.insert("snooze_until".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/projects/{{project_id}}/logs/alerts/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete logs
///
/// Method: DELETE /api/projects/{project_id}/logs/alerts/{id}/
#[actor(
PosthogDeleteLogsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_logs(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/logs/alerts/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/logs/alerts/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// export logs
///
/// Method: POST /api/projects/{project_id}/logs/export/
#[actor(
PosthogExportLogsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_export_logs(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/logs/export/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 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/projects/{{project_id}}/logs/export/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// The API for interacting with Notebooks. This feature is in early access and the API can have breaking changes without announcement.
///
/// Method: POST /api/projects/{project_id}/notebooks/
#[actor(
PosthogCreateNotebooksActor,
inports::<100>(project_id, created_by, deleted, id, created_at, last_modified_by, short_id, title, user_access_level, create_in_folder, text_content, version, last_modified_at, content),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_notebooks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/notebooks/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("text_content") {
body.insert("text_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("content") {
body.insert("content".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/projects/{{project_id}}/notebooks/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// The API for interacting with Notebooks. This feature is in early access and the API can have breaking changes without announcement.
///
/// Method: GET /api/projects/{project_id}/notebooks/
#[actor(
PosthogReadNotebooksActor,
inports::<100>(contains, created_by, date_from, date_to, limit, offset, project_id, user),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_notebooks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/notebooks/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("contains") {
query_pairs.push(("contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("created_by") {
query_pairs.push(("created_by", super::message_to_str(val)));
}
if let Some(val) = inputs.get("date_from") {
query_pairs.push(("date_from", super::message_to_str(val)));
}
if let Some(val) = inputs.get("date_to") {
query_pairs.push(("date_to", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("user") {
query_pairs.push(("user", 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/projects/{{project_id}}/notebooks/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/notebooks/{short_id}/
#[actor(
PosthogDeleteNotebooksActor,
inports::<100>(project_id, short_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_notebooks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/notebooks/{short_id}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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/projects/{{project_id}}/notebooks/{{short_id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// The API for interacting with Notebooks. This feature is in early access and the API can have breaking changes without announcement.
///
/// Method: PUT /api/projects/{project_id}/notebooks/{short_id}/
#[actor(
PosthogUpdateNotebooksActor,
inports::<100>(project_id, short_id, last_modified_at, id, last_modified_by, text_content, title, content, user_access_level, version, create_in_folder, created_at, created_by, deleted),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_notebooks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/notebooks/{short_id}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("text_content") {
body.insert("text_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("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("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".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/projects/{{project_id}}/notebooks/{{short_id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// The API for interacting with Notebooks. This feature is in early access and the API can have breaking changes without announcement.
///
/// Method: POST /api/projects/{project_id}/notebooks/{short_id}/kernel/start/
#[actor(
PosthogStartNotebooksActor,
inports::<100>(project_id, short_id, id, create_in_folder, last_modified_at, created_at, title, user_access_level, version, text_content, created_by, deleted, content, last_modified_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_start_notebooks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/notebooks/{short_id}/kernel/start/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("text_content") {
body.insert("text_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".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("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_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/projects/{{project_id}}/notebooks/{{short_id}}/kernel/start/ failed: {}", e).into()));
}
}
Ok(output)
}
/// The API for interacting with Notebooks. This feature is in early access and the API can have breaking changes without announcement.
///
/// Method: POST /api/projects/{project_id}/notebooks/{short_id}/kernel/stop/
#[actor(
PosthogStopNotebooksActor,
inports::<100>(project_id, short_id, created_at, text_content, content, id, user_access_level, deleted, last_modified_by, title, version, last_modified_at, create_in_folder, created_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_stop_notebooks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/notebooks/{short_id}/kernel/stop/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("text_content") {
body.insert("text_content".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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("version") {
body.insert("version".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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/projects/{{project_id}}/notebooks/{{short_id}}/kernel/stop/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create object media previews
///
/// Method: POST /api/projects/{project_id}/object_media_previews/
#[actor(
PosthogCreateObjectMediaPreviewsActor,
inports::<100>(project_id, metadata, media_type, created_at, exported_asset_id, id, event_definition_id, media_url, updated_at, uploaded_media_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_object_media_previews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/object_media_previews/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("metadata") {
body.insert("metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("media_type") {
body.insert("media_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("exported_asset_id") {
body.insert("exported_asset_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("event_definition_id") {
body.insert("event_definition_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("media_url") {
body.insert("media_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uploaded_media_id") {
body.insert("uploaded_media_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/projects/{{project_id}}/object_media_previews/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read object media previews
///
/// Method: GET /api/projects/{project_id}/object_media_previews/
#[actor(
PosthogReadObjectMediaPreviewsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_object_media_previews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/object_media_previews/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/object_media_previews/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update object media previews
///
/// Method: PATCH /api/projects/{project_id}/object_media_previews/{id}/
#[actor(
PosthogUpdateObjectMediaPreviewsActor,
inports::<100>(id, project_id, created_at, media_url, metadata, uploaded_media_id, event_definition_id, media_type, exported_asset_id, updated_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_object_media_previews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/object_media_previews/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("media_url") {
body.insert("media_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("metadata") {
body.insert("metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uploaded_media_id") {
body.insert("uploaded_media_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("event_definition_id") {
body.insert("event_definition_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("media_type") {
body.insert("media_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("exported_asset_id") {
body.insert("exported_asset_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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/projects/{{project_id}}/object_media_previews/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete object media previews
///
/// Method: DELETE /api/projects/{project_id}/object_media_previews/{id}/
#[actor(
PosthogDeleteObjectMediaPreviewsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_object_media_previews(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/object_media_previews/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/object_media_previews/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create persisted folder
///
/// Method: POST /api/projects/{project_id}/persisted_folder/
#[actor(
PosthogCreatePersistedFolderActor,
inports::<100>(project_id, type_, updated_at, created_at, path, id, protocol),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_persisted_folder(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persisted_folder/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("type_") {
body.insert("type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path") {
body.insert("path".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("protocol") {
body.insert("protocol".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/projects/{{project_id}}/persisted_folder/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read persisted folder
///
/// Method: GET /api/projects/{project_id}/persisted_folder/
#[actor(
PosthogReadPersistedFolderActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_persisted_folder(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persisted_folder/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/persisted_folder/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update persisted folder
///
/// Method: PUT /api/projects/{project_id}/persisted_folder/{id}/
#[actor(
PosthogUpdatePersistedFolderActor,
inports::<100>(id, project_id, type_, created_at, protocol, updated_at, path),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_persisted_folder(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persisted_folder/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("type_") {
body.insert("type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("protocol") {
body.insert("protocol".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("path") {
body.insert("path".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/projects/{{project_id}}/persisted_folder/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete persisted folder
///
/// Method: DELETE /api/projects/{project_id}/persisted_folder/{id}/
#[actor(
PosthogDeletePersistedFolderActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_persisted_folder(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persisted_folder/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/persisted_folder/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// This endpoint is meant for reading and deleting persons. To create or update persons, we recommend using the [capture API](https://posthog.com/docs/api/capture), the `$set` and `$unset` [properties](https://posthog.com/docs/product-analytics/user-properties), or one of our SDKs.
///
/// Method: GET /api/projects/{project_id}/persons/
#[actor(
PosthogReadPersonsActor,
inports::<100>(distinct_id, email, format, limit, offset, project_id, properties, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_persons(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persons/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("distinct_id") {
query_pairs.push(("distinct_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("email") {
query_pairs.push(("email", super::message_to_str(val)));
}
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("properties") {
query_pairs.push(("properties", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/projects/{{project_id}}/persons/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// This endpoint is meant for reading and deleting persons. To create or update persons, we recommend using the [capture API](https://posthog.com/docs/api/capture), the `$set` and `$unset` [properties](https://posthog.com/docs/product-analytics/user-properties), or one of our SDKs.
///
/// Method: POST /api/projects/{project_id}/persons/batch_by_distinct_ids/
#[actor(
PosthogCreatePersonsActor,
inports::<100>(format, project_id, properties, created_at, last_seen_at, id, name, uuid, distinct_ids),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_persons(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persons/batch_by_distinct_ids/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("properties") {
body.insert("properties".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_seen_at") {
body.insert("last_seen_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".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("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("distinct_ids") {
body.insert("distinct_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/projects/{{project_id}}/persons/batch_by_distinct_ids/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Only for setting properties on the person. \"properties\" from the request data will be updated via a \"$set\" event.\nThis means that only the properties listed will be updated, but other properties won't be removed nor updated.\nIf you would like to remove a property use the `delete_property` endpoint.
///
/// Method: PUT /api/projects/{project_id}/persons/{id}/
#[actor(
PosthogUpdatePersonsActor,
inports::<100>(format, id, project_id, created_at, distinct_ids, name, last_seen_at, uuid, properties),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_persons(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persons/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("distinct_ids") {
body.insert("distinct_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".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("last_seen_at") {
body.insert("last_seen_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("properties") {
body.insert("properties".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/projects/{{project_id}}/persons/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// This endpoint is meant for reading and deleting persons. To create or update persons, we recommend using the [capture API](https://posthog.com/docs/api/capture), the `$set` and `$unset` [properties](https://posthog.com/docs/product-analytics/user-properties), or one of our SDKs.
///
/// Method: POST /api/projects/{project_id}/persons/{id}/split/
#[actor(
PosthogSplitPersonsActor,
inports::<100>(format, id, project_id, properties, uuid, distinct_ids, created_at, name, last_seen_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_split_persons(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/persons/{id}/split/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("format") {
query_pairs.push(("format", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("properties") {
body.insert("properties".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("uuid") {
body.insert("uuid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("distinct_ids") {
body.insert("distinct_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("last_seen_at") {
body.insert("last_seen_at".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/projects/{{project_id}}/persons/{{id}}/split/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read plugin configs
///
/// Method: GET /api/projects/{project_id}/plugin_configs/{plugin_config_id}/logs/
#[actor(
PosthogReadPluginConfigsActor,
inports::<100>(limit, offset, plugin_config_id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_plugin_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/plugin_configs/{plugin_config_id}/logs/".to_string();
if let Some(val) = inputs.get("plugin_config_id") {
endpoint = endpoint.replace("{{plugin_config_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/plugin_configs/{{plugin_config_id}}/logs/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read product tours
///
/// Method: GET /api/projects/{project_id}/product_tours/
#[actor(
PosthogReadProductToursActor,
inports::<100>(limit, offset, project_id, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_product_tours(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/product_tours/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/projects/{{project_id}}/product_tours/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create product tours
///
/// Method: POST /api/projects/{project_id}/product_tours/
#[actor(
PosthogCreateProductToursActor,
inports::<100>(project_id, end_date, linked_flag_id, updated_at, created_by, description, auto_launch, linked_flag, creation_context, id, internal_targeting_flag, archived, content, created_at, targeting_flag_filters, name, start_date),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_product_tours(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/product_tours/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("end_date") {
body.insert("end_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag_id") {
body.insert("linked_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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("auto_launch") {
body.insert("auto_launch".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag") {
body.insert("linked_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("creation_context") {
body.insert("creation_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("internal_targeting_flag") {
body.insert("internal_targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("archived") {
body.insert("archived".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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag_filters") {
body.insert("targeting_flag_filters".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("start_date") {
body.insert("start_date".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/projects/{{project_id}}/product_tours/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete product tours
///
/// Method: DELETE /api/projects/{project_id}/product_tours/{id}/
#[actor(
PosthogDeleteProductToursActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_product_tours(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/product_tours/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/product_tours/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update product tours
///
/// Method: PATCH /api/projects/{project_id}/product_tours/{id}/
#[actor(
PosthogUpdateProductToursActor,
inports::<100>(id, project_id, start_date, archived, created_by, created_at, content, creation_context, linked_flag, targeting_flag_filters, linked_flag_id, updated_at, auto_launch, end_date, internal_targeting_flag, name, description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_product_tours(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/product_tours/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("start_date") {
body.insert("start_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("archived") {
body.insert("archived".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("creation_context") {
body.insert("creation_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag") {
body.insert("linked_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag_filters") {
body.insert("targeting_flag_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag_id") {
body.insert("linked_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("auto_launch") {
body.insert("auto_launch".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("end_date") {
body.insert("end_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("internal_targeting_flag") {
body.insert("internal_targeting_flag".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("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/projects/{{project_id}}/product_tours/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Generate tour step content using AI.
///
/// Method: POST /api/projects/{project_id}/product_tours/{id}/generate/
#[actor(
PosthogGenerateProductToursActor,
inports::<100>(id, project_id, steps, title, goal),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_generate_product_tours(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/product_tours/{id}/generate/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("steps") {
body.insert("steps".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("goal") {
body.insert("goal".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/projects/{{project_id}}/product_tours/{{id}}/generate/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create query
///
/// Method: POST /api/projects/{project_id}/query/
#[actor(
PosthogCreateQueryActor,
inports::<100>(project_id, client_query_id, limit_context, refresh, filters_override, query, async_, variables_override, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_query(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/query/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("client_query_id") {
body.insert("client_query_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("limit_context") {
body.insert("limit_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("refresh") {
body.insert("refresh".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters_override") {
body.insert("filters_override".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("async_") {
body.insert("async".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("variables_override") {
body.insert("variables_override".to_string(), val.clone().into());
}
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 /api/projects/{{project_id}}/query/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read query
///
/// Method: GET /api/projects/{project_id}/query/draft_sql/
#[actor(
PosthogReadQueryActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_query(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/query/draft_sql/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/query/draft_sql/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// (Experimental)
///
/// Method: DELETE /api/projects/{project_id}/query/{id}/
#[actor(
PosthogDeleteQueryActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_query(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/query/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/query/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create saved
///
/// Method: POST /api/projects/{project_id}/saved/
#[actor(
PosthogCreateSavedActor,
inports::<100>(project_id, data_url, deleted, snapshots, updated_at, short_id, target_widths, has_content, id, type_, created_by, exception, url, name, status, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_saved(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/saved/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("data_url") {
body.insert("data_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("snapshots") {
body.insert("snapshots".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("target_widths") {
body.insert("target_widths".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_content") {
body.insert("has_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".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("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("exception") {
body.insert("exception".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("url") {
body.insert("url".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("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/saved/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read saved
///
/// Method: GET /api/projects/{project_id}/saved/
#[actor(
PosthogReadSavedActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_saved(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/saved/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/saved/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/saved/{short_id}/
#[actor(
PosthogDeleteSavedActor,
inports::<100>(project_id, short_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_saved(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/saved/{short_id}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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/projects/{{project_id}}/saved/{{short_id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update saved
///
/// Method: PATCH /api/projects/{project_id}/saved/{short_id}/
#[actor(
PosthogUpdateSavedActor,
inports::<100>(project_id, short_id, created_at, id, deleted, status, target_widths, exception, url, updated_at, name, data_url, has_content, snapshots, created_by, type_),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_saved(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/saved/{short_id}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("target_widths") {
body.insert("target_widths".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("exception") {
body.insert("exception".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("url") {
body.insert("url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".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("data_url") {
body.insert("data_url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("has_content") {
body.insert("has_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("snapshots") {
body.insert("snapshots".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("type_") {
body.insert("type".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/projects/{{project_id}}/saved/{{short_id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read schema property groups
///
/// Method: GET /api/projects/{project_id}/schema_property_groups/
#[actor(
PosthogReadSchemaPropertyGroupsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_schema_property_groups(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/schema_property_groups/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/schema_property_groups/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create schema property groups
///
/// Method: POST /api/projects/{project_id}/schema_property_groups/
#[actor(
PosthogCreateSchemaPropertyGroupsActor,
inports::<100>(project_id, id, description, properties, events, name, updated_at, created_at, created_by),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_schema_property_groups(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/schema_property_groups/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".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("properties") {
body.insert("properties".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("events") {
body.insert("events".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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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/projects/{{project_id}}/schema_property_groups/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update schema property groups
///
/// Method: PATCH /api/projects/{project_id}/schema_property_groups/{id}/
#[actor(
PosthogUpdateSchemaPropertyGroupsActor,
inports::<100>(id, project_id, updated_at, description, created_at, properties, created_by, events, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_schema_property_groups(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/schema_property_groups/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("updated_at") {
body.insert("updated_at".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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("properties") {
body.insert("properties".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("events") {
body.insert("events".to_string(), val.clone().into());
}
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!("PATCH /api/projects/{{project_id}}/schema_property_groups/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// delete schema property groups
///
/// Method: DELETE /api/projects/{project_id}/schema_property_groups/{id}/
#[actor(
PosthogDeleteSchemaPropertyGroupsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_schema_property_groups(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/schema_property_groups/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/schema_property_groups/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// API for retrieving and managing stored group session summaries.
///
/// Method: POST /api/projects/{project_id}/session_group_summaries/
#[actor(
PosthogCreateSessionGroupSummariesActor,
inports::<100>(project_id, team, extra_summary_context, id, session_ids, summary, created_by, created_at, run_metadata, title),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_session_group_summaries(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/session_group_summaries/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("team") {
body.insert("team".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_summary_context") {
body.insert("extra_summary_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_ids") {
body.insert("session_ids".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("summary") {
body.insert("summary".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("run_metadata") {
body.insert("run_metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".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/projects/{{project_id}}/session_group_summaries/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// API for retrieving and managing stored group session summaries.
///
/// Method: GET /api/projects/{project_id}/session_group_summaries/
#[actor(
PosthogReadSessionGroupSummariesActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_session_group_summaries(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/session_group_summaries/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/session_group_summaries/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// API for retrieving and managing stored group session summaries.
///
/// Method: PUT /api/projects/{project_id}/session_group_summaries/{id}/
#[actor(
PosthogUpdateSessionGroupSummariesActor,
inports::<100>(id, project_id, summary, created_at, team, created_by, run_metadata, extra_summary_context, title, session_ids),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_session_group_summaries(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/session_group_summaries/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("summary") {
body.insert("summary".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("team") {
body.insert("team".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("run_metadata") {
body.insert("run_metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("extra_summary_context") {
body.insert("extra_summary_context".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("session_ids") {
body.insert("session_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!("PUT /api/projects/{{project_id}}/session_group_summaries/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// API for retrieving and managing stored group session summaries.
///
/// Method: DELETE /api/projects/{project_id}/session_group_summaries/{id}/
#[actor(
PosthogDeleteSessionGroupSummariesActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_session_group_summaries(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/session_group_summaries/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/session_group_summaries/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// create replay
///
/// Method: POST /api/projects/{project_id}/session_recording_playlists/
#[actor(
PosthogCreateReplayActor,
inports::<100>(project_id, created_at, description, last_modified_at, deleted, derived_name, created_by, recordings_counts, filters, name, pinned, short_id, last_modified_by, is_synthetic, id, type_, create_in_folder),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_replay(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/session_recording_playlists/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_at") {
body.insert("created_at".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("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_name") {
body.insert("derived_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recordings_counts") {
body.insert("recordings_counts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".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("pinned") {
body.insert("pinned".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_synthetic") {
body.insert("is_synthetic".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".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("create_in_folder") {
body.insert("_create_in_folder".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/projects/{{project_id}}/session_recording_playlists/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Override list to include synthetic playlists
///
/// Method: GET /api/projects/{project_id}/session_recording_playlists/
#[actor(
PosthogReadReplayActor,
inports::<100>(created_by, limit, offset, project_id, short_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_replay(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/session_recording_playlists/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_by") {
query_pairs.push(("created_by", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("short_id") {
query_pairs.push(("short_id", 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/projects/{{project_id}}/session_recording_playlists/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Hard delete of this model is not allowed. Use a patch API call to set \"deleted\" to true
///
/// Method: DELETE /api/projects/{project_id}/session_recording_playlists/{short_id}/
#[actor(
PosthogDeleteReplayActor,
inports::<100>(project_id, short_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_replay(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/session_recording_playlists/{short_id}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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/projects/{{project_id}}/session_recording_playlists/{{short_id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// update replay
///
/// Method: PUT /api/projects/{project_id}/session_recording_playlists/{short_id}/
#[actor(
PosthogUpdateReplayActor,
inports::<100>(project_id, short_id, deleted, create_in_folder, filters, recordings_counts, created_by, created_at, last_modified_by, type_, name, description, last_modified_at, derived_name, is_synthetic, pinned, id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_replay(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/session_recording_playlists/{short_id}/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("short_id") {
endpoint = endpoint.replace("{{short_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("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("short_id") {
body.insert("short_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("filters") {
body.insert("filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("recordings_counts") {
body.insert("recordings_counts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_modified_by") {
body.insert("last_modified_by".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("name") {
body.insert("name".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("last_modified_at") {
body.insert("last_modified_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("derived_name") {
body.insert("derived_name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_synthetic") {
body.insert("is_synthetic".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("pinned") {
body.insert("pinned".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("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!("PUT /api/projects/{{project_id}}/session_recording_playlists/{{short_id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read sessions
///
/// Method: GET /api/projects/{project_id}/sessions/property_definitions/
#[actor(
PosthogReadSessionsActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_sessions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/sessions/property_definitions/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/sessions/property_definitions/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read signal source configs
///
/// Method: GET /api/projects/{project_id}/signal_source_configs/
#[actor(
PosthogReadSignalSourceConfigsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_signal_source_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/signal_source_configs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/signal_source_configs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create signal source configs
///
/// Method: POST /api/projects/{project_id}/signal_source_configs/
#[actor(
PosthogCreateSignalSourceConfigsActor,
inports::<100>(project_id, source_type, status, id, config, enabled, source_product, updated_at, created_at),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_signal_source_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/signal_source_configs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("source_type") {
body.insert("source_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("config") {
body.insert("config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("source_product") {
body.insert("source_product".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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/projects/{{project_id}}/signal_source_configs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update signal source configs
///
/// Method: PUT /api/projects/{project_id}/signal_source_configs/{id}/
#[actor(
PosthogUpdateSignalSourceConfigsActor,
inports::<100>(id, project_id, updated_at, config, status, created_at, enabled, source_type, source_product),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_signal_source_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/signal_source_configs/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("updated_at") {
body.insert("updated_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("config") {
body.insert("config".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enabled") {
body.insert("enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("source_type") {
body.insert("source_type".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("source_product") {
body.insert("source_product".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/projects/{{project_id}}/signal_source_configs/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete signal source configs
///
/// Method: DELETE /api/projects/{project_id}/signal_source_configs/{id}/
#[actor(
PosthogDeleteSignalSourceConfigsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_signal_source_configs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/signal_source_configs/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/signal_source_configs/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// read surveys
///
/// Method: GET /api/projects/{project_id}/surveys/
#[actor(
PosthogReadSurveysActor,
inports::<100>(archived, limit, offset, project_id, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_surveys(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/surveys/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("archived") {
query_pairs.push(("archived", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/projects/{{project_id}}/surveys/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// create surveys
///
/// Method: POST /api/projects/{project_id}/surveys/
#[actor(
PosthogCreateSurveysActor,
inports::<100>(project_id, linked_flag_id, remove_targeting_flag, response_sampling_daily_limits, schedule, id, created_by, appearance, questions, current_iteration_start_date, response_sampling_limit, archived, targeting_flag_filters, form_content, responses_limit, iteration_start_dates, end_date, iteration_count, create_in_folder, enable_partial_responses, internal_targeting_flag, iteration_frequency_days, response_sampling_interval, targeting_flag, linked_flag, linked_insight_id, description, start_date, created_at, type_, enable_iframe_embedding, current_iteration, name, response_sampling_interval_type, targeting_flag_id, response_sampling_start_date, conditions, translations),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_surveys(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/surveys/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("linked_flag_id") {
body.insert("linked_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("remove_targeting_flag") {
body.insert("remove_targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_daily_limits") {
body.insert(
"response_sampling_daily_limits".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("schedule") {
body.insert("schedule".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("appearance") {
body.insert("appearance".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("questions") {
body.insert("questions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("current_iteration_start_date") {
body.insert(
"current_iteration_start_date".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("response_sampling_limit") {
body.insert("response_sampling_limit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("archived") {
body.insert("archived".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag_filters") {
body.insert("targeting_flag_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("form_content") {
body.insert("form_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("responses_limit") {
body.insert("responses_limit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_start_dates") {
body.insert("iteration_start_dates".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("end_date") {
body.insert("end_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_count") {
body.insert("iteration_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enable_partial_responses") {
body.insert("enable_partial_responses".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("internal_targeting_flag") {
body.insert("internal_targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_frequency_days") {
body.insert("iteration_frequency_days".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_interval") {
body.insert("response_sampling_interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag") {
body.insert("targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag") {
body.insert("linked_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_insight_id") {
body.insert("linked_insight_id".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("start_date") {
body.insert("start_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("enable_iframe_embedding") {
body.insert("enable_iframe_embedding".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("current_iteration") {
body.insert("current_iteration".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("response_sampling_interval_type") {
body.insert(
"response_sampling_interval_type".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("targeting_flag_id") {
body.insert("targeting_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_start_date") {
body.insert(
"response_sampling_start_date".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("conditions") {
body.insert("conditions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("translations") {
body.insert("translations".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/projects/{{project_id}}/surveys/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// delete surveys
///
/// Method: DELETE /api/projects/{project_id}/surveys/{id}/
#[actor(
PosthogDeleteSurveysActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_surveys(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/surveys/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/surveys/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update surveys
///
/// Method: PUT /api/projects/{project_id}/surveys/{id}/
#[actor(
PosthogUpdateSurveysActor,
inports::<100>(id, project_id, start_date, iteration_start_dates, appearance, archived, iteration_frequency_days, enable_iframe_embedding, iteration_count, type_, current_iteration_start_date, enable_partial_responses, response_sampling_start_date, responses_limit, name, response_sampling_interval, feature_flag_keys, current_iteration, linked_flag_id, conditions, internal_targeting_flag, targeting_flag, translations, response_sampling_limit, user_access_level, created_at, description, questions, linked_insight_id, end_date, response_sampling_daily_limits, response_sampling_interval_type, schedule, linked_flag, created_by, form_content),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_surveys(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/surveys/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("start_date") {
body.insert("start_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_start_dates") {
body.insert("iteration_start_dates".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("appearance") {
body.insert("appearance".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("archived") {
body.insert("archived".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_frequency_days") {
body.insert("iteration_frequency_days".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enable_iframe_embedding") {
body.insert("enable_iframe_embedding".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_count") {
body.insert("iteration_count".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("current_iteration_start_date") {
body.insert(
"current_iteration_start_date".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("enable_partial_responses") {
body.insert("enable_partial_responses".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_start_date") {
body.insert(
"response_sampling_start_date".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("responses_limit") {
body.insert("responses_limit".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("response_sampling_interval") {
body.insert("response_sampling_interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_keys") {
body.insert("feature_flag_keys".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("current_iteration") {
body.insert("current_iteration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag_id") {
body.insert("linked_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("conditions") {
body.insert("conditions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("internal_targeting_flag") {
body.insert("internal_targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag") {
body.insert("targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("translations") {
body.insert("translations".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_limit") {
body.insert("response_sampling_limit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_access_level") {
body.insert("user_access_level".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".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("questions") {
body.insert("questions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_insight_id") {
body.insert("linked_insight_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("end_date") {
body.insert("end_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_daily_limits") {
body.insert(
"response_sampling_daily_limits".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("response_sampling_interval_type") {
body.insert(
"response_sampling_interval_type".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("schedule") {
body.insert("schedule".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag") {
body.insert("linked_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("form_content") {
body.insert("form_content".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/projects/{{project_id}}/surveys/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Archive a single survey response.
///
/// Method: POST /api/projects/{project_id}/surveys/{id}/responses/{response_uuid}/archive/
#[actor(
PosthogArchiveSurveysActor,
inports::<100>(id, project_id, response_uuid, conditions, iteration_frequency_days, iteration_start_dates, type_, end_date, iteration_count, form_content, linked_flag_id, response_sampling_interval, response_sampling_interval_type, create_in_folder, response_sampling_limit, created_at, responses_limit, targeting_flag_id, questions, created_by, start_date, archived, enable_partial_responses, current_iteration, linked_flag, current_iteration_start_date, internal_targeting_flag, name, translations, targeting_flag_filters, linked_insight_id, appearance, remove_targeting_flag, schedule, enable_iframe_embedding, response_sampling_start_date, targeting_flag, description, response_sampling_daily_limits),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_archive_surveys(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/surveys/{id}/responses/{response_uuid}/archive/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("response_uuid") {
endpoint = endpoint.replace("{{response_uuid}}", &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("conditions") {
body.insert("conditions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_frequency_days") {
body.insert("iteration_frequency_days".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_start_dates") {
body.insert("iteration_start_dates".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("end_date") {
body.insert("end_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("iteration_count") {
body.insert("iteration_count".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("form_content") {
body.insert("form_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag_id") {
body.insert("linked_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_interval") {
body.insert("response_sampling_interval".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_interval_type") {
body.insert(
"response_sampling_interval_type".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("create_in_folder") {
body.insert("_create_in_folder".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_limit") {
body.insert("response_sampling_limit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("responses_limit") {
body.insert("responses_limit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag_id") {
body.insert("targeting_flag_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("questions") {
body.insert("questions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("start_date") {
body.insert("start_date".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("archived") {
body.insert("archived".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enable_partial_responses") {
body.insert("enable_partial_responses".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("current_iteration") {
body.insert("current_iteration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_flag") {
body.insert("linked_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("current_iteration_start_date") {
body.insert(
"current_iteration_start_date".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("internal_targeting_flag") {
body.insert("internal_targeting_flag".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("translations") {
body.insert("translations".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("targeting_flag_filters") {
body.insert("targeting_flag_filters".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("linked_insight_id") {
body.insert("linked_insight_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("appearance") {
body.insert("appearance".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("remove_targeting_flag") {
body.insert("remove_targeting_flag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("schedule") {
body.insert("schedule".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("enable_iframe_embedding") {
body.insert("enable_iframe_embedding".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("response_sampling_start_date") {
body.insert(
"response_sampling_start_date".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("targeting_flag") {
body.insert("targeting_flag".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("response_sampling_daily_limits") {
body.insert(
"response_sampling_daily_limits".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/projects/{{project_id}}/surveys/{{id}}/responses/{{response_uuid}}/archive/ failed: {}", e).into()));
}
}
Ok(output)
}
/// API for managing tasks within a project. Tasks represent units of work to be performed by an agent.
///
/// Method: POST /api/projects/{project_id}/tasks/
#[actor(
PosthogCreateTasksActor,
inports::<100>(project_id, description, title, assignee),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_tasks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("title") {
body.insert("title".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("assignee") {
body.insert("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/projects/{{project_id}}/tasks/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// List tasks
///
/// Method: GET /api/projects/{project_id}/tasks/
#[actor(
PosthogReadTasksActor,
inports::<100>(created_by, limit, offset, organization, origin_product, project_id, repository, stage),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_tasks(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("created_by") {
query_pairs.push(("created_by", 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("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("organization") {
query_pairs.push(("organization", super::message_to_str(val)));
}
if let Some(val) = inputs.get("origin_product") {
query_pairs.push(("origin_product", super::message_to_str(val)));
}
if let Some(val) = inputs.get("repository") {
query_pairs.push(("repository", super::message_to_str(val)));
}
if let Some(val) = inputs.get("stage") {
query_pairs.push(("stage", 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/projects/{{project_id}}/tasks/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// API for managing tasks within a project. Tasks represent units of work to be performed by an agent.
///
/// Method: PUT /api/projects/{project_id}/tasks/{id}/
#[actor(
PosthogUpdateTasksActor,
inports::<100>(id, project_id, assignee, description, title),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_tasks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("assignee") {
body.insert("assignee".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("title") {
body.insert("title".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/projects/{{project_id}}/tasks/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// API for managing tasks within a project. Tasks represent units of work to be performed by an agent.
///
/// Method: DELETE /api/projects/{project_id}/tasks/{id}/
#[actor(
PosthogDeleteTasksActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_tasks(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/tasks/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// List task runs
///
/// Method: GET /api/projects/{project_id}/tasks/{task_id}/runs/
#[actor(
PosthogReadTaskRunsActor,
inports::<100>(limit, offset, project_id, task_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_task_runs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/{task_id}/runs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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.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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/tasks/{{task_id}}/runs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create task run
///
/// Method: POST /api/projects/{project_id}/tasks/{task_id}/runs/
#[actor(
PosthogCreateTaskRunsActor,
inports::<100>(project_id, task_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_task_runs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/{task_id}/runs/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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.post(&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!(
"POST /api/projects/{{project_id}}/tasks/{{task_id}}/runs/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update task run
///
/// Method: PATCH /api/projects/{project_id}/tasks/{task_id}/runs/{id}/
#[actor(
PosthogUpdateTaskRunsActor,
inports::<100>(id, project_id, task_id, output, stage, error_message, branch, state, status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_task_runs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/tasks/{task_id}/runs/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("output") {
body.insert("output".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("stage") {
body.insert("stage".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("error_message") {
body.insert("error_message".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("branch") {
body.insert("branch".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".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/projects/{{project_id}}/tasks/{{task_id}}/runs/{{id}}/ failed: {}", e).into()));
}
}
Ok(output)
}
/// \n When object storage is available this API allows upload of media which can be used, for example, in text cards on dashboards.\n\n Uploaded media must have a content type beginning with 'image/' and be less than 4MB.\n
///
/// Method: POST /api/projects/{project_id}/uploaded_media/
#[actor(
PosthogUploadEdMediaCreateActor,
inports::<100>(project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_upload_ed_media_create(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/uploaded_media/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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 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/projects/{{project_id}}/uploaded_media/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// List all projects for the team.
///
/// Method: GET /api/projects/{project_id}/visual_review/repos/
#[actor(
PosthogReadVisualReviewActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_visual_review(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/visual_review/repos/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/visual_review/repos/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create a new repo.
///
/// Method: POST /api/projects/{project_id}/visual_review/repos/
#[actor(
PosthogCreateVisualReviewActor,
inports::<100>(project_id, repo_external_id, repo_full_name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_visual_review(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/visual_review/repos/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("repo_external_id") {
body.insert("repo_external_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("repo_full_name") {
body.insert("repo_full_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 /api/projects/{{project_id}}/visual_review/repos/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update a repo's settings.
///
/// Method: PATCH /api/projects/{project_id}/visual_review/repos/{id}/
#[actor(
PosthogUpdateVisualReviewActor,
inports::<100>(id, project_id, baseline_file_paths),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_visual_review(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/visual_review/repos/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("baseline_file_paths") {
body.insert("baseline_file_paths".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/projects/{{project_id}}/visual_review/repos/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Approve visual changes for snapshots in this run.
///
/// Method: POST /api/projects/{project_id}/visual_review/runs/{id}/approve/
#[actor(
PosthogApproveVisualReviewActor,
inports::<100>(id, project_id, commit_to_github, snapshots),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_approve_visual_review(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/visual_review/runs/{id}/approve/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("commit_to_github") {
body.insert("commit_to_github".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("snapshots") {
body.insert("snapshots".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/projects/{{project_id}}/visual_review/runs/{{id}}/approve/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Cancel a running saved query workflow.
///
/// Method: POST /api/projects/{project_id}/warehouse_saved_queries/{id}/cancel/
#[actor(
PosthogCancelDataWarehouseActor,
inports::<100>(id, project_id, sync_frequency, query, status, last_run_at, managed_viewset_kind, is_materialized, latest_error, soft_update, latest_history_id, created_at, columns, created_by, name, deleted, origin, edited_history_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_cancel_data_warehouse(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/api/projects/{project_id}/warehouse_saved_queries/{id}/cancel/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("sync_frequency") {
body.insert("sync_frequency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("query".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("status") {
body.insert("status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("last_run_at") {
body.insert("last_run_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("managed_viewset_kind") {
body.insert("managed_viewset_kind".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_materialized") {
body.insert("is_materialized".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_error") {
body.insert("latest_error".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("soft_update") {
body.insert("soft_update".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("latest_history_id") {
body.insert("latest_history_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("columns") {
body.insert("columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".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("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("origin") {
body.insert("origin".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("edited_history_id") {
body.insert("edited_history_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/projects/{{project_id}}/warehouse_saved_queries/{{id}}/cancel/ failed: {}", e).into()));
}
}
Ok(output)
}
/// Create, Read, Update and Delete Warehouse Tables.
///
/// Method: POST /api/projects/{project_id}/warehouse_tables/
#[actor(
PosthogCreateWarehouseTablesActor,
inports::<100>(project_id, credential, format, created_at, id, name, options, created_by, url_pattern, external_schema, deleted, external_data_source, columns),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_warehouse_tables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/warehouse_tables/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("credential") {
body.insert("credential".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("format") {
body.insert("format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".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("options") {
body.insert("options".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("url_pattern") {
body.insert("url_pattern".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_schema") {
body.insert("external_schema".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_data_source") {
body.insert("external_data_source".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("columns") {
body.insert("columns".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/projects/{{project_id}}/warehouse_tables/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete Warehouse Tables.
///
/// Method: GET /api/projects/{project_id}/warehouse_tables/
#[actor(
PosthogReadWarehouseTablesActor,
inports::<100>(limit, offset, project_id, search),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_warehouse_tables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/warehouse_tables/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("search") {
query_pairs.push(("search", 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/projects/{{project_id}}/warehouse_tables/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete Warehouse Tables.
///
/// Method: PATCH /api/projects/{project_id}/warehouse_tables/{id}/
#[actor(
PosthogUpdateWarehouseTablesActor,
inports::<100>(id, project_id, url_pattern, columns, credential, deleted, external_schema, external_data_source, created_by, created_at, format, name, options),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_warehouse_tables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/warehouse_tables/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("url_pattern") {
body.insert("url_pattern".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("columns") {
body.insert("columns".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("credential") {
body.insert("credential".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deleted") {
body.insert("deleted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_schema") {
body.insert("external_schema".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_data_source") {
body.insert("external_data_source".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_by") {
body.insert("created_by".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("format") {
body.insert("format".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".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("options") {
body.insert("options".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/projects/{{project_id}}/warehouse_tables/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create, Read, Update and Delete Warehouse Tables.
///
/// Method: DELETE /api/projects/{project_id}/warehouse_tables/{id}/
#[actor(
PosthogDeleteWarehouseTablesActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_warehouse_tables(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/warehouse_tables/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/warehouse_tables/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// This endpoint is in Concept state, please join the feature preview to try it out when it's ready. Get a breakdown by a property (e.g. browser, device type, country, etc.).
///
/// Method: GET /api/projects/{project_id}/web_analytics/breakdown/
#[actor(
PosthogReadWebAnalyticsActor,
inports::<100>(apply_path_cleaning, breakdown_by, date_from, date_to, filter_test_accounts, host, limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_web_analytics(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/web_analytics/breakdown/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("apply_path_cleaning") {
query_pairs.push(("apply_path_cleaning", super::message_to_str(val)));
}
if let Some(val) = inputs.get("breakdown_by") {
query_pairs.push(("breakdown_by", super::message_to_str(val)));
}
if let Some(val) = inputs.get("date_from") {
query_pairs.push(("date_from", super::message_to_str(val)));
}
if let Some(val) = inputs.get("date_to") {
query_pairs.push(("date_to", super::message_to_str(val)));
}
if let Some(val) = inputs.get("filter_test_accounts") {
query_pairs.push(("filter_test_accounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("host") {
query_pairs.push(("host", 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("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/web_analytics/breakdown/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// create web experiments
///
/// Method: POST /api/projects/{project_id}/web_experiments/
#[actor(
PosthogCreateWebExperimentsActor,
inports::<100>(project_id, variants, feature_flag_key, created_at, id, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_create_web_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/web_experiments/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("variants") {
body.insert("variants".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_key") {
body.insert("feature_flag_key".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
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 /api/projects/{{project_id}}/web_experiments/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// read web experiments
///
/// Method: GET /api/projects/{project_id}/web_experiments/
#[actor(
PosthogReadWebExperimentsActor,
inports::<100>(limit, offset, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_web_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/web_experiments/".to_string();
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", 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/projects/{{project_id}}/web_experiments/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// delete web experiments
///
/// Method: DELETE /api/projects/{project_id}/web_experiments/{id}/
#[actor(
PosthogDeleteWebExperimentsActor,
inports::<100>(id, project_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_delete_web_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/web_experiments/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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/projects/{{project_id}}/web_experiments/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// update web experiments
///
/// Method: PUT /api/projects/{project_id}/web_experiments/{id}/
#[actor(
PosthogUpdateWebExperimentsActor,
inports::<100>(id, project_id, name, variants, created_at, feature_flag_key),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_web_experiments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/projects/{project_id}/web_experiments/{id}/".to_string();
if let Some(val) = inputs.get("id") {
endpoint = endpoint.replace("{{id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("project_id") {
endpoint = endpoint.replace("{{project_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("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("variants") {
body.insert("variants".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("id") {
body.insert("id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at") {
body.insert("created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("feature_flag_key") {
body.insert("feature_flag_key".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/projects/{{project_id}}/web_experiments/{{id}}/ failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// list hog function templates
///
/// Method: GET /api/public_hog_function_templates/
#[actor(
PosthogListHogFunctionTemplatesActor,
inports::<100>(limit, offset, template_id, type_, types),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_list_hog_function_templates(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/api/public_hog_function_templates/".to_string();
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("limit") {
query_pairs.push(("limit", super::message_to_str(val)));
}
if let Some(val) = inputs.get("offset") {
query_pairs.push(("offset", super::message_to_str(val)));
}
if let Some(val) = inputs.get("template_id") {
query_pairs.push(("template_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("type_") {
query_pairs.push(("type", super::message_to_str(val)));
}
if let Some(val) = inputs.get("types") {
query_pairs.push(("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/public_hog_function_templates/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// update user home settings
///
/// Method: PATCH /api/user_home_settings/{uuid}/
#[actor(
PosthogUpdateUserHomeSettingsActor,
inports::<100>(uuid, homepage, tabs),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_update_user_home_settings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/user_home_settings/{uuid}/".to_string();
if let Some(val) = inputs.get("uuid") {
endpoint = endpoint.replace("{{uuid}}", &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("homepage") {
body.insert("homepage".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("tabs") {
body.insert("tabs".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/user_home_settings/{{uuid}}/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// read user home settings
///
/// Method: GET /api/user_home_settings/{uuid}/
#[actor(
PosthogReadUserHomeSettingsActor,
inports::<100>(uuid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_read_user_home_settings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/api/user_home_settings/{uuid}/".to_string();
if let Some(val) = inputs.get("uuid") {
endpoint = endpoint.replace("{{uuid}}", &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/user_home_settings/{{uuid}}/ failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// list core
///
/// Method: GET /api/users/
#[actor(
PosthogListCoreActor,
inports::<100>(email, is_staff, limit, offset),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn posthog_list_core(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/api/users/".to_string();
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("email") {
query_pairs.push(("email", super::message_to_str(val)));
}
if let Some(val) = inputs.get("is_staff") {
query_pairs.push(("is_staff", 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("offset") {
query_pairs.push(("offset", 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/users/ failed: {}", e).into()),
);
}
}
Ok(output)
}