#![allow(clippy::all, unused_imports, dead_code)]
use crate::{Actor, ActorBehavior, ClientBuilderExt, Message, Port};
use anyhow::{Error, Result};
use reflow_actor::{message::EncodableValue, ActorContext};
use reflow_actor_macro::actor;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::time::Duration;
const BASE_URL: &str = "https://api.intercom.io";
const ENV_KEY: &str = "INTERCOM_API_KEY";
fn apply_auth(
config: &reflow_actor::ActorConfig,
mut builder: reqwest::RequestBuilder,
) -> Result<reqwest::RequestBuilder> {
let credential = config
.get_config_or_env(ENV_KEY)
.ok_or_else(|| anyhow::anyhow!("Missing env var: {}", ENV_KEY))?;
builder = builder.header("Authorization", format!("Bearer {}", credential));
Ok(builder)
}
#[actor(
IntercomCreateContactActor,
inports::<100>(email, name, Intercom_Version, signed_up_at, avatar, last_seen_at, phone, role, unsubscribed_from_emails, owner_id, external_id, custom_attributes),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_contact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/contacts".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("email") {
body.insert("email".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("signed_up_at") {
body.insert("signed_up_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("avatar") {
body.insert("avatar".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("phone") {
body.insert("phone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("role") {
body.insert("role".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("unsubscribed_from_emails") {
body.insert("unsubscribed_from_emails".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("owner_id") {
body.insert("owner_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_id") {
body.insert("external_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("custom_attributes") {
body.insert("custom_attributes".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 /contacts failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomSendMessageActor,
inports::<100>(from, to, message_type, Intercom_Version, created_at, create_conversation_without_contact_reply, body, template, subject),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_send_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/messages".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("from") {
body.insert("from".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("to") {
body.insert("to".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("message_type") {
body.insert("message_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("create_conversation_without_contact_reply") {
body.insert(
"create_conversation_without_contact_reply".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("body") {
body.insert("body".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("subject") {
body.insert("subject".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 /messages failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListAdminsActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_admins(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/admins".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /admins failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListActivityLogsActor,
inports::<100>(Intercom_Version, created_at_after, created_at_before),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_activity_logs(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/admins/activity_logs".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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_after") {
query_pairs.push(("created_at_after", super::message_to_str(val)));
}
if let Some(val) = inputs.get("created_at_before") {
query_pairs.push(("created_at_before", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /admins/activity_logs failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadAdminsActor,
inports::<100>(Intercom_Version, admin_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_admins(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/admins/{admin_id}".to_string();
if let Some(val) = inputs.get("admin_id") {
endpoint = endpoint.replace("{{admin_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /admins/{{admin_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateAdminsActor,
inports::<100>(Intercom_Version, admin_id, away_mode_enabled, away_mode_reassign),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_admins(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/admins/{admin_id}/away".to_string();
if let Some(val) = inputs.get("admin_id") {
endpoint = endpoint.replace("{{admin_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("away_mode_enabled") {
body.insert("away_mode_enabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("away_mode_reassign") {
body.insert("away_mode_reassign".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 /admins/{{admin_id}}/away failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListArticlesActor,
inports::<100>(Intercom_Version, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_articles(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/articles".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /articles failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateArticleActor,
inports::<100>(Intercom_Version, author_id, parent_type, title, parent_id, body, description, translated_content, state),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_article(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/articles".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("author_id") {
body.insert("author_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("parent_type") {
body.insert("parent_type".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("parent_id") {
body.insert("parent_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("body") {
body.insert("body".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("translated_content") {
body.insert("translated_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".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 /articles failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomSearchArticlesActor,
inports::<100>(Intercom_Version, phrase, state, help_center_id, highlight),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_search_articles(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/articles/search".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("phrase") {
query_pairs.push(("phrase", super::message_to_str(val)));
}
if let Some(val) = inputs.get("state") {
query_pairs.push(("state", super::message_to_str(val)));
}
if let Some(val) = inputs.get("help_center_id") {
query_pairs.push(("help_center_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("highlight") {
query_pairs.push(("highlight", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /articles/search failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadArticlesActor,
inports::<100>(Intercom_Version, article_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_articles(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/articles/{article_id}".to_string();
if let Some(val) = inputs.get("article_id") {
endpoint = endpoint.replace("{{article_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /articles/{{article_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteArticleActor,
inports::<100>(Intercom_Version, article_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_article(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/articles/{article_id}".to_string();
if let Some(val) = inputs.get("article_id") {
endpoint = endpoint.replace("{{article_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /articles/{{article_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateArticleActor,
inports::<100>(Intercom_Version, article_id, body, translated_content, parent_type, state, description, parent_id, title, author_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_article(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/articles/{article_id}".to_string();
if let Some(val) = inputs.get("article_id") {
endpoint = endpoint.replace("{{article_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("body") {
body.insert("body".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("translated_content") {
body.insert("translated_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("parent_type") {
body.insert("parent_type".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("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("parent_id") {
body.insert("parent_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("author_id") {
body.insert("author_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 /articles/{{article_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateOrUpdateCompanyActor,
inports::<100>(Intercom_Version, company_id, custom_attributes, monthly_spend, plan, size, website, remote_created_at, industry, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_or_update_company(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/companies".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("company_id") {
body.insert("company_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("custom_attributes") {
body.insert("custom_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("monthly_spend") {
body.insert("monthly_spend".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("plan") {
body.insert("plan".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("size") {
body.insert("size".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("website") {
body.insert("website".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("remote_created_at") {
body.insert("remote_created_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("industry") {
body.insert("industry".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 /companies failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListCompaniesActor,
inports::<100>(Intercom_Version, name, company_id, tag_id, segment_id, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_companies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/companies".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("name") {
query_pairs.push(("name", super::message_to_str(val)));
}
if let Some(val) = inputs.get("company_id") {
query_pairs.push(("company_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("tag_id") {
query_pairs.push(("tag_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("segment_id") {
query_pairs.push(("segment_id", super::message_to_str(val)));
}
if let Some(val) = inputs.get("page") {
query_pairs.push(("page", super::message_to_str(val)));
}
if let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListAllCompaniesActor,
inports::<100>(Intercom_Version, page, per_page, order),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_all_companies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/companies/list".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("page") {
query_pairs.push(("page", super::message_to_str(val)));
}
if let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if let Some(val) = inputs.get("order") {
query_pairs.push(("order", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies/list failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadCompaniesActor,
inports::<100>(Intercom_Version, company_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_companies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/companies/{company_id}".to_string();
if let Some(val) = inputs.get("company_id") {
endpoint = endpoint.replace("{{company_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies/{{company_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateCompanyActor,
inports::<100>(Intercom_Version, company_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_company(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/companies/{company_id}".to_string();
if let Some(val) = inputs.get("company_id") {
endpoint = endpoint.replace("{{company_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies/{{company_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteCompanyActor,
inports::<100>(Intercom_Version, company_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_company(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/companies/{company_id}".to_string();
if let Some(val) = inputs.get("company_id") {
endpoint = endpoint.replace("{{company_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies/{{company_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListAttachedContactsActor,
inports::<100>(Intercom_Version, company_id, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_attached_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/companies/{company_id}/contacts".to_string();
if let Some(val) = inputs.get("company_id") {
endpoint = endpoint.replace("{{company_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies/{{company_id}}/contacts failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListAttachedSegmentsForCompaniesActor,
inports::<100>(Intercom_Version, company_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_attached_segments_for_companies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/companies/{company_id}/segments".to_string();
if let Some(val) = inputs.get("company_id") {
endpoint = endpoint.replace("{{company_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /companies/{{company_id}}/segments failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListContactsActor,
inports::<100>(Intercom_Version, page, per_page, starting_after),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/contacts".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if let Some(val) = inputs.get("starting_after") {
query_pairs.push(("starting_after", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomMergeContactsActor,
inports::<100>(Intercom_Version, into, from),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_merge_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/contacts/merge".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("into") {
body.insert("into".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("from") {
body.insert("from".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 /contacts/merge failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomSearchContactsActor,
inports::<100>(Intercom_Version, query, pagination),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_search_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/contacts/search".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("pagination") {
body.insert("pagination".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("POST /contacts/search failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteContactActor,
inports::<100>(Intercom_Version, contact_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_contact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateContactActor,
inports::<100>(Intercom_Version, contact_id, name, unsubscribed_from_emails, owner_id, avatar, custom_attributes, role, last_seen_at, phone, signed_up_at, external_id, email),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_contact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("unsubscribed_from_emails") {
body.insert("unsubscribed_from_emails".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("owner_id") {
body.insert("owner_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("avatar") {
body.insert("avatar".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("custom_attributes") {
body.insert("custom_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("role") {
body.insert("role".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("phone") {
body.insert("phone".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("signed_up_at") {
body.insert("signed_up_at".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("external_id") {
body.insert("external_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("email") {
body.insert("email".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 /contacts/{{contact_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadContactsActor,
inports::<100>(Intercom_Version, contact_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomArchiveContactsActor,
inports::<100>(Intercom_Version, contact_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_archive_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/archive".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/archive failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateCompaniesActor,
inports::<100>(Intercom_Version, contact_id, id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_companies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/companies".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
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!("POST /contacts/{{contact_id}}/companies failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListCompaniesForAcontactActor,
inports::<100>(contact_id, Intercom_Version, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_companies_for_acontact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/companies".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/companies failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteCompaniesActor,
inports::<100>(Intercom_Version, contact_id, company_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_companies(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/companies/{company_id}".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("company_id") {
endpoint = endpoint.replace("{{company_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/companies/{{company_id}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateNoteActor,
inports::<100>(Intercom_Version, contact_id, admin_id, body),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_note(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/notes".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("admin_id") {
body.insert("admin_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("body") {
body.insert("body".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("POST /contacts/{{contact_id}}/notes failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListNotesActor,
inports::<100>(contact_id, Intercom_Version, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_notes(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/notes".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/notes failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListSegmentsForAcontactActor,
inports::<100>(contact_id, Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_segments_for_acontact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/segments".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/segments failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateSubscriptionTypesActor,
inports::<100>(Intercom_Version, contact_id, id, consent_type),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_subscription_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/subscriptions".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("consent_type") {
body.insert("consent_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 /contacts/{{contact_id}}/subscriptions failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListSubscriptionsForAcontactActor,
inports::<100>(contact_id, Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_subscriptions_for_acontact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/subscriptions".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/subscriptions failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteSubscriptionTypesActor,
inports::<100>(Intercom_Version, contact_id, subscription_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_subscription_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/subscriptions/{subscription_id}".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("subscription_id") {
endpoint = endpoint.replace("{{subscription_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/subscriptions/{{subscription_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
IntercomListTagsForAcontactActor,
inports::<100>(Intercom_Version, contact_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_tags_for_acontact(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/tags".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/tags failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateTagsActor,
inports::<100>(Intercom_Version, contact_id, id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_tags(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/tags".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
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!("POST /contacts/{{contact_id}}/tags failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteTagsActor,
inports::<100>(Intercom_Version, contact_id, tag_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_tags(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/tags/{tag_id}".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("tag_id") {
endpoint = endpoint.replace("{{tag_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/tags/{{tag_id}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateContactsActor,
inports::<100>(Intercom_Version, contact_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_contacts(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/contacts/{contact_id}/unarchive".to_string();
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /contacts/{{contact_id}}/unarchive failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListConversationsActor,
inports::<100>(Intercom_Version, per_page, starting_after),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/conversations".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if let Some(val) = inputs.get("starting_after") {
query_pairs.push(("starting_after", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /conversations failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateConversationActor,
inports::<100>(Intercom_Version, created_at, from, body),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_conversation(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/conversations".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("from") {
body.insert("from".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("body") {
body.insert("body".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("POST /conversations failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateConversationsActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/conversations/redact".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /conversations/redact failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomSearchConversationsActor,
inports::<100>(Intercom_Version, query, pagination),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_search_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/conversations/search".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("pagination") {
body.insert("pagination".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("POST /conversations/search failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateConversationActor,
inports::<100>(Intercom_Version, conversation_id, display_as, read, custom_attributes),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_conversation(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/conversations/{conversation_id}".to_string();
if let Some(val) = inputs.get("conversation_id") {
endpoint = endpoint.replace("{{conversation_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("display_as") {
query_pairs.push(("display_as", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("read") {
body.insert("read".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("custom_attributes") {
body.insert("custom_attributes".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 /conversations/{{conversation_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomReadConversationsActor,
inports::<100>(Intercom_Version, conversation_id, display_as),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/conversations/{conversation_id}".to_string();
if let Some(val) = inputs.get("conversation_id") {
endpoint = endpoint.replace("{{conversation_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("display_as") {
query_pairs.push(("display_as", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /conversations/{{conversation_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteConversationsActor,
inports::<100>(Intercom_Version, conversation_id, contact_id, admin_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_conversations(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/conversations/{conversation_id}/customers/{contact_id}".to_string();
if let Some(val) = inputs.get("conversation_id") {
endpoint = endpoint.replace("{{conversation_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("contact_id") {
endpoint = endpoint.replace("{{contact_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /conversations/{{conversation_id}}/customers/{{contact_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
IntercomCreateDataAttributeActor,
inports::<100>(Intercom_Version, name, options, data_type, model, description, messenger_writable),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_data_attribute(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/data_attributes".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("options") {
body.insert("options".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_type") {
body.insert("data_type".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("description") {
body.insert("description".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("messenger_writable") {
body.insert("messenger_writable".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 /data_attributes failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListDataAttributesActor,
inports::<100>(Intercom_Version, model, include_archived),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_data_attributes(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/data_attributes".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("model") {
query_pairs.push(("model", super::message_to_str(val)));
}
if let Some(val) = inputs.get("include_archived") {
query_pairs.push(("include_archived", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /data_attributes failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateDataAttributeActor,
inports::<100>(Intercom_Version, data_attribute_id, archived, description, messenger_writable, options),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_data_attribute(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/data_attributes/{data_attribute_id}".to_string();
if let Some(val) = inputs.get("data_attribute_id") {
endpoint = endpoint.replace("{{data_attribute_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("archived") {
body.insert("archived".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("messenger_writable") {
body.insert("messenger_writable".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!("PUT /data_attributes/{{data_attribute_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomDownloadDataExportActor,
inports::<100>(Intercom_Version, job_identifier),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_download_data_export(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/download/content/data/{job_identifier}".to_string();
if let Some(val) = inputs.get("job_identifier") {
endpoint = endpoint.replace("{{job_identifier}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /download/content/data/{{job_identifier}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListDataEventsActor,
inports::<100>(Intercom_Version, filter, type_, summary, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_data_events(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/events".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("filter") {
query_pairs.push(("filter", 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("summary") {
query_pairs.push(("summary", super::message_to_str(val)));
}
if let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /events failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateDataEventActor,
inports::<100>(Intercom_Version, created_at, id, metadata, user_id, email, event_name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_data_event(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/events".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("metadata") {
body.insert("metadata".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("user_id") {
body.insert("user_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("email") {
body.insert("email".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("event_name") {
body.insert("event_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 /events failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateDataEventsActor,
inports::<100>(Intercom_Version, user_id, event_summaries),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_data_events(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/events/summaries".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("user_id") {
body.insert("user_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("event_summaries") {
body.insert("event_summaries".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 /events/summaries failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCancelDataExportActor,
inports::<100>(Intercom_Version, job_identifier),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_cancel_data_export(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/export/cancel/{job_identifier}".to_string();
if let Some(val) = inputs.get("job_identifier") {
endpoint = endpoint.replace("{{job_identifier}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /export/cancel/{{job_identifier}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateDataExportActor,
inports::<100>(Intercom_Version, created_at_before, created_at_after),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_data_export(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/export/content/data".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("created_at_before") {
body.insert("created_at_before".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("created_at_after") {
body.insert("created_at_after".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 /export/content/data failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadDataExportActor,
inports::<100>(Intercom_Version, job_identifier),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_data_export(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/export/content/data/{job_identifier}".to_string();
if let Some(val) = inputs.get("job_identifier") {
endpoint = endpoint.replace("{{job_identifier}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /export/content/data/{{job_identifier}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListAllCollectionsActor,
inports::<100>(Intercom_Version, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_all_collections(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/help_center/collections".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /help_center/collections failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateCollectionActor,
inports::<100>(Intercom_Version, parent_id, translated_content, description, name, help_center_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_collection(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/help_center/collections".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("parent_id") {
body.insert("parent_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("translated_content") {
body.insert("translated_content".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("help_center_id") {
body.insert("help_center_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 /help_center/collections failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadHelpCenterActor,
inports::<100>(Intercom_Version, collection_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_help_center(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/help_center/collections/{collection_id}".to_string();
if let Some(val) = inputs.get("collection_id") {
endpoint = endpoint.replace("{{collection_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /help_center/collections/{{collection_id}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteCollectionActor,
inports::<100>(Intercom_Version, collection_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_collection(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/help_center/collections/{collection_id}".to_string();
if let Some(val) = inputs.get("collection_id") {
endpoint = endpoint.replace("{{collection_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /help_center/collections/{{collection_id}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateCollectionActor,
inports::<100>(Intercom_Version, collection_id, description, translated_content, parent_id, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_collection(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/help_center/collections/{collection_id}".to_string();
if let Some(val) = inputs.get("collection_id") {
endpoint = endpoint.replace("{{collection_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("translated_content") {
body.insert("translated_content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("parent_id") {
body.insert("parent_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!(
"PUT /help_center/collections/{{collection_id}} failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListHelpCentersActor,
inports::<100>(Intercom_Version, page, per_page),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_help_centers(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/help_center/help_centers".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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 let Some(val) = inputs.get("per_page") {
query_pairs.push(("per_page", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /help_center/help_centers failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateMessageActor,
inports::<100>(Intercom_Version, created_at, from, to, create_conversation_without_contact_reply, body, message_type, template, subject),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/messages".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("from") {
body.insert("from".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("to") {
body.insert("to".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("create_conversation_without_contact_reply") {
body.insert(
"create_conversation_without_contact_reply".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("body") {
body.insert("body".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("message_type") {
body.insert("message_type".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("subject") {
body.insert("subject".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 /messages failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateNewsItemActor,
inports::<100>(Intercom_Version, state, body, deliver_silently, title, labels, newsfeed_assignments, reactions, sender_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_news_item(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/news/news_items".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("body") {
body.insert("body".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deliver_silently") {
body.insert("deliver_silently".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("labels") {
body.insert("labels".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("newsfeed_assignments") {
body.insert("newsfeed_assignments".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("reactions") {
body.insert("reactions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sender_id") {
body.insert("sender_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 /news/news_items failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListNewsItemsActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_news_items(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/news/news_items".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /news/news_items failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadNewsActor,
inports::<100>(Intercom_Version, news_item_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_news(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/news/news_items/{news_item_id}".to_string();
if let Some(val) = inputs.get("news_item_id") {
endpoint = endpoint.replace("{{news_item_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /news/news_items/{{news_item_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteNewsItemActor,
inports::<100>(Intercom_Version, news_item_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_news_item(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/news/news_items/{news_item_id}".to_string();
if let Some(val) = inputs.get("news_item_id") {
endpoint = endpoint.replace("{{news_item_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /news/news_items/{{news_item_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateNewsItemActor,
inports::<100>(Intercom_Version, news_item_id, labels, body, title, reactions, newsfeed_assignments, deliver_silently, sender_id, state),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_news_item(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/news/news_items/{news_item_id}".to_string();
if let Some(val) = inputs.get("news_item_id") {
endpoint = endpoint.replace("{{news_item_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("labels") {
body.insert("labels".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("body") {
body.insert("body".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("reactions") {
body.insert("reactions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("newsfeed_assignments") {
body.insert("newsfeed_assignments".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("deliver_silently") {
body.insert("deliver_silently".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("sender_id") {
body.insert("sender_id".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".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 /news/news_items/{{news_item_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomListNewsfeedsActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_newsfeeds(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/news/newsfeeds".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /news/newsfeeds failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListLiveNewsfeedItemsActor,
inports::<100>(Intercom_Version, newsfeed_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_live_newsfeed_items(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/news/newsfeeds/{newsfeed_id}/items".to_string();
if let Some(val) = inputs.get("newsfeed_id") {
endpoint = endpoint.replace("{{newsfeed_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /news/newsfeeds/{{newsfeed_id}}/items failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomReadNotesActor,
inports::<100>(Intercom_Version, note_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_notes(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/notes/{note_id}".to_string();
if let Some(val) = inputs.get("note_id") {
endpoint = endpoint.replace("{{note_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /notes/{{note_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreatePhoneSwitchActor,
inports::<100>(Intercom_Version, custom_attributes, phone),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_phone_switch(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/phone_call_redirects".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("custom_attributes") {
body.insert("custom_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("phone") {
body.insert("phone".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 /phone_call_redirects failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListSegmentsActor,
inports::<100>(Intercom_Version, include_count),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_segments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/segments".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("include_count") {
query_pairs.push(("include_count", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /segments failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadSegmentsActor,
inports::<100>(Intercom_Version, segment_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_segments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/segments/{segment_id}".to_string();
if let Some(val) = inputs.get("segment_id") {
endpoint = endpoint.replace("{{segment_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /segments/{{segment_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListSubscriptionTypesActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_subscription_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/subscription_types".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /subscription_types failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateTagActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_tag(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/tags".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /tags failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListTagsActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_tags(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/tags".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /tags failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomSearchTagActor,
inports::<100>(Intercom_Version, tag_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_search_tag(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/tags/{tag_id}".to_string();
if let Some(val) = inputs.get("tag_id") {
endpoint = endpoint.replace("{{tag_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /tags/{{tag_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomDeleteTagActor,
inports::<100>(Intercom_Version, tag_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_delete_tag(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/tags/{tag_id}".to_string();
if let Some(val) = inputs.get("tag_id") {
endpoint = endpoint.replace("{{tag_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /tags/{{tag_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListTeamsActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_teams(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/teams".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /teams failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadTeamsActor,
inports::<100>(Intercom_Version, team_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_teams(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/teams/{team_id}".to_string();
if let Some(val) = inputs.get("team_id") {
endpoint = endpoint.replace("{{team_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /teams/{{team_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListTicketTypesActor,
inports::<100>(Intercom_Version),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_ticket_types(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/ticket_types".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /ticket_types failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateTicketTypeActor,
inports::<100>(Intercom_Version, category, icon, is_internal, name, description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_ticket_type(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/ticket_types".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("category") {
body.insert("category".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("icon") {
body.insert("icon".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("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!("POST /ticket_types failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateTicketTypeActor,
inports::<100>(Intercom_Version, ticket_type_id, category, archived, icon, description, is_internal, name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_ticket_type(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/ticket_types/{ticket_type_id}".to_string();
if let Some(val) = inputs.get("ticket_type_id") {
endpoint = endpoint.replace("{{ticket_type_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("category") {
body.insert("category".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("icon") {
body.insert("icon".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_internal") {
body.insert("is_internal".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 /ticket_types/{{ticket_type_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomReadTicketTypeActor,
inports::<100>(Intercom_Version, ticket_type_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_ticket_type(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/ticket_types/{ticket_type_id}".to_string();
if let Some(val) = inputs.get("ticket_type_id") {
endpoint = endpoint.replace("{{ticket_type_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /ticket_types/{{ticket_type_id}} failed: {}", e).into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateTicketTypeAttributeActor,
inports::<100>(Intercom_Version, ticket_type_id, allow_multiple_values, name, visible_to_contacts, required_to_create_for_contacts, list_items, multiline, description, visible_on_create, required_to_create, data_type),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_ticket_type_attribute(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/ticket_types/{ticket_type_id}/attributes".to_string();
if let Some(val) = inputs.get("ticket_type_id") {
endpoint = endpoint.replace("{{ticket_type_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("allow_multiple_values") {
body.insert("allow_multiple_values".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("visible_to_contacts") {
body.insert("visible_to_contacts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("required_to_create_for_contacts") {
body.insert(
"required_to_create_for_contacts".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("list_items") {
body.insert("list_items".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("multiline") {
body.insert("multiline".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("visible_on_create") {
body.insert("visible_on_create".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("required_to_create") {
body.insert("required_to_create".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("data_type") {
body.insert("data_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 /ticket_types/{{ticket_type_id}}/attributes failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateTicketTypeAttributeActor,
inports::<100>(Intercom_Version, ticket_type_id, attribute_id, required_to_create_for_contacts, description, visible_on_create, name, list_items, allow_multiple_values, multiline, archived, visible_to_contacts, required_to_create),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_ticket_type_attribute(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/ticket_types/{ticket_type_id}/attributes/{attribute_id}".to_string();
if let Some(val) = inputs.get("ticket_type_id") {
endpoint = endpoint.replace("{{ticket_type_id}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("attribute_id") {
endpoint = endpoint.replace("{{attribute_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("required_to_create_for_contacts") {
body.insert(
"required_to_create_for_contacts".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("visible_on_create") {
body.insert("visible_on_create".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("list_items") {
body.insert("list_items".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("allow_multiple_values") {
body.insert("allow_multiple_values".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("multiline") {
body.insert("multiline".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("visible_to_contacts") {
body.insert("visible_to_contacts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("required_to_create") {
body.insert("required_to_create".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 /ticket_types/{{ticket_type_id}}/attributes/{{attribute_id}} failed: {}", e).into()));
}
}
Ok(output)
}
#[actor(
IntercomCreateTicketActor,
inports::<100>(Intercom_Version, contacts, ticket_type_id, created_at, ticket_attributes, company_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_ticket(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/tickets".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("contacts") {
body.insert("contacts".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ticket_type_id") {
body.insert("ticket_type_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("ticket_attributes") {
body.insert("ticket_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("company_id") {
body.insert("company_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 /tickets failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomSearchTicketsActor,
inports::<100>(Intercom_Version, pagination, query),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_search_tickets(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/tickets/search".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("pagination") {
body.insert("pagination".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("query") {
body.insert("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!("POST /tickets/search failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateTicketActor,
inports::<100>(Intercom_Version, ticket_id, open, assignment, snoozed_until, state, ticket_attributes, is_shared),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_ticket(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/tickets/{ticket_id}".to_string();
if let Some(val) = inputs.get("ticket_id") {
endpoint = endpoint.replace("{{ticket_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("open") {
body.insert("open".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("assignment") {
body.insert("assignment".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("ticket_attributes") {
body.insert("ticket_attributes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("is_shared") {
body.insert("is_shared".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 /tickets/{{ticket_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomReadTicketActor,
inports::<100>(Intercom_Version, ticket_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_read_ticket(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/tickets/{ticket_id}".to_string();
if let Some(val) = inputs.get("ticket_id") {
endpoint = endpoint.replace("{{ticket_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /tickets/{{ticket_id}} failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateTicketsActor,
inports::<100>(Intercom_Version, ticket_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_tickets(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/tickets/{ticket_id}/reply".to_string();
if let Some(val) = inputs.get("ticket_id") {
endpoint = endpoint.replace("{{ticket_id}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /tickets/{{ticket_id}}/reply failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomUpdateVisitorActor,
inports::<100>(Intercom_Version, name, custom_attributes, id, user_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_update_visitor(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/visitors".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.put(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("custom_attributes") {
body.insert("custom_attributes".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_id") {
body.insert("user_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 /visitors failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomListVisitorsActor,
inports::<100>(Intercom_Version, user_id),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_list_visitors(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/visitors".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(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("user_id") {
query_pairs.push(("user_id", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".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 /visitors failed: {}", e).into()),
);
}
}
Ok(output)
}
#[actor(
IntercomCreateVisitorsActor,
inports::<100>(Intercom_Version, type_, user, visitor),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn intercom_create_visitors(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/visitors/convert".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
if let Some(val) = inputs.get("Intercom_Version") {
builder = builder.header("Intercom-Version", super::message_to_str(val));
}
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("user") {
body.insert("user".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("visitor") {
body.insert("visitor".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 /visitors/convert failed: {}", e).into()),
);
}
}
Ok(output)
}