#![allow(clippy::all, unused_imports, dead_code)]
//! Auto-generated API actors for Twilio
//!
//! Service: Twilio (twilio)
//! Cloud communications platform for SMS, voice, and video
//!
//! Required env var: TWILIO_API_KEY (Basic auth credentials (user:pass))
//!
//! Generated by api-schema-gen codegen — do not edit manually.
use crate::{Actor, ActorBehavior, Message, Port};
use anyhow::{Error, Result};
use reflow_actor::{message::EncodableValue, ActorContext};
use reflow_actor_macro::actor;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::time::Duration;
const BASE_URL: &str = "https://api.twilio.com/2010-04-01";
const ENV_KEY: &str = "TWILIO_API_KEY";
/// Apply authentication to the request builder.
fn apply_auth(
config: &reflow_actor::ActorConfig,
mut builder: reqwest::RequestBuilder,
) -> Result<reqwest::RequestBuilder> {
let credential = config
.get_config_or_env(ENV_KEY)
.ok_or_else(|| anyhow::anyhow!("Missing env var: {}", ENV_KEY))?;
builder = builder.header("Authorization", format!("Basic {}", credential));
Ok(builder)
}
/// send message via Twilio API
///
/// Method: POST /Accounts/{AccountSid}/Messages.json
#[actor(
TwilioSendMessageActor,
inports::<100>(To, From, Body),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_send_message(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/Accounts/{AccountSid}/Messages.json".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("To") {
body.insert("To".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 /Accounts/{{AccountSid}}/Messages.json failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// create call via Twilio API
///
/// Method: POST /Accounts/{AccountSid}/Calls.json
#[actor(
TwilioCreateCallActor,
inports::<100>(To, From, Url),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_call(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/Accounts/{AccountSid}/Calls.json".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("To") {
body.insert("To".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("Url") {
body.insert("Url".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!("POST /Accounts/{{AccountSid}}/Calls.json failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Create a new Twilio Subaccount from the account making the request
///
/// Method: POST /2010-04-01/Accounts.json
#[actor(
TwilioCreateAccountActor,
inports::<100>(FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_account(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/2010-04-01/Accounts.json".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts.json failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Retrieves a collection of Accounts belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts.json
#[actor(
TwilioListAccountActor,
inports::<100>(FriendlyName, Status, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_account(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/2010-04-01/Accounts.json".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Status") {
query_pairs.push(("Status", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("GET /2010-04-01/Accounts.json failed: {}", e).into()),
);
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Addresses.json
#[actor(
TwilioCreateAddressActor,
inports::<100>(AccountSid, IsoCountry, PostalCode, Street, FriendlyName, EmergencyEnabled, CustomerName, City, AutoCorrectAddress, Region, StreetSecondary),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Addresses.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("IsoCountry") {
body.insert("IsoCountry".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PostalCode") {
body.insert("PostalCode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Street") {
body.insert("Street".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyEnabled") {
body.insert("EmergencyEnabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CustomerName") {
body.insert("CustomerName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("City") {
body.insert("City".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AutoCorrectAddress") {
body.insert("AutoCorrectAddress".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Region") {
body.insert("Region".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StreetSecondary") {
body.insert("StreetSecondary".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 /2010-04-01/Accounts/{{AccountSid}}/Addresses.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Addresses.json
#[actor(
TwilioListAddressActor,
inports::<100>(AccountSid, CustomerName, FriendlyName, EmergencyEnabled, IsoCountry, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_address(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Addresses.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("CustomerName") {
query_pairs.push(("CustomerName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EmergencyEnabled") {
query_pairs.push(("EmergencyEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IsoCountry") {
query_pairs.push(("IsoCountry", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Addresses.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Addresses/{AddressSid}/DependentPhoneNumbers.json
#[actor(
TwilioListDependentPhoneNumberActor,
inports::<100>(AccountSid, AddressSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_dependent_phone_number(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Addresses/{AddressSid}/DependentPhoneNumbers.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AddressSid") {
endpoint = endpoint.replace("{{AddressSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Addresses/{{AddressSid}}/DependentPhoneNumbers.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json
#[actor(
TwilioDeleteAddressActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Addresses/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json
#[actor(
TwilioReadApi20100401AddressActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Addresses/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json
#[actor(
TwilioUpdateAddressActor,
inports::<100>(AccountSid, Sid, AutoCorrectAddress, Street, EmergencyEnabled, City, StreetSecondary, Region, CustomerName, PostalCode, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("AutoCorrectAddress") {
body.insert("AutoCorrectAddress".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Street") {
body.insert("Street".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyEnabled") {
body.insert("EmergencyEnabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("City") {
body.insert("City".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StreetSecondary") {
body.insert("StreetSecondary".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Region") {
body.insert("Region".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CustomerName") {
body.insert("CustomerName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PostalCode") {
body.insert("PostalCode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/Addresses/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of applications representing an application within the requesting account
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Applications.json
#[actor(
TwilioListApplicationActor,
inports::<100>(AccountSid, FriendlyName, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_application(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Applications.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Applications.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create a new application within your account
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Applications.json
#[actor(
TwilioCreateApplicationActor,
inports::<100>(AccountSid, SmsMethod, MessageStatusCallback, PublicApplicationConnectEnabled, SmsFallbackMethod, SmsUrl, StatusCallbackMethod, VoiceUrl, StatusCallback, ApiVersion, SmsStatusCallback, VoiceFallbackMethod, VoiceMethod, VoiceFallbackUrl, VoiceCallerIdLookup, FriendlyName, SmsFallbackUrl),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_application(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Applications.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MessageStatusCallback") {
body.insert("MessageStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PublicApplicationConnectEnabled") {
body.insert(
"PublicApplicationConnectEnabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsStatusCallback") {
body.insert("SmsStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".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 /2010-04-01/Accounts/{{AccountSid}}/Applications.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Delete the application by the specified application sid
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json
#[actor(
TwilioDeleteApplicationActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_application(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Applications/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Updates the application's properties
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json
#[actor(
TwilioUpdateApplicationActor,
inports::<100>(AccountSid, Sid, SmsMethod, SmsStatusCallback, VoiceUrl, ApiVersion, FriendlyName, VoiceCallerIdLookup, VoiceFallbackMethod, VoiceFallbackUrl, StatusCallbackMethod, StatusCallback, SmsUrl, PublicApplicationConnectEnabled, VoiceMethod, MessageStatusCallback, SmsFallbackUrl, SmsFallbackMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_application(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsStatusCallback") {
body.insert("SmsStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PublicApplicationConnectEnabled") {
body.insert(
"PublicApplicationConnectEnabled".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MessageStatusCallback") {
body.insert("MessageStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".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 /2010-04-01/Accounts/{{AccountSid}}/Applications/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch the application specified by the provided sid
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json
#[actor(
TwilioReadApi20100401ApplicationActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_application(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Applications/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of authorized-connect-apps belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json
#[actor(
TwilioListAuthorizedConnectAppActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_authorized_connect_app(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AuthorizedConnectApps.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of an authorized-connect-app
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps/{ConnectAppSid}.json
#[actor(
TwilioReadAuthorizedConnectAppsActor,
inports::<100>(AccountSid, ConnectAppSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_authorized_connect_apps(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps/{ConnectAppSid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConnectAppSid") {
endpoint = endpoint.replace("{{ConnectAppSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AuthorizedConnectApps/{{ConnectAppSid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json
#[actor(
TwilioListAvailablePhoneNumberCountryActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_country(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json
#[actor(
TwilioReadAvailablePhoneNumbersActor,
inports::<100>(AccountSid, CountryCode),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_available_phone_numbers(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Local.json
#[actor(
TwilioListAvailablePhoneNumberLocalActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_local(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Local.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/Local.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json
#[actor(
TwilioListAvailablePhoneNumberMachineToMachineActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_machine_to_machine(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/MachineToMachine.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Mobile.json
#[actor(
TwilioListAvailablePhoneNumberMobileActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_mobile(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Mobile.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/Mobile.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/National.json
#[actor(
TwilioListAvailablePhoneNumberNationalActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_national(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/National.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/National.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json
#[actor(
TwilioListAvailablePhoneNumberSharedCostActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_shared_cost(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/SharedCost.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/TollFree.json
#[actor(
TwilioListAvailablePhoneNumberTollFreeActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_toll_free(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/TollFree.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/TollFree.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Voip.json
#[actor(
TwilioListAvailablePhoneNumberVoipActor,
inports::<100>(AccountSid, CountryCode, AreaCode, Contains, SmsEnabled, MmsEnabled, VoiceEnabled, ExcludeAllAddressRequired, ExcludeLocalAddressRequired, ExcludeForeignAddressRequired, Beta, NearNumber, NearLatLong, Distance, InPostalCode, InRegion, InRateCenter, InLata, InLocality, FaxEnabled, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_available_phone_number_voip(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Voip.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CountryCode") {
endpoint = endpoint.replace("{{CountryCode}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("AreaCode") {
query_pairs.push(("AreaCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Contains") {
query_pairs.push(("Contains", super::message_to_str(val)));
}
if let Some(val) = inputs.get("SmsEnabled") {
query_pairs.push(("SmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MmsEnabled") {
query_pairs.push(("MmsEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("VoiceEnabled") {
query_pairs.push(("VoiceEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeAllAddressRequired") {
query_pairs.push(("ExcludeAllAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeLocalAddressRequired") {
query_pairs.push(("ExcludeLocalAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ExcludeForeignAddressRequired") {
query_pairs.push(("ExcludeForeignAddressRequired", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearNumber") {
query_pairs.push(("NearNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("NearLatLong") {
query_pairs.push(("NearLatLong", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Distance") {
query_pairs.push(("Distance", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InPostalCode") {
query_pairs.push(("InPostalCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRegion") {
query_pairs.push(("InRegion", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InRateCenter") {
query_pairs.push(("InRateCenter", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLata") {
query_pairs.push(("InLata", super::message_to_str(val)));
}
if let Some(val) = inputs.get("InLocality") {
query_pairs.push(("InLocality", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FaxEnabled") {
query_pairs.push(("FaxEnabled", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/AvailablePhoneNumbers/{{CountryCode}}/Voip.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch the balance for an Account based on Account Sid. Balance changes may not be reflected immediately. Child accounts do not contain balance information
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Balance.json
#[actor(
TwilioReadApi20100401BalanceActor,
inports::<100>(AccountSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_balance(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Balance.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Balance.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieves a collection of calls made to and from your account
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls.json
#[actor(
TwilioListCallActor,
inports::<100>(AccountSid, To, From, ParentCallSid, Status, StartTime, StartTime_before, StartTime_after, EndTime, EndTime_before, EndTime_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_call(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("To") {
query_pairs.push(("To", super::message_to_str(val)));
}
if let Some(val) = inputs.get("From") {
query_pairs.push(("From", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ParentCallSid") {
query_pairs.push(("ParentCallSid", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Status") {
query_pairs.push(("Status", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartTime") {
query_pairs.push(("StartTime", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartTime_before") {
query_pairs.push(("StartTime<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartTime_after") {
query_pairs.push(("StartTime>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndTime") {
query_pairs.push(("EndTime", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndTime_before") {
query_pairs.push(("EndTime<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndTime_after") {
query_pairs.push(("EndTime>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Calls.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of all events for a call.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json
#[actor(
TwilioListCallEventActor,
inports::<100>(AccountSid, CallSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_call_event(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Events.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json
#[actor(
TwilioListCallNotificationActor,
inports::<100>(AccountSid, CallSid, Log, MessageDate, MessageDate_before, MessageDate_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_call_notification(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Log") {
query_pairs.push(("Log", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MessageDate") {
query_pairs.push(("MessageDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MessageDate_before") {
query_pairs.push(("MessageDate<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MessageDate_after") {
query_pairs.push(("MessageDate>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Notifications.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json
#[actor(
TwilioReadApi20100401CallNotificationActor,
inports::<100>(AccountSid, CallSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_call_notification(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Notifications/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// create an instance of payments. This will start a new payments session
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json
#[actor(
TwilioCreatePaymentsActor,
inports::<100>(AccountSid, CallSid, SecurityCode, PaymentConnector, Input, Parameter, BankAccountType, PostalCode, StatusCallback, TokenType, MinPostalCodeLength, ChargeAmount, Description, ValidCardTypes, Confirmation, Currency, Timeout, IdempotencyKey, RequireMatchingInputs, PaymentMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_payments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("SecurityCode") {
body.insert("SecurityCode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PaymentConnector") {
body.insert("PaymentConnector".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Input") {
body.insert("Input".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter") {
body.insert("Parameter".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("BankAccountType") {
body.insert("BankAccountType".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PostalCode") {
body.insert("PostalCode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TokenType") {
body.insert("TokenType".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MinPostalCodeLength") {
body.insert("MinPostalCodeLength".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ChargeAmount") {
body.insert("ChargeAmount".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("ValidCardTypes") {
body.insert("ValidCardTypes".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Confirmation") {
body.insert("Confirmation".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Currency") {
body.insert("Currency".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Timeout") {
body.insert("Timeout".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdempotencyKey") {
body.insert("IdempotencyKey".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RequireMatchingInputs") {
body.insert("RequireMatchingInputs".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PaymentMethod") {
body.insert("PaymentMethod".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Payments.json failed: {}", e).into()));
}
}
Ok(output)
}
/// update an instance of payments with different phases of payment flows.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json
#[actor(
TwilioUpdatePaymentsActor,
inports::<100>(AccountSid, CallSid, Sid, Status, IdempotencyKey, StatusCallback, Capture),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_payments(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdempotencyKey") {
body.insert("IdempotencyKey".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Capture") {
body.insert("Capture".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Payments/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a recording for the call
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json
#[actor(
TwilioCreateCallRecordingActor,
inports::<100>(AccountSid, CallSid, RecordingTrack, RecordingStatusCallback, RecordingStatusCallbackMethod, Trim, RecordingChannels, RecordingStatusCallbackEvent),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_call_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("RecordingTrack") {
body.insert("RecordingTrack".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingStatusCallback") {
body.insert("RecordingStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingStatusCallbackMethod") {
body.insert(
"RecordingStatusCallbackMethod".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("Trim") {
body.insert("Trim".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingChannels") {
body.insert("RecordingChannels".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingStatusCallbackEvent") {
body.insert(
"RecordingStatusCallbackEvent".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Recordings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of recordings belonging to the call used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json
#[actor(
TwilioListCallRecordingActor,
inports::<100>(AccountSid, CallSid, DateCreated, DateCreated_before, DateCreated_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_call_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("DateCreated") {
query_pairs.push(("DateCreated", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_before") {
query_pairs.push(("DateCreated<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_after") {
query_pairs.push(("DateCreated>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Recordings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Changes the status of the recording to paused, stopped, or in-progress. Note: Pass `Twilio.CURRENT` instead of recording sid to reference current active recording.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json
#[actor(
TwilioUpdateCallRecordingActor,
inports::<100>(AccountSid, CallSid, Sid, PauseBehavior, Status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_call_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("PauseBehavior") {
body.insert("PauseBehavior".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a recording from your account
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json
#[actor(
TwilioDeleteCallRecordingActor,
inports::<100>(AccountSid, CallSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_call_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a recording for a call
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json
#[actor(
TwilioReadApi20100401CallRecordingActor,
inports::<100>(AccountSid, CallSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_call_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a Siprec
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec.json
#[actor(
TwilioCreateSiprecActor,
inports::<100>(AccountSid, CallSid, Parameter48_Value, Parameter70_Name, Parameter92_Name, Parameter18_Value, Parameter14_Name, Parameter20_Name, Parameter5_Name, Parameter64_Value, Parameter49_Name, Parameter71_Value, Parameter81_Value, Parameter91_Name, Parameter23_Value, Parameter63_Name, Parameter30_Name, Parameter10_Value, ConnectorName, Parameter1_Name, Parameter90_Value, Parameter96_Value, Parameter97_Value, Parameter73_Name, Parameter39_Name, Parameter95_Value, Parameter98_Name, Parameter33_Value, Parameter22_Value, Parameter39_Value, Parameter99_Value, Parameter43_Value, Parameter2_Value, Parameter54_Name, Parameter64_Name, Parameter53_Name, Parameter11_Value, Parameter16_Name, Parameter34_Name, Parameter38_Value, Parameter4_Value, Parameter38_Name, Parameter52_Value, Parameter27_Name, Parameter15_Name, Parameter51_Name, Parameter13_Name, StatusCallback, Parameter44_Value, Parameter66_Name, Parameter50_Value, Parameter58_Name, Parameter62_Value, Parameter49_Value, Parameter63_Value, Parameter46_Value, Parameter9_Value, Parameter88_Value, Parameter57_Name, Parameter87_Name, Parameter93_Name, Parameter35_Name, Parameter72_Name, Track, Parameter2_Name, Parameter21_Name, Parameter26_Name, Parameter79_Value, Parameter40_Name, Parameter41_Name, Parameter83_Name, Parameter81_Name, Parameter58_Value, Parameter86_Value, Parameter17_Name, Parameter98_Value, Parameter87_Value, Parameter1_Value, Parameter24_Name, Parameter43_Name, Parameter89_Name, Parameter80_Name, Parameter37_Name, Parameter19_Value, Parameter18_Name, Parameter96_Name, Parameter53_Value, Parameter54_Value, Parameter32_Value, Parameter31_Name, Parameter65_Value, Parameter48_Name, Parameter56_Name, Parameter22_Name, Parameter3_Name, Parameter79_Name, Parameter12_Name, Parameter20_Value, Parameter59_Name, Parameter57_Value, Parameter7_Value, Parameter37_Value, Parameter77_Value, StatusCallbackMethod, Name, Parameter25_Value, Parameter61_Name, Parameter70_Value, Parameter82_Name, Parameter45_Value, Parameter28_Value, Parameter44_Name, Parameter52_Name, Parameter16_Value, Parameter62_Name, Parameter67_Name, Parameter91_Value, Parameter97_Name, Parameter99_Name, Parameter94_Name, Parameter83_Value, Parameter25_Name, Parameter19_Name, Parameter75_Name, Parameter80_Value, Parameter88_Name, Parameter14_Value, Parameter93_Value, Parameter67_Value, Parameter95_Name, Parameter29_Name, Parameter35_Value, Parameter50_Name, Parameter15_Value, Parameter33_Name, Parameter12_Value, Parameter36_Name, Parameter69_Name, Parameter71_Name, Parameter13_Value, Parameter29_Value, Parameter73_Value, Parameter6_Name, Parameter59_Value, Parameter7_Name, Parameter75_Value, Parameter24_Value, Parameter78_Value, Parameter8_Name, Parameter34_Value, Parameter4_Name, Parameter55_Name, Parameter66_Value, Parameter41_Value, Parameter6_Value, Parameter60_Name, Parameter47_Value, Parameter68_Name, Parameter77_Name, Parameter46_Name, Parameter10_Name, Parameter30_Value, Parameter45_Name, Parameter5_Value, Parameter11_Name, Parameter32_Name, Parameter40_Value, Parameter47_Name, Parameter56_Value, Parameter84_Value, Parameter27_Value, Parameter85_Value, Parameter76_Value, Parameter92_Value, Parameter69_Value, Parameter74_Name, Parameter55_Value, Parameter78_Name, Parameter65_Name, Parameter21_Value, Parameter31_Value, Parameter60_Value, Parameter86_Name, Parameter3_Value, Parameter90_Name, Parameter89_Value, Parameter72_Value, Parameter17_Value, Parameter28_Name, Parameter74_Value, Parameter26_Value, Parameter68_Value, Parameter9_Name, Parameter36_Value, Parameter85_Name, Parameter51_Value, Parameter61_Value, Parameter42_Name, Parameter76_Name, Parameter94_Value, Parameter84_Name, Parameter23_Name, Parameter8_Value, Parameter82_Value, Parameter42_Value),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_siprec(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Parameter48_Value") {
body.insert("Parameter48.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter70_Name") {
body.insert("Parameter70.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter92_Name") {
body.insert("Parameter92.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter18_Value") {
body.insert("Parameter18.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter14_Name") {
body.insert("Parameter14.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter20_Name") {
body.insert("Parameter20.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter5_Name") {
body.insert("Parameter5.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter64_Value") {
body.insert("Parameter64.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter49_Name") {
body.insert("Parameter49.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter71_Value") {
body.insert("Parameter71.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter81_Value") {
body.insert("Parameter81.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter91_Name") {
body.insert("Parameter91.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter23_Value") {
body.insert("Parameter23.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter63_Name") {
body.insert("Parameter63.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter30_Name") {
body.insert("Parameter30.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter10_Value") {
body.insert("Parameter10.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ConnectorName") {
body.insert("ConnectorName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter1_Name") {
body.insert("Parameter1.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter90_Value") {
body.insert("Parameter90.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter96_Value") {
body.insert("Parameter96.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter97_Value") {
body.insert("Parameter97.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter73_Name") {
body.insert("Parameter73.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter39_Name") {
body.insert("Parameter39.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter95_Value") {
body.insert("Parameter95.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter98_Name") {
body.insert("Parameter98.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter33_Value") {
body.insert("Parameter33.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter22_Value") {
body.insert("Parameter22.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter39_Value") {
body.insert("Parameter39.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter99_Value") {
body.insert("Parameter99.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter43_Value") {
body.insert("Parameter43.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter2_Value") {
body.insert("Parameter2.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter54_Name") {
body.insert("Parameter54.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter64_Name") {
body.insert("Parameter64.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter53_Name") {
body.insert("Parameter53.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter11_Value") {
body.insert("Parameter11.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter16_Name") {
body.insert("Parameter16.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter34_Name") {
body.insert("Parameter34.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter38_Value") {
body.insert("Parameter38.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter4_Value") {
body.insert("Parameter4.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter38_Name") {
body.insert("Parameter38.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter52_Value") {
body.insert("Parameter52.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter27_Name") {
body.insert("Parameter27.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter15_Name") {
body.insert("Parameter15.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter51_Name") {
body.insert("Parameter51.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter13_Name") {
body.insert("Parameter13.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter44_Value") {
body.insert("Parameter44.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter66_Name") {
body.insert("Parameter66.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter50_Value") {
body.insert("Parameter50.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter58_Name") {
body.insert("Parameter58.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter62_Value") {
body.insert("Parameter62.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter49_Value") {
body.insert("Parameter49.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter63_Value") {
body.insert("Parameter63.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter46_Value") {
body.insert("Parameter46.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter9_Value") {
body.insert("Parameter9.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter88_Value") {
body.insert("Parameter88.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter57_Name") {
body.insert("Parameter57.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter87_Name") {
body.insert("Parameter87.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter93_Name") {
body.insert("Parameter93.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter35_Name") {
body.insert("Parameter35.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter72_Name") {
body.insert("Parameter72.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Track") {
body.insert("Track".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter2_Name") {
body.insert("Parameter2.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter21_Name") {
body.insert("Parameter21.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter26_Name") {
body.insert("Parameter26.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter79_Value") {
body.insert("Parameter79.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter40_Name") {
body.insert("Parameter40.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter41_Name") {
body.insert("Parameter41.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter83_Name") {
body.insert("Parameter83.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter81_Name") {
body.insert("Parameter81.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter58_Value") {
body.insert("Parameter58.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter86_Value") {
body.insert("Parameter86.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter17_Name") {
body.insert("Parameter17.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter98_Value") {
body.insert("Parameter98.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter87_Value") {
body.insert("Parameter87.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter1_Value") {
body.insert("Parameter1.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter24_Name") {
body.insert("Parameter24.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter43_Name") {
body.insert("Parameter43.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter89_Name") {
body.insert("Parameter89.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter80_Name") {
body.insert("Parameter80.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter37_Name") {
body.insert("Parameter37.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter19_Value") {
body.insert("Parameter19.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter18_Name") {
body.insert("Parameter18.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter96_Name") {
body.insert("Parameter96.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter53_Value") {
body.insert("Parameter53.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter54_Value") {
body.insert("Parameter54.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter32_Value") {
body.insert("Parameter32.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter31_Name") {
body.insert("Parameter31.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter65_Value") {
body.insert("Parameter65.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter48_Name") {
body.insert("Parameter48.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter56_Name") {
body.insert("Parameter56.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter22_Name") {
body.insert("Parameter22.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter3_Name") {
body.insert("Parameter3.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter79_Name") {
body.insert("Parameter79.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter12_Name") {
body.insert("Parameter12.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter20_Value") {
body.insert("Parameter20.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter59_Name") {
body.insert("Parameter59.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter57_Value") {
body.insert("Parameter57.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter7_Value") {
body.insert("Parameter7.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter37_Value") {
body.insert("Parameter37.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter77_Value") {
body.insert("Parameter77.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".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("Parameter25_Value") {
body.insert("Parameter25.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter61_Name") {
body.insert("Parameter61.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter70_Value") {
body.insert("Parameter70.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter82_Name") {
body.insert("Parameter82.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter45_Value") {
body.insert("Parameter45.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter28_Value") {
body.insert("Parameter28.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter44_Name") {
body.insert("Parameter44.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter52_Name") {
body.insert("Parameter52.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter16_Value") {
body.insert("Parameter16.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter62_Name") {
body.insert("Parameter62.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter67_Name") {
body.insert("Parameter67.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter91_Value") {
body.insert("Parameter91.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter97_Name") {
body.insert("Parameter97.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter99_Name") {
body.insert("Parameter99.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter94_Name") {
body.insert("Parameter94.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter83_Value") {
body.insert("Parameter83.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter25_Name") {
body.insert("Parameter25.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter19_Name") {
body.insert("Parameter19.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter75_Name") {
body.insert("Parameter75.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter80_Value") {
body.insert("Parameter80.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter88_Name") {
body.insert("Parameter88.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter14_Value") {
body.insert("Parameter14.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter93_Value") {
body.insert("Parameter93.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter67_Value") {
body.insert("Parameter67.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter95_Name") {
body.insert("Parameter95.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter29_Name") {
body.insert("Parameter29.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter35_Value") {
body.insert("Parameter35.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter50_Name") {
body.insert("Parameter50.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter15_Value") {
body.insert("Parameter15.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter33_Name") {
body.insert("Parameter33.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter12_Value") {
body.insert("Parameter12.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter36_Name") {
body.insert("Parameter36.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter69_Name") {
body.insert("Parameter69.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter71_Name") {
body.insert("Parameter71.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter13_Value") {
body.insert("Parameter13.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter29_Value") {
body.insert("Parameter29.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter73_Value") {
body.insert("Parameter73.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter6_Name") {
body.insert("Parameter6.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter59_Value") {
body.insert("Parameter59.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter7_Name") {
body.insert("Parameter7.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter75_Value") {
body.insert("Parameter75.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter24_Value") {
body.insert("Parameter24.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter78_Value") {
body.insert("Parameter78.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter8_Name") {
body.insert("Parameter8.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter34_Value") {
body.insert("Parameter34.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter4_Name") {
body.insert("Parameter4.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter55_Name") {
body.insert("Parameter55.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter66_Value") {
body.insert("Parameter66.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter41_Value") {
body.insert("Parameter41.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter6_Value") {
body.insert("Parameter6.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter60_Name") {
body.insert("Parameter60.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter47_Value") {
body.insert("Parameter47.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter68_Name") {
body.insert("Parameter68.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter77_Name") {
body.insert("Parameter77.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter46_Name") {
body.insert("Parameter46.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter10_Name") {
body.insert("Parameter10.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter30_Value") {
body.insert("Parameter30.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter45_Name") {
body.insert("Parameter45.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter5_Value") {
body.insert("Parameter5.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter11_Name") {
body.insert("Parameter11.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter32_Name") {
body.insert("Parameter32.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter40_Value") {
body.insert("Parameter40.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter47_Name") {
body.insert("Parameter47.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter56_Value") {
body.insert("Parameter56.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter84_Value") {
body.insert("Parameter84.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter27_Value") {
body.insert("Parameter27.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter85_Value") {
body.insert("Parameter85.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter76_Value") {
body.insert("Parameter76.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter92_Value") {
body.insert("Parameter92.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter69_Value") {
body.insert("Parameter69.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter74_Name") {
body.insert("Parameter74.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter55_Value") {
body.insert("Parameter55.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter78_Name") {
body.insert("Parameter78.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter65_Name") {
body.insert("Parameter65.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter21_Value") {
body.insert("Parameter21.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter31_Value") {
body.insert("Parameter31.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter60_Value") {
body.insert("Parameter60.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter86_Name") {
body.insert("Parameter86.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter3_Value") {
body.insert("Parameter3.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter90_Name") {
body.insert("Parameter90.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter89_Value") {
body.insert("Parameter89.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter72_Value") {
body.insert("Parameter72.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter17_Value") {
body.insert("Parameter17.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter28_Name") {
body.insert("Parameter28.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter74_Value") {
body.insert("Parameter74.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter26_Value") {
body.insert("Parameter26.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter68_Value") {
body.insert("Parameter68.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter9_Name") {
body.insert("Parameter9.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter36_Value") {
body.insert("Parameter36.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter85_Name") {
body.insert("Parameter85.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter51_Value") {
body.insert("Parameter51.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter61_Value") {
body.insert("Parameter61.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter42_Name") {
body.insert("Parameter42.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter76_Name") {
body.insert("Parameter76.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter94_Value") {
body.insert("Parameter94.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter84_Name") {
body.insert("Parameter84.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter23_Name") {
body.insert("Parameter23.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter8_Value") {
body.insert("Parameter8.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter82_Value") {
body.insert("Parameter82.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter42_Value") {
body.insert("Parameter42.Value".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Siprec.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Stop a Siprec using either the SID of the Siprec resource or the `name` used when creating the resource
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec/{Sid}.json
#[actor(
TwilioUpdateSiprecActor,
inports::<100>(AccountSid, CallSid, Sid, Status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_siprec(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if !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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Siprec/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a Stream
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json
#[actor(
TwilioCreateStreamActor,
inports::<100>(AccountSid, CallSid, Parameter88_Value, Parameter16_Name, Parameter58_Name, Parameter21_Name, Parameter96_Value, Parameter65_Name, Parameter70_Value, Parameter20_Name, Parameter21_Value, Parameter28_Value, Parameter66_Value, Parameter38_Name, Parameter4_Value, Parameter54_Name, Parameter33_Value, Parameter6_Name, Parameter63_Name, Parameter79_Value, Parameter80_Value, Parameter6_Value, Parameter26_Name, Parameter30_Name, Parameter41_Name, Parameter52_Value, Parameter46_Name, Parameter68_Value, Parameter35_Name, Parameter1_Name, Parameter82_Value, Parameter9_Name, Parameter24_Value, Parameter56_Name, Parameter86_Name, Name, Parameter16_Value, Parameter46_Value, Parameter53_Name, Parameter43_Name, Parameter30_Value, Parameter33_Name, Parameter10_Name, Parameter18_Name, Parameter11_Value, Parameter10_Value, Parameter48_Value, Parameter74_Name, Parameter84_Name, Parameter28_Name, Parameter88_Name, Parameter89_Value, Parameter36_Name, Parameter99_Value, Parameter90_Name, Parameter13_Value, Parameter59_Value, Parameter60_Name, Parameter67_Value, StatusCallbackMethod, Parameter71_Value, Parameter17_Value, Parameter26_Value, Parameter77_Name, Parameter22_Name, Parameter95_Value, Parameter4_Name, Parameter62_Name, Parameter37_Name, Parameter20_Value, Parameter81_Name, Parameter8_Value, Parameter11_Name, Parameter48_Name, Parameter19_Name, Parameter3_Name, Parameter35_Value, Parameter5_Value, Parameter50_Name, Parameter76_Name, Parameter89_Name, Parameter65_Value, Parameter97_Value, Parameter78_Value, Parameter25_Value, Parameter2_Name, Parameter49_Value, Parameter74_Value, Parameter72_Value, Parameter83_Value, Parameter27_Value, Parameter60_Value, Parameter69_Value, Parameter51_Value, Parameter58_Value, Parameter94_Value, Parameter2_Value, Parameter54_Value, Parameter64_Value, Parameter34_Value, Parameter39_Value, Parameter50_Value, Parameter12_Name, Parameter91_Name, Parameter92_Value, Parameter23_Name, Parameter22_Value, Parameter84_Value, Parameter42_Name, Parameter59_Name, Parameter93_Name, Parameter98_Name, Parameter7_Name, Parameter87_Value, Url, Parameter86_Value, Parameter76_Value, Parameter47_Value, Parameter90_Value, Parameter93_Value, Parameter98_Value, Parameter32_Name, Parameter85_Name, Parameter97_Name, Parameter40_Value, Parameter24_Name, Parameter18_Value, Parameter8_Name, Parameter5_Name, Parameter38_Value, Parameter14_Value, Parameter47_Name, Parameter95_Name, Track, Parameter77_Value, Parameter44_Value, Parameter99_Name, Parameter23_Value, Parameter29_Value, Parameter87_Name, Parameter29_Name, Parameter17_Name, Parameter62_Value, Parameter70_Name, Parameter36_Value, Parameter72_Name, Parameter40_Name, Parameter55_Name, Parameter57_Value, Parameter7_Value, Parameter15_Value, Parameter42_Value, Parameter45_Value, Parameter53_Value, Parameter57_Name, Parameter71_Name, Parameter73_Name, Parameter67_Name, Parameter13_Name, Parameter34_Name, Parameter55_Value, Parameter63_Value, Parameter1_Value, Parameter19_Value, Parameter3_Value, Parameter51_Name, Parameter79_Name, Parameter85_Value, Parameter68_Name, Parameter56_Value, Parameter37_Value, Parameter12_Value, Parameter31_Value, Parameter75_Name, Parameter83_Name, Parameter73_Value, Parameter61_Name, Parameter82_Name, Parameter14_Name, Parameter91_Value, Parameter9_Value, Parameter27_Name, Parameter96_Name, StatusCallback, Parameter61_Value, Parameter92_Name, Parameter43_Value, Parameter32_Value, Parameter31_Name, Parameter41_Value, Parameter45_Name, Parameter94_Name, Parameter80_Name, Parameter52_Name, Parameter75_Value, Parameter49_Name, Parameter69_Name, Parameter81_Value, Parameter25_Name, Parameter39_Name, Parameter44_Name, Parameter66_Name, Parameter15_Name, Parameter64_Name, Parameter78_Name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_stream(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Parameter88_Value") {
body.insert("Parameter88.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter16_Name") {
body.insert("Parameter16.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter58_Name") {
body.insert("Parameter58.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter21_Name") {
body.insert("Parameter21.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter96_Value") {
body.insert("Parameter96.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter65_Name") {
body.insert("Parameter65.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter70_Value") {
body.insert("Parameter70.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter20_Name") {
body.insert("Parameter20.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter21_Value") {
body.insert("Parameter21.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter28_Value") {
body.insert("Parameter28.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter66_Value") {
body.insert("Parameter66.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter38_Name") {
body.insert("Parameter38.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter4_Value") {
body.insert("Parameter4.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter54_Name") {
body.insert("Parameter54.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter33_Value") {
body.insert("Parameter33.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter6_Name") {
body.insert("Parameter6.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter63_Name") {
body.insert("Parameter63.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter79_Value") {
body.insert("Parameter79.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter80_Value") {
body.insert("Parameter80.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter6_Value") {
body.insert("Parameter6.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter26_Name") {
body.insert("Parameter26.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter30_Name") {
body.insert("Parameter30.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter41_Name") {
body.insert("Parameter41.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter52_Value") {
body.insert("Parameter52.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter46_Name") {
body.insert("Parameter46.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter68_Value") {
body.insert("Parameter68.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter35_Name") {
body.insert("Parameter35.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter1_Name") {
body.insert("Parameter1.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter82_Value") {
body.insert("Parameter82.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter9_Name") {
body.insert("Parameter9.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter24_Value") {
body.insert("Parameter24.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter56_Name") {
body.insert("Parameter56.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter86_Name") {
body.insert("Parameter86.Name".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("Parameter16_Value") {
body.insert("Parameter16.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter46_Value") {
body.insert("Parameter46.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter53_Name") {
body.insert("Parameter53.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter43_Name") {
body.insert("Parameter43.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter30_Value") {
body.insert("Parameter30.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter33_Name") {
body.insert("Parameter33.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter10_Name") {
body.insert("Parameter10.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter18_Name") {
body.insert("Parameter18.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter11_Value") {
body.insert("Parameter11.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter10_Value") {
body.insert("Parameter10.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter48_Value") {
body.insert("Parameter48.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter74_Name") {
body.insert("Parameter74.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter84_Name") {
body.insert("Parameter84.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter28_Name") {
body.insert("Parameter28.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter88_Name") {
body.insert("Parameter88.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter89_Value") {
body.insert("Parameter89.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter36_Name") {
body.insert("Parameter36.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter99_Value") {
body.insert("Parameter99.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter90_Name") {
body.insert("Parameter90.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter13_Value") {
body.insert("Parameter13.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter59_Value") {
body.insert("Parameter59.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter60_Name") {
body.insert("Parameter60.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter67_Value") {
body.insert("Parameter67.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter71_Value") {
body.insert("Parameter71.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter17_Value") {
body.insert("Parameter17.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter26_Value") {
body.insert("Parameter26.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter77_Name") {
body.insert("Parameter77.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter22_Name") {
body.insert("Parameter22.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter95_Value") {
body.insert("Parameter95.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter4_Name") {
body.insert("Parameter4.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter62_Name") {
body.insert("Parameter62.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter37_Name") {
body.insert("Parameter37.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter20_Value") {
body.insert("Parameter20.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter81_Name") {
body.insert("Parameter81.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter8_Value") {
body.insert("Parameter8.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter11_Name") {
body.insert("Parameter11.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter48_Name") {
body.insert("Parameter48.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter19_Name") {
body.insert("Parameter19.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter3_Name") {
body.insert("Parameter3.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter35_Value") {
body.insert("Parameter35.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter5_Value") {
body.insert("Parameter5.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter50_Name") {
body.insert("Parameter50.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter76_Name") {
body.insert("Parameter76.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter89_Name") {
body.insert("Parameter89.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter65_Value") {
body.insert("Parameter65.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter97_Value") {
body.insert("Parameter97.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter78_Value") {
body.insert("Parameter78.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter25_Value") {
body.insert("Parameter25.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter2_Name") {
body.insert("Parameter2.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter49_Value") {
body.insert("Parameter49.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter74_Value") {
body.insert("Parameter74.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter72_Value") {
body.insert("Parameter72.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter83_Value") {
body.insert("Parameter83.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter27_Value") {
body.insert("Parameter27.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter60_Value") {
body.insert("Parameter60.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter69_Value") {
body.insert("Parameter69.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter51_Value") {
body.insert("Parameter51.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter58_Value") {
body.insert("Parameter58.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter94_Value") {
body.insert("Parameter94.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter2_Value") {
body.insert("Parameter2.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter54_Value") {
body.insert("Parameter54.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter64_Value") {
body.insert("Parameter64.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter34_Value") {
body.insert("Parameter34.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter39_Value") {
body.insert("Parameter39.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter50_Value") {
body.insert("Parameter50.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter12_Name") {
body.insert("Parameter12.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter91_Name") {
body.insert("Parameter91.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter92_Value") {
body.insert("Parameter92.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter23_Name") {
body.insert("Parameter23.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter22_Value") {
body.insert("Parameter22.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter84_Value") {
body.insert("Parameter84.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter42_Name") {
body.insert("Parameter42.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter59_Name") {
body.insert("Parameter59.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter93_Name") {
body.insert("Parameter93.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter98_Name") {
body.insert("Parameter98.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter7_Name") {
body.insert("Parameter7.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter87_Value") {
body.insert("Parameter87.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Url") {
body.insert("Url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter86_Value") {
body.insert("Parameter86.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter76_Value") {
body.insert("Parameter76.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter47_Value") {
body.insert("Parameter47.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter90_Value") {
body.insert("Parameter90.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter93_Value") {
body.insert("Parameter93.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter98_Value") {
body.insert("Parameter98.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter32_Name") {
body.insert("Parameter32.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter85_Name") {
body.insert("Parameter85.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter97_Name") {
body.insert("Parameter97.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter40_Value") {
body.insert("Parameter40.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter24_Name") {
body.insert("Parameter24.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter18_Value") {
body.insert("Parameter18.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter8_Name") {
body.insert("Parameter8.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter5_Name") {
body.insert("Parameter5.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter38_Value") {
body.insert("Parameter38.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter14_Value") {
body.insert("Parameter14.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter47_Name") {
body.insert("Parameter47.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter95_Name") {
body.insert("Parameter95.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Track") {
body.insert("Track".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter77_Value") {
body.insert("Parameter77.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter44_Value") {
body.insert("Parameter44.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter99_Name") {
body.insert("Parameter99.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter23_Value") {
body.insert("Parameter23.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter29_Value") {
body.insert("Parameter29.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter87_Name") {
body.insert("Parameter87.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter29_Name") {
body.insert("Parameter29.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter17_Name") {
body.insert("Parameter17.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter62_Value") {
body.insert("Parameter62.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter70_Name") {
body.insert("Parameter70.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter36_Value") {
body.insert("Parameter36.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter72_Name") {
body.insert("Parameter72.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter40_Name") {
body.insert("Parameter40.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter55_Name") {
body.insert("Parameter55.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter57_Value") {
body.insert("Parameter57.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter7_Value") {
body.insert("Parameter7.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter15_Value") {
body.insert("Parameter15.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter42_Value") {
body.insert("Parameter42.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter45_Value") {
body.insert("Parameter45.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter53_Value") {
body.insert("Parameter53.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter57_Name") {
body.insert("Parameter57.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter71_Name") {
body.insert("Parameter71.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter73_Name") {
body.insert("Parameter73.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter67_Name") {
body.insert("Parameter67.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter13_Name") {
body.insert("Parameter13.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter34_Name") {
body.insert("Parameter34.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter55_Value") {
body.insert("Parameter55.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter63_Value") {
body.insert("Parameter63.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter1_Value") {
body.insert("Parameter1.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter19_Value") {
body.insert("Parameter19.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter3_Value") {
body.insert("Parameter3.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter51_Name") {
body.insert("Parameter51.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter79_Name") {
body.insert("Parameter79.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter85_Value") {
body.insert("Parameter85.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter68_Name") {
body.insert("Parameter68.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter56_Value") {
body.insert("Parameter56.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter37_Value") {
body.insert("Parameter37.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter12_Value") {
body.insert("Parameter12.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter31_Value") {
body.insert("Parameter31.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter75_Name") {
body.insert("Parameter75.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter83_Name") {
body.insert("Parameter83.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter73_Value") {
body.insert("Parameter73.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter61_Name") {
body.insert("Parameter61.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter82_Name") {
body.insert("Parameter82.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter14_Name") {
body.insert("Parameter14.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter91_Value") {
body.insert("Parameter91.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter9_Value") {
body.insert("Parameter9.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter27_Name") {
body.insert("Parameter27.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter96_Name") {
body.insert("Parameter96.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter61_Value") {
body.insert("Parameter61.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter92_Name") {
body.insert("Parameter92.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter43_Value") {
body.insert("Parameter43.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter32_Value") {
body.insert("Parameter32.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter31_Name") {
body.insert("Parameter31.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter41_Value") {
body.insert("Parameter41.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter45_Name") {
body.insert("Parameter45.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter94_Name") {
body.insert("Parameter94.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter80_Name") {
body.insert("Parameter80.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter52_Name") {
body.insert("Parameter52.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter75_Value") {
body.insert("Parameter75.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter49_Name") {
body.insert("Parameter49.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter69_Name") {
body.insert("Parameter69.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter81_Value") {
body.insert("Parameter81.Value".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter25_Name") {
body.insert("Parameter25.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter39_Name") {
body.insert("Parameter39.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter44_Name") {
body.insert("Parameter44.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter66_Name") {
body.insert("Parameter66.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter15_Name") {
body.insert("Parameter15.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter64_Name") {
body.insert("Parameter64.Name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Parameter78_Name") {
body.insert("Parameter78.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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Streams.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Stop a Stream using either the SID of the Stream resource or the `name` used when creating the resource
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json
#[actor(
TwilioUpdateStreamActor,
inports::<100>(AccountSid, CallSid, Sid, Status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_stream(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if !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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Streams/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a Transcription
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions.json
#[actor(
TwilioCreateRealtimeTranscriptionActor,
inports::<100>(AccountSid, CallSid, ConversationConfiguration, InboundTrackLabel, StatusCallbackMethod, ConversationId, EnableProviderData, Hints, LanguageCode, Track, OutboundTrackLabel, IntelligenceService, PartialResults, ProfanityFilter, EnableAutomaticPunctuation, StatusCallbackUrl, SpeechModel, TranscriptionEngine, Name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_realtime_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("ConversationConfiguration") {
body.insert("ConversationConfiguration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("InboundTrackLabel") {
body.insert("InboundTrackLabel".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ConversationId") {
body.insert("ConversationId".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EnableProviderData") {
body.insert("EnableProviderData".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Hints") {
body.insert("Hints".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("LanguageCode") {
body.insert("LanguageCode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Track") {
body.insert("Track".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("OutboundTrackLabel") {
body.insert("OutboundTrackLabel".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IntelligenceService") {
body.insert("IntelligenceService".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PartialResults") {
body.insert("PartialResults".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ProfanityFilter") {
body.insert("ProfanityFilter".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EnableAutomaticPunctuation") {
body.insert("EnableAutomaticPunctuation".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackUrl") {
body.insert("StatusCallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SpeechModel") {
body.insert("SpeechModel".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TranscriptionEngine") {
body.insert("TranscriptionEngine".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Transcriptions.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Stop a Transcription using either the SID of the Transcription resource or the `name` used when creating the resource
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions/{Sid}.json
#[actor(
TwilioUpdateRealtimeTranscriptionActor,
inports::<100>(AccountSid, CallSid, Sid, Status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_realtime_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if !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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/Transcriptions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Subscribe to User Defined Messages for a given Call SID.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json
#[actor(
TwilioCreateUserDefinedMessageSubscriptionActor,
inports::<100>(AccountSid, CallSid, IdempotencyKey, Callback, Method),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_user_defined_message_subscription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("IdempotencyKey") {
body.insert("IdempotencyKey".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Callback") {
body.insert("Callback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Method") {
body.insert("Method".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/UserDefinedMessageSubscriptions.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a specific User Defined Message Subscription.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json
#[actor(
TwilioDeleteUserDefinedMessageSubscriptionActor,
inports::<100>(AccountSid, CallSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_user_defined_message_subscription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/UserDefinedMessageSubscriptions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new User Defined Message for the given Call SID.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json
#[actor(
TwilioCreateUserDefinedMessageActor,
inports::<100>(AccountSid, CallSid, Content, IdempotencyKey),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_user_defined_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Content") {
body.insert("Content".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdempotencyKey") {
body.insert("IdempotencyKey".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{CallSid}}/UserDefinedMessages.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch the call specified by the provided Call SID
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json
#[actor(
TwilioReadApi20100401CallActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_call(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Calls/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Initiates a call redirect or terminates a call
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json
#[actor(
TwilioUpdateCallActor,
inports::<100>(AccountSid, Sid, FallbackMethod, FallbackUrl, Twiml, StatusCallback, Status, Method, Url, StatusCallbackMethod, TimeLimit),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_call(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FallbackMethod") {
body.insert("FallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FallbackUrl") {
body.insert("FallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Twiml") {
body.insert("Twiml".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Method") {
body.insert("Method".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Url") {
body.insert("Url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TimeLimit") {
body.insert("TimeLimit".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 /2010-04-01/Accounts/{{AccountSid}}/Calls/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Delete a Call record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json
#[actor(
TwilioDeleteCallActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_call(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"DELETE /2010-04-01/Accounts/{{AccountSid}}/Calls/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of conferences belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Conferences.json
#[actor(
TwilioListConferenceActor,
inports::<100>(AccountSid, DateCreated, DateCreated_before, DateCreated_after, DateUpdated, DateUpdated_before, DateUpdated_after, FriendlyName, Status, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_conference(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Conferences.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("DateCreated") {
query_pairs.push(("DateCreated", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_before") {
query_pairs.push(("DateCreated<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_after") {
query_pairs.push(("DateCreated>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateUpdated") {
query_pairs.push(("DateUpdated", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateUpdated_before") {
query_pairs.push(("DateUpdated<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateUpdated_after") {
query_pairs.push(("DateUpdated>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Status") {
query_pairs.push(("Status", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Conferences.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of participants belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json
#[actor(
TwilioListParticipantActor,
inports::<100>(AccountSid, ConferenceSid, Muted, Hold, Coaching, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_participant(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Muted") {
query_pairs.push(("Muted", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Hold") {
query_pairs.push(("Hold", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Coaching") {
query_pairs.push(("Coaching", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Participants.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json
#[actor(
TwilioCreateParticipantActor,
inports::<100>(AccountSid, ConferenceSid, CallSidToCoach, StatusCallbackMethod, EarlyMedia, AmdStatusCallback, ConferenceRecord, ConferenceStatusCallbackMethod, ConferenceStatusCallbackEvent, Coaching, JitterBufferSize, AmdStatusCallbackMethod, RecordingStatusCallbackEvent, ConferenceRecordingStatusCallback, Muted, RecordingStatusCallbackMethod, ConferenceTrim, RecordingTrack, Record, Region, StatusCallback, StatusCallbackEvent, StartConferenceOnEnter, To, MachineDetectionSpeechThreshold, Trim, CallToken, ConferenceRecordingStatusCallbackEvent, WaitMethod, EndConferenceOnExit, Beep, MachineDetectionSpeechEndThreshold, CallerDisplayName, RecordingChannels, Byoc, ConferenceRecordingStatusCallbackMethod, ConferenceStatusCallback, MachineDetectionSilenceTimeout, From, TimeLimit, WaitUrl, CallReason, RecordingStatusCallback, SipAuthUsername, Timeout, MaxParticipants, MachineDetection, MachineDetectionTimeout, ClientNotificationUrl, Label, SipAuthPassword, CallerId),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_participant(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("CallSidToCoach") {
body.insert("CallSidToCoach".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EarlyMedia") {
body.insert("EarlyMedia".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AmdStatusCallback") {
body.insert("AmdStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ConferenceRecord") {
body.insert("ConferenceRecord".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ConferenceStatusCallbackMethod") {
body.insert(
"ConferenceStatusCallbackMethod".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ConferenceStatusCallbackEvent") {
body.insert(
"ConferenceStatusCallbackEvent".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("Coaching") {
body.insert("Coaching".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("JitterBufferSize") {
body.insert("JitterBufferSize".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AmdStatusCallbackMethod") {
body.insert("AmdStatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingStatusCallbackEvent") {
body.insert(
"RecordingStatusCallbackEvent".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ConferenceRecordingStatusCallback") {
body.insert(
"ConferenceRecordingStatusCallback".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("Muted") {
body.insert("Muted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingStatusCallbackMethod") {
body.insert(
"RecordingStatusCallbackMethod".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ConferenceTrim") {
body.insert("ConferenceTrim".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingTrack") {
body.insert("RecordingTrack".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Record") {
body.insert("Record".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Region") {
body.insert("Region".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackEvent") {
body.insert("StatusCallbackEvent".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StartConferenceOnEnter") {
body.insert("StartConferenceOnEnter".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("MachineDetectionSpeechThreshold") {
body.insert(
"MachineDetectionSpeechThreshold".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("Trim") {
body.insert("Trim".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallToken") {
body.insert("CallToken".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ConferenceRecordingStatusCallbackEvent") {
body.insert(
"ConferenceRecordingStatusCallbackEvent".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("WaitMethod") {
body.insert("WaitMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EndConferenceOnExit") {
body.insert("EndConferenceOnExit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Beep") {
body.insert("Beep".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MachineDetectionSpeechEndThreshold") {
body.insert(
"MachineDetectionSpeechEndThreshold".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("CallerDisplayName") {
body.insert("CallerDisplayName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingChannels") {
body.insert("RecordingChannels".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Byoc") {
body.insert("Byoc".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ConferenceRecordingStatusCallbackMethod") {
body.insert(
"ConferenceRecordingStatusCallbackMethod".to_string(),
val.clone().into(),
);
}
if let Some(val) = inputs.get("ConferenceStatusCallback") {
body.insert("ConferenceStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MachineDetectionSilenceTimeout") {
body.insert(
"MachineDetectionSilenceTimeout".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("TimeLimit") {
body.insert("TimeLimit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("WaitUrl") {
body.insert("WaitUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallReason") {
body.insert("CallReason".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RecordingStatusCallback") {
body.insert("RecordingStatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SipAuthUsername") {
body.insert("SipAuthUsername".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Timeout") {
body.insert("Timeout".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MaxParticipants") {
body.insert("MaxParticipants".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MachineDetection") {
body.insert("MachineDetection".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MachineDetectionTimeout") {
body.insert("MachineDetectionTimeout".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ClientNotificationUrl") {
body.insert("ClientNotificationUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Label") {
body.insert("Label".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SipAuthPassword") {
body.insert("SipAuthPassword".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallerId") {
body.insert("CallerId".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 /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Participants.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a participant
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json
#[actor(
TwilioReadApi20100401ParticipantActor,
inports::<100>(AccountSid, ConferenceSid, CallSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_participant(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Participants/{{CallSid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update the properties of the participant
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json
#[actor(
TwilioUpdateParticipantActor,
inports::<100>(AccountSid, ConferenceSid, CallSid, EndConferenceOnExit, Hold, BeepOnExit, AnnounceMethod, HoldMethod, Muted, AnnounceUrl, WaitMethod, Coaching, CallSidToCoach, HoldUrl, WaitUrl),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_participant(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("EndConferenceOnExit") {
body.insert("EndConferenceOnExit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Hold") {
body.insert("Hold".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("BeepOnExit") {
body.insert("BeepOnExit".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AnnounceMethod") {
body.insert("AnnounceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("HoldMethod") {
body.insert("HoldMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Muted") {
body.insert("Muted".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AnnounceUrl") {
body.insert("AnnounceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("WaitMethod") {
body.insert("WaitMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Coaching") {
body.insert("Coaching".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallSidToCoach") {
body.insert("CallSidToCoach".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("HoldUrl") {
body.insert("HoldUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("WaitUrl") {
body.insert("WaitUrl".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 /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Participants/{{CallSid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Kick a participant from a given conference
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json
#[actor(
TwilioDeleteParticipantActor,
inports::<100>(AccountSid, ConferenceSid, CallSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_participant(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Participants/{{CallSid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of recordings belonging to the call used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json
#[actor(
TwilioListConferenceRecordingActor,
inports::<100>(AccountSid, ConferenceSid, DateCreated, DateCreated_before, DateCreated_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_conference_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("DateCreated") {
query_pairs.push(("DateCreated", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_before") {
query_pairs.push(("DateCreated<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_after") {
query_pairs.push(("DateCreated>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Recordings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Changes the status of the recording to paused, stopped, or in-progress. Note: To use `Twilio.CURRENT`, pass it as recording sid.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json
#[actor(
TwilioUpdateConferenceRecordingActor,
inports::<100>(AccountSid, ConferenceSid, Sid, Status, PauseBehavior),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_conference_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PauseBehavior") {
body.insert("PauseBehavior".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 /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a recording for a call
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json
#[actor(
TwilioReadRecordingsActor,
inports::<100>(AccountSid, ConferenceSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_recordings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a recording from your account
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json
#[actor(
TwilioDeleteConferenceRecordingActor,
inports::<100>(AccountSid, ConferenceSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_conference_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ConferenceSid") {
endpoint = endpoint.replace("{{ConferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{ConferenceSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a conference
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json
#[actor(
TwilioReadApi20100401ConferenceActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_conference(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json
#[actor(
TwilioUpdateConferenceActor,
inports::<100>(AccountSid, Sid, AnnounceMethod, Status, AnnounceUrl),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_conference(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("AnnounceMethod") {
body.insert("AnnounceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AnnounceUrl") {
body.insert("AnnounceUrl".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 /2010-04-01/Accounts/{{AccountSid}}/Conferences/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of connect-apps belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/ConnectApps.json
#[actor(
TwilioListConnectAppActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_connect_app(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/ConnectApps.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Fetch an instance of a connect-app
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json
#[actor(
TwilioReadApi20100401ConnectAppActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_connect_app(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/ConnectApps/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update a connect-app with the specified parameters
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json
#[actor(
TwilioUpdateConnectAppActor,
inports::<100>(AccountSid, Sid, AuthorizeRedirectUrl, FriendlyName, CompanyName, Permissions, HomepageUrl, DeauthorizeCallbackMethod, DeauthorizeCallbackUrl, Description),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_connect_app(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("AuthorizeRedirectUrl") {
body.insert("AuthorizeRedirectUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CompanyName") {
body.insert("CompanyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Permissions") {
body.insert("Permissions".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("HomepageUrl") {
body.insert("HomepageUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("DeauthorizeCallbackMethod") {
body.insert("DeauthorizeCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("DeauthorizeCallbackUrl") {
body.insert("DeauthorizeCallbackUrl".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 /2010-04-01/Accounts/{{AccountSid}}/ConnectApps/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete an instance of a connect-app
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json
#[actor(
TwilioDeleteConnectAppActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_connect_app(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/ConnectApps/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of incoming-phone-numbers belonging to the account used to make the request.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json
#[actor(
TwilioListIncomingPhoneNumberActor,
inports::<100>(AccountSid, Beta, FriendlyName, PhoneNumber, Origin, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_incoming_phone_number(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PhoneNumber") {
query_pairs.push(("PhoneNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Origin") {
query_pairs.push(("Origin", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Purchase a phone-number for the account.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json
#[actor(
TwilioCreateIncomingPhoneNumberActor,
inports::<100>(AccountSid, VoiceApplicationSid, VoiceCallerIdLookup, PhoneNumber, ApiVersion, StatusCallback, StatusCallbackMethod, VoiceUrl, TrunkSid, EmergencyAddressSid, VoiceFallbackUrl, EmergencyStatus, FriendlyName, SmsFallbackMethod, AreaCode, VoiceMethod, BundleSid, IdentitySid, SmsMethod, VoiceFallbackMethod, VoiceReceiveMode, SmsUrl, SmsFallbackUrl, SmsApplicationSid, AddressSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_incoming_phone_number(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("VoiceApplicationSid") {
body.insert("VoiceApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PhoneNumber") {
body.insert("PhoneNumber".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TrunkSid") {
body.insert("TrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyAddressSid") {
body.insert("EmergencyAddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyStatus") {
body.insert("EmergencyStatus".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AreaCode") {
body.insert("AreaCode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("BundleSid") {
body.insert("BundleSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdentitySid") {
body.insert("IdentitySid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceReceiveMode") {
body.insert("VoiceReceiveMode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsApplicationSid") {
body.insert("SmsApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AddressSid") {
body.insert("AddressSid".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 /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json
#[actor(
TwilioListIncomingPhoneNumberLocalActor,
inports::<100>(AccountSid, Beta, FriendlyName, PhoneNumber, Origin, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_incoming_phone_number_local(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PhoneNumber") {
query_pairs.push(("PhoneNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Origin") {
query_pairs.push(("Origin", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/Local.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json
#[actor(
TwilioCreateIncomingPhoneNumberLocalActor,
inports::<100>(AccountSid, PhoneNumber, SmsFallbackUrl, SmsUrl, BundleSid, StatusCallback, VoiceApplicationSid, SmsMethod, StatusCallbackMethod, ApiVersion, SmsApplicationSid, EmergencyAddressSid, TrunkSid, VoiceFallbackUrl, VoiceMethod, VoiceUrl, AddressSid, VoiceCallerIdLookup, FriendlyName, IdentitySid, VoiceFallbackMethod, SmsFallbackMethod, EmergencyStatus, VoiceReceiveMode),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_incoming_phone_number_local(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("PhoneNumber") {
body.insert("PhoneNumber".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("BundleSid") {
body.insert("BundleSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceApplicationSid") {
body.insert("VoiceApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsApplicationSid") {
body.insert("SmsApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyAddressSid") {
body.insert("EmergencyAddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TrunkSid") {
body.insert("TrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AddressSid") {
body.insert("AddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdentitySid") {
body.insert("IdentitySid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyStatus") {
body.insert("EmergencyStatus".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceReceiveMode") {
body.insert("VoiceReceiveMode".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 /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/Local.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json
#[actor(
TwilioListIncomingPhoneNumberMobileActor,
inports::<100>(AccountSid, Beta, FriendlyName, PhoneNumber, Origin, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_incoming_phone_number_mobile(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PhoneNumber") {
query_pairs.push(("PhoneNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Origin") {
query_pairs.push(("Origin", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/Mobile.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json
#[actor(
TwilioCreateIncomingPhoneNumberMobileActor,
inports::<100>(AccountSid, SmsFallbackMethod, SmsMethod, EmergencyAddressSid, TrunkSid, SmsApplicationSid, StatusCallback, PhoneNumber, VoiceMethod, EmergencyStatus, SmsFallbackUrl, VoiceApplicationSid, VoiceCallerIdLookup, VoiceFallbackUrl, StatusCallbackMethod, ApiVersion, VoiceReceiveMode, AddressSid, VoiceFallbackMethod, VoiceUrl, FriendlyName, SmsUrl, IdentitySid, BundleSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_incoming_phone_number_mobile(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyAddressSid") {
body.insert("EmergencyAddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TrunkSid") {
body.insert("TrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsApplicationSid") {
body.insert("SmsApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PhoneNumber") {
body.insert("PhoneNumber".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyStatus") {
body.insert("EmergencyStatus".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceApplicationSid") {
body.insert("VoiceApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceReceiveMode") {
body.insert("VoiceReceiveMode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AddressSid") {
body.insert("AddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdentitySid") {
body.insert("IdentitySid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("BundleSid") {
body.insert("BundleSid".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 /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/Mobile.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json
#[actor(
TwilioListIncomingPhoneNumberTollFreeActor,
inports::<100>(AccountSid, Beta, FriendlyName, PhoneNumber, Origin, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_incoming_phone_number_toll_free(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Beta") {
query_pairs.push(("Beta", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PhoneNumber") {
query_pairs.push(("PhoneNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("Origin") {
query_pairs.push(("Origin", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/TollFree.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json
#[actor(
TwilioCreateIncomingPhoneNumberTollFreeActor,
inports::<100>(AccountSid, ApiVersion, StatusCallbackMethod, AddressSid, BundleSid, SmsFallbackMethod, SmsFallbackUrl, StatusCallback, EmergencyStatus, VoiceFallbackMethod, VoiceFallbackUrl, SmsApplicationSid, VoiceReceiveMode, VoiceUrl, VoiceCallerIdLookup, VoiceApplicationSid, SmsMethod, VoiceMethod, FriendlyName, IdentitySid, TrunkSid, EmergencyAddressSid, SmsUrl, PhoneNumber),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_incoming_phone_number_toll_free(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AddressSid") {
body.insert("AddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("BundleSid") {
body.insert("BundleSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyStatus") {
body.insert("EmergencyStatus".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsApplicationSid") {
body.insert("SmsApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceReceiveMode") {
body.insert("VoiceReceiveMode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceApplicationSid") {
body.insert("VoiceApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdentitySid") {
body.insert("IdentitySid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TrunkSid") {
body.insert("TrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyAddressSid") {
body.insert("EmergencyAddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PhoneNumber") {
body.insert("PhoneNumber".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 /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/TollFree.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of Add-on installations currently assigned to this Number.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json
#[actor(
TwilioListIncomingPhoneNumberAssignedAddOnActor,
inports::<100>(AccountSid, ResourceSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_incoming_phone_number_assigned_add_on(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ResourceSid") {
endpoint = endpoint.replace("{{ResourceSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{ResourceSid}}/AssignedAddOns.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Assign an Add-on installation to the Number specified.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json
#[actor(
TwilioCreateIncomingPhoneNumberAssignedAddOnActor,
inports::<100>(AccountSid, ResourceSid, InstalledAddOnSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_incoming_phone_number_assigned_add_on(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ResourceSid") {
endpoint = endpoint.replace("{{ResourceSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("InstalledAddOnSid") {
body.insert("InstalledAddOnSid".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 /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{ResourceSid}}/AssignedAddOns.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of Extensions for the Assigned Add-on.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json
#[actor(
TwilioListIncomingPhoneNumberAssignedAddOnExtensionActor,
inports::<100>(AccountSid, ResourceSid, AssignedAddOnSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_incoming_phone_number_assigned_add_on_extension(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ResourceSid") {
endpoint = endpoint.replace("{{ResourceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AssignedAddOnSid") {
endpoint = endpoint.replace("{{AssignedAddOnSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{ResourceSid}}/AssignedAddOns/{{AssignedAddOnSid}}/Extensions.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of an Extension for the Assigned Add-on.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json
#[actor(
TwilioReadExtensionsActor,
inports::<100>(AccountSid, ResourceSid, AssignedAddOnSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_extensions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ResourceSid") {
endpoint = endpoint.replace("{{ResourceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AssignedAddOnSid") {
endpoint = endpoint.replace("{{AssignedAddOnSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{ResourceSid}}/AssignedAddOns/{{AssignedAddOnSid}}/Extensions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of an Add-on installation currently assigned to this Number.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json
#[actor(
TwilioReadApi20100401AssignedAddOnActor,
inports::<100>(AccountSid, ResourceSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_assigned_add_on(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ResourceSid") {
endpoint = endpoint.replace("{{ResourceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{ResourceSid}}/AssignedAddOns/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Remove the assignment of an Add-on installation from the Number specified.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json
#[actor(
TwilioDeleteIncomingPhoneNumberAssignedAddOnActor,
inports::<100>(AccountSid, ResourceSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_incoming_phone_number_assigned_add_on(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ResourceSid") {
endpoint = endpoint.replace("{{ResourceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{ResourceSid}}/AssignedAddOns/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update an incoming-phone-number instance.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json
#[actor(
TwilioUpdateIncomingPhoneNumberActor,
inports::<100>(AccountSid, Sid, BundleSid, SmsApplicationSid, EmergencyAddressSid, AddressSid, TrunkSid, SmsUrl, VoiceCallerIdLookup, VoiceFallbackUrl, VoiceMethod, SmsFallbackMethod, VoiceUrl, FriendlyName, ApiVersion, StatusCallback, VoiceReceiveMode, VoiceFallbackMethod, IdentitySid, SmsMethod, VoiceApplicationSid, SmsFallbackUrl, EmergencyStatus, StatusCallbackMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_incoming_phone_number(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("BundleSid") {
body.insert("BundleSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsApplicationSid") {
body.insert("SmsApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyAddressSid") {
body.insert("EmergencyAddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AddressSid") {
body.insert("AddressSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TrunkSid") {
body.insert("TrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceCallerIdLookup") {
body.insert("VoiceCallerIdLookup".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceReceiveMode") {
body.insert("VoiceReceiveMode".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IdentitySid") {
body.insert("IdentitySid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceApplicationSid") {
body.insert("VoiceApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AccountSid") {
body.insert("AccountSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyStatus") {
body.insert("EmergencyStatus".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".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 /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an incoming-phone-number belonging to the account used to make the request.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json
#[actor(
TwilioReadIncomingPhoneNumbersActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_incoming_phone_numbers(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a phone-numbers belonging to the account used to make the request.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json
#[actor(
TwilioDeleteIncomingPhoneNumberActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_incoming_phone_number(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/IncomingPhoneNumbers/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Keys.json
#[actor(
TwilioCreateNewKeyActor,
inports::<100>(AccountSid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_new_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Keys.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/Keys.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Keys.json
#[actor(
TwilioListKeyActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_key(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Keys.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Keys.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json
#[actor(
TwilioReadApi20100401KeyActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Keys/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json
#[actor(
TwilioUpdateKeyActor,
inports::<100>(AccountSid, Sid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_key(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/Keys/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json
#[actor(
TwilioDeleteKeyActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_key(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"DELETE /2010-04-01/Accounts/{{AccountSid}}/Keys/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Send a message
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Messages.json
#[actor(
TwilioCreateMessageActor,
inports::<100>(AccountSid, StatusCallback, ContentRetention, SendAsMms, From, To, MaxPrice, MessagingServiceSid, RiskCheck, ProvideFeedback, PersistentAction, AddressRetention, MediaUrl, ShortenUrls, Body, ScheduleType, ForceDelivery, SendAt, ValidityPeriod, ApplicationSid, Attempt, SmartEncoded, ContentVariables, ContentSid, TrafficType),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Messages.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ContentRetention") {
body.insert("ContentRetention".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SendAsMms") {
body.insert("SendAsMms".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("MaxPrice") {
body.insert("MaxPrice".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MessagingServiceSid") {
body.insert("MessagingServiceSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("RiskCheck") {
body.insert("RiskCheck".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ProvideFeedback") {
body.insert("ProvideFeedback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PersistentAction") {
body.insert("PersistentAction".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("AddressRetention") {
body.insert("AddressRetention".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MediaUrl") {
body.insert("MediaUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ShortenUrls") {
body.insert("ShortenUrls".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("ScheduleType") {
body.insert("ScheduleType".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ForceDelivery") {
body.insert("ForceDelivery".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SendAt") {
body.insert("SendAt".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ValidityPeriod") {
body.insert("ValidityPeriod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApplicationSid") {
body.insert("ApplicationSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Attempt") {
body.insert("Attempt".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmartEncoded") {
body.insert("SmartEncoded".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ContentVariables") {
body.insert("ContentVariables".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ContentSid") {
body.insert("ContentSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TrafficType") {
body.insert("TrafficType".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 /2010-04-01/Accounts/{{AccountSid}}/Messages.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of Message resources associated with a Twilio Account
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Messages.json
#[actor(
TwilioListMessageActor,
inports::<100>(AccountSid, To, From, DateSent, DateSent_before, DateSent_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_message(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Messages.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("To") {
query_pairs.push(("To", super::message_to_str(val)));
}
if let Some(val) = inputs.get("From") {
query_pairs.push(("From", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateSent") {
query_pairs.push(("DateSent", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateSent_before") {
query_pairs.push(("DateSent<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateSent_after") {
query_pairs.push(("DateSent>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Messages.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create Message Feedback to confirm a tracked user action was performed by the recipient of the associated Message
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json
#[actor(
TwilioCreateMessageFeedbackActor,
inports::<100>(AccountSid, MessageSid, Outcome),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_message_feedback(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("MessageSid") {
endpoint = endpoint.replace("{{MessageSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Outcome") {
body.insert("Outcome".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 /2010-04-01/Accounts/{{AccountSid}}/Messages/{{MessageSid}}/Feedback.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Read a list of Media resources associated with a specific Message resource
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json
#[actor(
TwilioListMediaActor,
inports::<100>(AccountSid, MessageSid, DateCreated, DateCreated_before, DateCreated_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_media(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("MessageSid") {
endpoint = endpoint.replace("{{MessageSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("DateCreated") {
query_pairs.push(("DateCreated", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_before") {
query_pairs.push(("DateCreated<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_after") {
query_pairs.push(("DateCreated>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Messages/{{MessageSid}}/Media.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a single Media resource associated with a specific Message resource
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json
#[actor(
TwilioReadApi20100401MediaInstanceActor,
inports::<100>(AccountSid, MessageSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_media_instance(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("MessageSid") {
endpoint = endpoint.replace("{{MessageSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Messages/{{MessageSid}}/Media/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete the Media resource.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json
#[actor(
TwilioDeleteMediaActor,
inports::<100>(AccountSid, MessageSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_media(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("MessageSid") {
endpoint = endpoint.replace("{{MessageSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Messages/{{MessageSid}}/Media/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a specific Message
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json
#[actor(
TwilioReadApi20100401MessageActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Messages/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update a Message resource (used to redact Message `body` text and to cancel not-yet-sent messages)
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json
#[actor(
TwilioUpdateMessageActor,
inports::<100>(AccountSid, Sid, Body, Status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Body") {
body.insert("Body".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"POST /2010-04-01/Accounts/{{AccountSid}}/Messages/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Deletes a Message resource from your account
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json
#[actor(
TwilioDeleteMessageActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_message(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Messages/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of notifications belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Notifications.json
#[actor(
TwilioListNotificationActor,
inports::<100>(AccountSid, Log, MessageDate, MessageDate_before, MessageDate_after, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_notification(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Notifications.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Log") {
query_pairs.push(("Log", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MessageDate") {
query_pairs.push(("MessageDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MessageDate_before") {
query_pairs.push(("MessageDate<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("MessageDate_after") {
query_pairs.push(("MessageDate>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Notifications.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Fetch a notification belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json
#[actor(
TwilioReadApi20100401NotificationActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_notification(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Notifications/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of outgoing-caller-ids belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json
#[actor(
TwilioListOutgoingCallerIdActor,
inports::<100>(AccountSid, PhoneNumber, FriendlyName, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_outgoing_caller_id(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PhoneNumber") {
query_pairs.push(("PhoneNumber", super::message_to_str(val)));
}
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/OutgoingCallerIds.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json
#[actor(
TwilioCreateValidationRequestActor,
inports::<100>(AccountSid, Extension, StatusCallback, CallDelay, PhoneNumber, FriendlyName, StatusCallbackMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_validation_request(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Extension") {
body.insert("Extension".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallback") {
body.insert("StatusCallback".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallDelay") {
body.insert("CallDelay".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("PhoneNumber") {
body.insert("PhoneNumber".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("StatusCallbackMethod") {
body.insert("StatusCallbackMethod".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 /2010-04-01/Accounts/{{AccountSid}}/OutgoingCallerIds.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an outgoing-caller-id belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json
#[actor(
TwilioReadOutgoingCallerIdsActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_outgoing_caller_ids(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/OutgoingCallerIds/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete the caller-id specified from the account
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json
#[actor(
TwilioDeleteOutgoingCallerIdActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_outgoing_caller_id(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/OutgoingCallerIds/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Updates the caller-id
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json
#[actor(
TwilioUpdateOutgoingCallerIdActor,
inports::<100>(AccountSid, Sid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_outgoing_caller_id(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/OutgoingCallerIds/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a queue
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Queues.json
#[actor(
TwilioCreateQueueActor,
inports::<100>(AccountSid, FriendlyName, MaxSize),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_queue(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Queues.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MaxSize") {
body.insert("MaxSize".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 /2010-04-01/Accounts/{{AccountSid}}/Queues.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of queues belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Queues.json
#[actor(
TwilioListQueueActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_queue(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Queues.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Queues.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve the members of the queue
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json
#[actor(
TwilioListMemberActor,
inports::<100>(AccountSid, QueueSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_member(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("QueueSid") {
endpoint = endpoint.replace("{{QueueSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Queues/{{QueueSid}}/Members.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Dequeue a member from a queue and have the member's call begin executing the TwiML document at that URL
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json
#[actor(
TwilioUpdateMemberActor,
inports::<100>(AccountSid, QueueSid, CallSid, Url, Method),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_member(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("QueueSid") {
endpoint = endpoint.replace("{{QueueSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Url") {
body.insert("Url".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Method") {
body.insert("Method".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /2010-04-01/Accounts/{{AccountSid}}/Queues/{{QueueSid}}/Members/{{CallSid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a specific member from the queue
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json
#[actor(
TwilioReadApi20100401MemberActor,
inports::<100>(AccountSid, QueueSid, CallSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_member(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("QueueSid") {
endpoint = endpoint.replace("{{QueueSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CallSid") {
endpoint = endpoint.replace("{{CallSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Queues/{{QueueSid}}/Members/{{CallSid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a queue identified by the QueueSid
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json
#[actor(
TwilioReadApi20100401QueueActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_queue(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Queues/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Remove an empty queue
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json
#[actor(
TwilioDeleteQueueActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_queue(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"DELETE /2010-04-01/Accounts/{{AccountSid}}/Queues/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update the queue with the new parameters
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json
#[actor(
TwilioUpdateQueueActor,
inports::<100>(AccountSid, Sid, FriendlyName, MaxSize),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_queue(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("MaxSize") {
body.insert("MaxSize".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 /2010-04-01/Accounts/{{AccountSid}}/Queues/{{Sid}}.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of recordings belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings.json
#[actor(
TwilioListRecordingActor,
inports::<100>(AccountSid, DateCreated, DateCreated_before, DateCreated_after, CallSid, ConferenceSid, IncludeSoftDeleted, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("DateCreated") {
query_pairs.push(("DateCreated", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_before") {
query_pairs.push(("DateCreated<", super::message_to_str(val)));
}
if let Some(val) = inputs.get("DateCreated_after") {
query_pairs.push(("DateCreated>", super::message_to_str(val)));
}
if let Some(val) = inputs.get("CallSid") {
query_pairs.push(("CallSid", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ConferenceSid") {
query_pairs.push(("ConferenceSid", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSoftDeleted") {
query_pairs.push(("IncludeSoftDeleted", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Recordings.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json
#[actor(
TwilioListRecordingTranscriptionActor,
inports::<100>(AccountSid, RecordingSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_recording_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("RecordingSid") {
endpoint = endpoint.replace("{{RecordingSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{RecordingSid}}/Transcriptions.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json
#[actor(
TwilioReadTranscriptionsActor,
inports::<100>(AccountSid, RecordingSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_transcriptions(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("RecordingSid") {
endpoint = endpoint.replace("{{RecordingSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{RecordingSid}}/Transcriptions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json
#[actor(
TwilioDeleteRecordingTranscriptionActor,
inports::<100>(AccountSid, RecordingSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_recording_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("RecordingSid") {
endpoint = endpoint.replace("{{RecordingSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{RecordingSid}}/Transcriptions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of results belonging to the recording
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json
#[actor(
TwilioListRecordingAddOnResultActor,
inports::<100>(AccountSid, ReferenceSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_recording_add_on_result(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of payloads belonging to the AddOnResult
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads.json
#[actor(
TwilioListRecordingAddOnResultPayloadActor,
inports::<100>(AccountSid, ReferenceSid, AddOnResultSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_recording_add_on_result_payload(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AddOnResultSid") {
endpoint = endpoint.replace("{{AddOnResultSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults/{{AddOnResultSid}}/Payloads.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a result payload
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{PayloadSid}/Data.json
#[actor(
TwilioReadApi20100401DataActor,
inports::<100>(AccountSid, ReferenceSid, AddOnResultSid, PayloadSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_data(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{PayloadSid}/Data.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AddOnResultSid") {
endpoint = endpoint.replace("{{AddOnResultSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("PayloadSid") {
endpoint = endpoint.replace("{{PayloadSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults/{{AddOnResultSid}}/Payloads/{{PayloadSid}}/Data.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a result payload
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json
#[actor(
TwilioReadApi20100401PayloadActor,
inports::<100>(AccountSid, ReferenceSid, AddOnResultSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_payload(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AddOnResultSid") {
endpoint = endpoint.replace("{{AddOnResultSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults/{{AddOnResultSid}}/Payloads/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a payload from the result along with all associated Data
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json
#[actor(
TwilioDeleteRecordingAddOnResultPayloadActor,
inports::<100>(AccountSid, ReferenceSid, AddOnResultSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_recording_add_on_result_payload(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("AddOnResultSid") {
endpoint = endpoint.replace("{{AddOnResultSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults/{{AddOnResultSid}}/Payloads/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of an AddOnResult
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json
#[actor(
TwilioReadApi20100401AddOnResultActor,
inports::<100>(AccountSid, ReferenceSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_add_on_result(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a result and purge all associated Payloads
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json
#[actor(
TwilioDeleteRecordingAddOnResultActor,
inports::<100>(AccountSid, ReferenceSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_recording_add_on_result(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("ReferenceSid") {
endpoint = endpoint.replace("{{ReferenceSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{ReferenceSid}}/AddOnResults/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a recording from your account
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json
#[actor(
TwilioDeleteRecordingActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a recording
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json
#[actor(
TwilioReadApi20100401RecordingActor,
inports::<100>(AccountSid, Sid, IncludeSoftDeleted),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_recording(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("IncludeSoftDeleted") {
query_pairs.push(("IncludeSoftDeleted", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Recordings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Get All Credential Lists
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json
#[actor(
TwilioListSipCredentialListActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_credential_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a Credential List
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json
#[actor(
TwilioCreateSipCredentialListActor,
inports::<100>(AccountSid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_credential_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new credential resource.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json
#[actor(
TwilioCreateSipCredentialActor,
inports::<100>(AccountSid, CredentialListSid, Username, Password),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_credential(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CredentialListSid") {
endpoint = endpoint.replace("{{CredentialListSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Username") {
body.insert("Username".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Password") {
body.insert("Password".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{CredentialListSid}}/Credentials.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of credentials.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json
#[actor(
TwilioListSipCredentialActor,
inports::<100>(AccountSid, CredentialListSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_credential(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CredentialListSid") {
endpoint = endpoint.replace("{{CredentialListSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{CredentialListSid}}/Credentials.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a single credential.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json
#[actor(
TwilioReadApi20100401CredentialActor,
inports::<100>(AccountSid, CredentialListSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_credential(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CredentialListSid") {
endpoint = endpoint.replace("{{CredentialListSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{CredentialListSid}}/Credentials/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a credential resource.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json
#[actor(
TwilioDeleteSipCredentialActor,
inports::<100>(AccountSid, CredentialListSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_credential(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CredentialListSid") {
endpoint = endpoint.replace("{{CredentialListSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{CredentialListSid}}/Credentials/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update a credential resource.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json
#[actor(
TwilioUpdateSipCredentialActor,
inports::<100>(AccountSid, CredentialListSid, Sid, Password),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_sip_credential(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("CredentialListSid") {
endpoint = endpoint.replace("{{CredentialListSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Password") {
body.insert("Password".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{CredentialListSid}}/Credentials/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a Credential List
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json
#[actor(
TwilioDeleteSipCredentialListActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_credential_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Get a Credential List
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json
#[actor(
TwilioReadApi20100401CredentialListActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_credential_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update a Credential List
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json
#[actor(
TwilioUpdateSipCredentialListActor,
inports::<100>(AccountSid, Sid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_sip_credential_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/CredentialLists/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new Domain
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains.json
#[actor(
TwilioCreateSipDomainActor,
inports::<100>(AccountSid, FriendlyName, DomainName, VoiceUrl, EmergencyCallerSid, Secure, VoiceStatusCallbackMethod, EmergencyCallingEnabled, VoiceFallbackUrl, VoiceFallbackMethod, VoiceMethod, ByocTrunkSid, SipRegistration, VoiceStatusCallbackUrl),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_domain(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("DomainName") {
body.insert("DomainName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyCallerSid") {
body.insert("EmergencyCallerSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Secure") {
body.insert("Secure".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceStatusCallbackMethod") {
body.insert("VoiceStatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyCallingEnabled") {
body.insert("EmergencyCallingEnabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ByocTrunkSid") {
body.insert("ByocTrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SipRegistration") {
body.insert("SipRegistration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceStatusCallbackUrl") {
body.insert("VoiceStatusCallbackUrl".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of domains belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains.json
#[actor(
TwilioListSipDomainActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_domain(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Create a new credential list mapping resource
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json
#[actor(
TwilioCreateSipAuthCallsCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, CredentialListSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_auth_calls_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("CredentialListSid") {
body.insert("CredentialListSid".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/CredentialListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of credential list mappings belonging to the domain used in the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json
#[actor(
TwilioListSipAuthCallsCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_auth_calls_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/CredentialListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a credential list mapping from the requested domain
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json
#[actor(
TwilioDeleteSipAuthCallsCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_auth_calls_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/CredentialListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a specific instance of a credential list mapping
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json
#[actor(
TwilioReadCredentialListMappingsActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_credential_list_mappings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/CredentialListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of IP Access Control List mappings belonging to the domain used in the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json
#[actor(
TwilioListSipAuthCallsIpAccessControlListMappingActor,
inports::<100>(AccountSid, DomainSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_auth_calls_ip_access_control_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/IpAccessControlListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new IP Access Control List mapping
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json
#[actor(
TwilioCreateSipAuthCallsIpAccessControlListMappingActor,
inports::<100>(AccountSid, DomainSid, IpAccessControlListSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_auth_calls_ip_access_control_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("IpAccessControlListSid") {
body.insert("IpAccessControlListSid".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/IpAccessControlListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a specific instance of an IP Access Control List mapping
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json
#[actor(
TwilioReadIpAccessControlListMappingsActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_ip_access_control_list_mappings(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/IpAccessControlListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete an IP Access Control List mapping from the requested domain
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json
#[actor(
TwilioDeleteSipAuthCallsIpAccessControlListMappingActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_auth_calls_ip_access_control_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Calls/IpAccessControlListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new credential list mapping resource
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json
#[actor(
TwilioCreateSipAuthRegistrationsCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, CredentialListSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_auth_registrations_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("CredentialListSid") {
body.insert("CredentialListSid".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Registrations/CredentialListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of credential list mappings belonging to the domain used in the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json
#[actor(
TwilioListSipAuthRegistrationsCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_auth_registrations_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Registrations/CredentialListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a credential list mapping from the requested domain
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json
#[actor(
TwilioDeleteSipAuthRegistrationsCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_auth_registrations_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/Auth/Registrations/CredentialListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Read multiple CredentialListMapping resources from an account.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json
#[actor(
TwilioListSipCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/CredentialListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a CredentialListMapping resource for an account.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json
#[actor(
TwilioCreateSipCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, CredentialListSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"
.to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("CredentialListSid") {
body.insert("CredentialListSid".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/CredentialListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a CredentialListMapping resource from an account.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json
#[actor(
TwilioDeleteSipCredentialListMappingActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_credential_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/CredentialListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of IpAccessControlListMapping resources.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json
#[actor(
TwilioListSipIpAccessControlListMappingActor,
inports::<100>(AccountSid, DomainSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_ip_access_control_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/IpAccessControlListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new IpAccessControlListMapping resource.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json
#[actor(
TwilioCreateSipIpAccessControlListMappingActor,
inports::<100>(AccountSid, DomainSid, IpAccessControlListSid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_ip_access_control_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("IpAccessControlListSid") {
body.insert("IpAccessControlListSid".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/IpAccessControlListMappings.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete an IpAccessControlListMapping resource.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json
#[actor(
TwilioDeleteSipIpAccessControlListMappingActor,
inports::<100>(AccountSid, DomainSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_ip_access_control_list_mapping(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("DomainSid") {
endpoint = endpoint.replace("{{DomainSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{DomainSid}}/IpAccessControlListMappings/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a Domain
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json
#[actor(
TwilioReadApi20100401DomainActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_domain(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update the attributes of a domain
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json
#[actor(
TwilioUpdateSipDomainActor,
inports::<100>(AccountSid, Sid, ByocTrunkSid, EmergencyCallingEnabled, VoiceFallbackMethod, EmergencyCallerSid, Secure, VoiceFallbackUrl, VoiceUrl, VoiceStatusCallbackMethod, DomainName, VoiceStatusCallbackUrl, FriendlyName, SipRegistration, VoiceMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_sip_domain(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("ByocTrunkSid") {
body.insert("ByocTrunkSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyCallingEnabled") {
body.insert("EmergencyCallingEnabled".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackMethod") {
body.insert("VoiceFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("EmergencyCallerSid") {
body.insert("EmergencyCallerSid".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Secure") {
body.insert("Secure".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceFallbackUrl") {
body.insert("VoiceFallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceUrl") {
body.insert("VoiceUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceStatusCallbackMethod") {
body.insert("VoiceStatusCallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("DomainName") {
body.insert("DomainName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceStatusCallbackUrl") {
body.insert("VoiceStatusCallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SipRegistration") {
body.insert("SipRegistration".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("VoiceMethod") {
body.insert("VoiceMethod".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete an instance of a Domain
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json
#[actor(
TwilioDeleteSipDomainActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_domain(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/Domains/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new IpAccessControlList resource
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json
#[actor(
TwilioCreateSipIpAccessControlListActor,
inports::<100>(AccountSid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_ip_access_control_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of IpAccessControlLists that belong to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json
#[actor(
TwilioListSipIpAccessControlListActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_ip_access_control_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Read multiple IpAddress resources.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json
#[actor(
TwilioListSipIpAddressActor,
inports::<100>(AccountSid, IpAccessControlListSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_sip_ip_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("IpAccessControlListSid") {
endpoint = endpoint.replace("{{IpAccessControlListSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{IpAccessControlListSid}}/IpAddresses.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new IpAddress resource.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json
#[actor(
TwilioCreateSipIpAddressActor,
inports::<100>(AccountSid, IpAccessControlListSid, IpAddress, CidrPrefixLength, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_sip_ip_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("IpAccessControlListSid") {
endpoint = endpoint.replace("{{IpAccessControlListSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("IpAddress") {
body.insert("IpAddress".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CidrPrefixLength") {
body.insert("CidrPrefixLength".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{IpAccessControlListSid}}/IpAddresses.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Read one IpAddress resource.
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json
#[actor(
TwilioReadApi20100401SipIpAddressActor,
inports::<100>(AccountSid, IpAccessControlListSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_sip_ip_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("IpAccessControlListSid") {
endpoint = endpoint.replace("{{IpAccessControlListSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{IpAccessControlListSid}}/IpAddresses/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Update an IpAddress resource.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json
#[actor(
TwilioUpdateSipIpAddressActor,
inports::<100>(AccountSid, IpAccessControlListSid, Sid, FriendlyName, CidrPrefixLength, IpAddress),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_sip_ip_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("IpAccessControlListSid") {
endpoint = endpoint.replace("{{IpAccessControlListSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CidrPrefixLength") {
body.insert("CidrPrefixLength".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("IpAddress") {
body.insert("IpAddress".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{IpAccessControlListSid}}/IpAddresses/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete an IpAddress resource.
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json
#[actor(
TwilioDeleteSipIpAddressActor,
inports::<100>(AccountSid, IpAccessControlListSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_ip_address(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("IpAccessControlListSid") {
endpoint = endpoint.replace("{{IpAccessControlListSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{IpAccessControlListSid}}/IpAddresses/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete an IpAccessControlList from the requested account
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json
#[actor(
TwilioDeleteSipIpAccessControlListActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_sip_ip_access_control_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch a specific instance of an IpAccessControlList
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json
#[actor(
TwilioReadIpAccessControlListsActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_ip_access_control_lists(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Rename an IpAccessControlList
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json
#[actor(
TwilioUpdateSipIpAccessControlListActor,
inports::<100>(AccountSid, Sid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_sip_ip_access_control_list(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SIP/IpAccessControlLists/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of short-codes belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes.json
#[actor(
TwilioListShortCodeActor,
inports::<100>(AccountSid, FriendlyName, ShortCode, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_short_code(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("FriendlyName") {
query_pairs.push(("FriendlyName", super::message_to_str(val)));
}
if let Some(val) = inputs.get("ShortCode") {
query_pairs.push(("ShortCode", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/SMS/ShortCodes.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update a short code with the following parameters
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json
#[actor(
TwilioUpdateShortCodeActor,
inports::<100>(AccountSid, Sid, SmsFallbackMethod, ApiVersion, FriendlyName, SmsUrl, SmsMethod, SmsFallbackUrl),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_short_code(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("SmsFallbackMethod") {
body.insert("SmsFallbackMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("ApiVersion") {
body.insert("ApiVersion".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsUrl") {
body.insert("SmsUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsMethod") {
body.insert("SmsMethod".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("SmsFallbackUrl") {
body.insert("SmsFallbackUrl".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 /2010-04-01/Accounts/{{AccountSid}}/SMS/ShortCodes/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch an instance of a short code
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json
#[actor(
TwilioReadApi20100401ShortCodeActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_short_code(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SMS/ShortCodes/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new Signing Key for the account making the request.
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SigningKeys.json
#[actor(
TwilioCreateNewSigningKeyActor,
inports::<100>(AccountSid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_new_signing_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SigningKeys.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SigningKeys.json
#[actor(
TwilioListSigningKeyActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_signing_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/SigningKeys.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json
#[actor(
TwilioDeleteSigningKeyActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_signing_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/SigningKeys/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json
#[actor(
TwilioUpdateSigningKeyActor,
inports::<100>(AccountSid, Sid, FriendlyName),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_signing_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".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 /2010-04-01/Accounts/{{AccountSid}}/SigningKeys/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json
#[actor(
TwilioReadApi20100401SigningKeyActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_signing_key(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/SigningKeys/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new token for ICE servers
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Tokens.json
#[actor(
TwilioCreateTokenActor,
inports::<100>(AccountSid, Ttl),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_token(context: ActorContext) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Tokens.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("Ttl") {
body.insert("Ttl".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 /2010-04-01/Accounts/{{AccountSid}}/Tokens.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of transcriptions belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Transcriptions.json
#[actor(
TwilioListTranscriptionActor,
inports::<100>(AccountSid, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Transcriptions.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Transcriptions.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Fetch an instance of a Transcription
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json
#[actor(
TwilioReadApi20100401TranscriptionActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Transcriptions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Delete a transcription from the account used to make the request
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json
#[actor(
TwilioDeleteTranscriptionActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_transcription(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Transcriptions/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Retrieve a list of usage-records belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records.json
#[actor(
TwilioListUsageRecordActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/AllTime.json
#[actor(
TwilioListUsageRecordAllTimeActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_all_time(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/AllTime.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/AllTime.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json
#[actor(
TwilioListUsageRecordDailyActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_daily(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/Daily.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/LastMonth.json
#[actor(
TwilioListUsageRecordLastMonthActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_last_month(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/LastMonth.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/LastMonth.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/Monthly.json
#[actor(
TwilioListUsageRecordMonthlyActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_monthly(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Monthly.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/Monthly.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/ThisMonth.json
#[actor(
TwilioListUsageRecordThisMonthActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_this_month(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/ThisMonth.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/ThisMonth.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/Today.json
#[actor(
TwilioListUsageRecordTodayActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_today(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Today.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/Today.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/Yearly.json
#[actor(
TwilioListUsageRecordYearlyActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_yearly(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yearly.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/Yearly.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Records/Yesterday.json
#[actor(
TwilioListUsageRecordYesterdayActor,
inports::<100>(AccountSid, Category, StartDate, EndDate, IncludeSubaccounts, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_record_yesterday(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yesterday.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Category") {
query_pairs.push(("Category", super::message_to_str(val)));
}
if let Some(val) = inputs.get("StartDate") {
query_pairs.push(("StartDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("EndDate") {
query_pairs.push(("EndDate", super::message_to_str(val)));
}
if let Some(val) = inputs.get("IncludeSubaccounts") {
query_pairs.push(("IncludeSubaccounts", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Records/Yesterday.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Create a new UsageTrigger
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json
#[actor(
TwilioCreateUsageTriggerActor,
inports::<100>(AccountSid, TriggerValue, FriendlyName, UsageCategory, Recurring, TriggerBy, CallbackUrl, CallbackMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_create_usage_trigger(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("TriggerValue") {
body.insert("TriggerValue".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("UsageCategory") {
body.insert("UsageCategory".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Recurring") {
body.insert("Recurring".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("TriggerBy") {
body.insert("TriggerBy".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallbackUrl") {
body.insert("CallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallbackMethod") {
body.insert("CallbackMethod".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 /2010-04-01/Accounts/{{AccountSid}}/Usage/Triggers.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Retrieve a list of usage-triggers belonging to the account used to make the request
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json
#[actor(
TwilioListUsageTriggerActor,
inports::<100>(AccountSid, Recurring, TriggerBy, UsageCategory, PageSize, Page, PageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_list_usage_trigger(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("Recurring") {
query_pairs.push(("Recurring", super::message_to_str(val)));
}
if let Some(val) = inputs.get("TriggerBy") {
query_pairs.push(("TriggerBy", super::message_to_str(val)));
}
if let Some(val) = inputs.get("UsageCategory") {
query_pairs.push(("UsageCategory", super::message_to_str(val)));
}
if let Some(val) = inputs.get("PageSize") {
query_pairs.push(("PageSize", 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("PageToken") {
query_pairs.push(("PageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!(
"GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Triggers.json failed: {}",
e
)
.into(),
),
);
}
}
Ok(output)
}
/// Update an instance of a usage trigger
///
/// Method: POST /2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json
#[actor(
TwilioUpdateUsageTriggerActor,
inports::<100>(AccountSid, Sid, CallbackUrl, FriendlyName, CallbackMethod),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_usage_trigger(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("CallbackUrl") {
body.insert("CallbackUrl".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("CallbackMethod") {
body.insert("CallbackMethod".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 /2010-04-01/Accounts/{{AccountSid}}/Usage/Triggers/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch and instance of a usage-trigger
///
/// Method: GET /2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json
#[actor(
TwilioReadApi20100401TriggerActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_trigger(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /2010-04-01/Accounts/{{AccountSid}}/Usage/Triggers/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
///
///
/// Method: DELETE /2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json
#[actor(
TwilioDeleteUsageTriggerActor,
inports::<100>(AccountSid, Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_delete_usage_trigger(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json".to_string();
if let Some(val) = inputs.get("AccountSid") {
endpoint = endpoint.replace("{{AccountSid}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("DELETE /2010-04-01/Accounts/{{AccountSid}}/Usage/Triggers/{{Sid}}.json failed: {}", e).into()));
}
}
Ok(output)
}
/// Fetch the account specified by the provided Account Sid
///
/// Method: GET /2010-04-01/Accounts/{Sid}.json
#[actor(
TwilioReadApi20100401AccountActor,
inports::<100>(Sid),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_read_api20100401_account(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{Sid}.json".to_string();
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!("GET /2010-04-01/Accounts/{{Sid}}.json failed: {}", e).into(),
),
);
}
}
Ok(output)
}
/// Modify the properties of a given Account
///
/// Method: POST /2010-04-01/Accounts/{Sid}.json
#[actor(
TwilioUpdateAccountActor,
inports::<100>(Sid, FriendlyName, Status),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn twilio_update_account(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/2010-04-01/Accounts/{Sid}.json".to_string();
if let Some(val) = inputs.get("Sid") {
endpoint = endpoint.replace("{{Sid}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("FriendlyName") {
body.insert("FriendlyName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("Status") {
body.insert("Status".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(
format!("POST /2010-04-01/Accounts/{{Sid}}.json failed: {}", e).into(),
),
);
}
}
Ok(output)
}