pub struct Client { /* private fields */ }Expand description
Client for the OpenIntents agentic API.
use openintents::{Client, CreateIntent};
let oi = Client::from_env()?; // OPENINTENTS_API_KEY
let intent = oi.create_intent(CreateIntent::new("flat white, oat milk").max_amount(1000)).await?;
let intent = oi.wait(&intent.id, Default::default()).await?;
if let Some(payment) = &intent.payment {
println!("pay here: {}", payment.payment_url);
}Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
A client with the given API key and default settings.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Reads OPENINTENTS_API_KEY (and OPENINTENTS_BASE_URL, if set).
pub fn builder(api_key: impl Into<String>) -> ClientBuilder
Sourcepub async fn create_intent(&self, params: CreateIntent) -> Result<Intent>
pub async fn create_intent(&self, params: CreateIntent) -> Result<Intent>
Start an intent. Returns immediately, usually with status queued.
Sends a fresh Idempotency-Key; use Client::create_intent_idempotent to set your own.
pub async fn create_intent_idempotent( &self, params: CreateIntent, idempotency_key: &str, ) -> Result<Intent>
pub async fn get_intent(&self, id: &str) -> Result<Intent>
Sourcepub async fn create_intent_waiting(
&self,
params: CreateIntent,
wait_secs: u32,
) -> Result<Intent>
pub async fn create_intent_waiting( &self, params: CreateIntent, wait_secs: u32, ) -> Result<Intent>
Client::create_intent, holding the request up to wait_secs whole
seconds (Prefer: wait=N, applied as 50 at most) until the intent is
neither queued nor running: it finished, or now needs a payment, an
answer or a sign-in. A hold that runs out is no error: the intent comes
back as it stands. The client’s timeout is stretched to outlast the hold.
Sourcepub async fn get_intent_waiting(
&self,
id: &str,
wait_secs: u32,
) -> Result<Intent>
pub async fn get_intent_waiting( &self, id: &str, wait_secs: u32, ) -> Result<Intent>
Client::get_intent, held like Client::create_intent_waiting.
pub async fn list_intents(&self, params: &ListIntents) -> Result<IntentList>
Sourcepub async fn cancel_intent(&self, id: &str) -> Result<Intent>
pub async fn cancel_intent(&self, id: &str) -> Result<Intent>
Cancel an intent that hasn’t paid yet. Cancelled intents are free.
Sourcepub async fn answer_intent_input(
&self,
id: &str,
answer: AnswerInput,
) -> Result<Intent>
pub async fn answer_intent_input( &self, id: &str, answer: AnswerInput, ) -> Result<Intent>
Answer the intent’s input_request while it waits in
requires_input. Returns the intent, usually running again. A
request already answered or expired is a 409 input_not_waiting.
Sends a fresh Idempotency-Key, so a retry never answers twice.
use openintents::AnswerInput;
if let Some(request) = &intent.input_request {
// Ask the payer `request.prompt`, then:
oi.answer_intent_input(&intent.id, AnswerInput::value(&request.id, "481516"))
.await?;
}Sourcepub async fn balance(&self) -> Result<Balance>
pub async fn balance(&self) -> Result<Balance>
The agent balance intents pay from, and this month’s spend.
Sourcepub async fn balance_for(&self, customer: &str) -> Result<Balance>
pub async fn balance_for(&self, customer: &str) -> Result<Balance>
A customer’s balance.
Sourcepub async fn create_customer(&self, params: CustomerParams) -> Result<Customer>
pub async fn create_customer(&self, params: CustomerParams) -> Result<Customer>
Someone you buy for, with their own balance and browser profile.
Sends a fresh Idempotency-Key; use Client::create_customer_idempotent to set your own.
pub async fn create_customer_idempotent( &self, params: CustomerParams, idempotency_key: &str, ) -> Result<Customer>
pub async fn get_customer(&self, id: &str) -> Result<Customer>
Sourcepub async fn update_customer(
&self,
id: &str,
params: CustomerParams,
) -> Result<Customer>
pub async fn update_customer( &self, id: &str, params: CustomerParams, ) -> Result<Customer>
Fields left out stay as they are (see CustomerParams).
Sourcepub async fn list_customers(
&self,
params: &ListCustomers,
) -> Result<CustomerList>
pub async fn list_customers( &self, params: &ListCustomers, ) -> Result<CustomerList>
Newest first.
Sourcepub async fn create_topup(&self, params: CreateTopup) -> Result<Topup>
pub async fn create_topup(&self, params: CreateTopup) -> Result<Topup>
A payment link that adds amount to a balance once paid. Live keys only.
Sends a fresh Idempotency-Key; use Client::create_topup_idempotent to set your own.
pub async fn create_topup_idempotent( &self, params: CreateTopup, idempotency_key: &str, ) -> Result<Topup>
pub async fn get_topup(&self, id: &str) -> Result<Topup>
Sourcepub async fn list_intent_events(
&self,
id: &str,
params: &ListEvents,
) -> Result<EventList>
pub async fn list_intent_events( &self, id: &str, params: &ListEvents, ) -> Result<EventList>
A page of the intent’s timeline, oldest first: status changes, the agent’s steps, its checkout.
Sourcepub fn stream_intent_events(
&self,
id: &str,
last_event_id: Option<&str>,
) -> EventStream
pub fn stream_intent_events( &self, id: &str, last_event_id: Option<&str>, ) -> EventStream
Follow the intent’s timeline live: past events first, then new ones as
they happen, after last_event_id if given. The stream resumes by
itself after a dropped connection, and ends once the intent is over and
its last event was sent.
let mut events = oi.stream_intent_events("int_7f3a2c", None);
while let Some(event) = events.next().await {
let event = event?;
println!("{} {}", event.kind, event.data);
}Sourcepub async fn list_profiles(&self, params: &ListProfiles) -> Result<ProfileList>
pub async fn list_profiles(&self, params: &ListProfiles) -> Result<ProfileList>
Your account’s profile and your customers’ that exist so far, newest first.
Sourcepub async fn create_profile(&self, params: CreateProfile) -> Result<Profile>
pub async fn create_profile(&self, params: CreateProfile) -> Result<Profile>
Make the profile of your account, or of a customer, ahead of its first intent or session. Optional: an intent makes the profile it needs. Making one that exists returns it unchanged, so no Idempotency-Key is sent.
pub async fn get_profile(&self, id: &str) -> Result<Profile>
Sourcepub async fn forget_profile(&self, id: &str) -> Result<Profile>
pub async fn forget_profile(&self, id: &str) -> Result<Profile>
Erase everything the profile kept: logins, cookies, saved data. Returns
it forgetting, then it turns forgotten. Forgetting twice is fine.
Sourcepub async fn create_session(&self, params: CreateSession) -> Result<Session>
pub async fn create_session(&self, params: CreateSession) -> Result<Session>
Open a browser on a profile without an intent. A profile in use is a
409 profile_busy whose lease says what holds it. Sends a fresh
Idempotency-Key; use Client::create_session_idempotent to set your own.
pub async fn create_session_idempotent( &self, params: CreateSession, idempotency_key: &str, ) -> Result<Session>
pub async fn get_session(&self, id: &str) -> Result<Session>
Sourcepub async fn list_sessions(&self, params: &ListSessions) -> Result<SessionList>
pub async fn list_sessions(&self, params: &ListSessions) -> Result<SessionList>
Newest first.
Sourcepub async fn release_session(&self, id: &str) -> Result<Session>
pub async fn release_session(&self, id: &str) -> Result<Session>
Close the browser, keeping what the session changed in the profile. A session that already ended is returned unchanged.
Sourcepub async fn run_session_command(
&self,
id: &str,
command: SessionCommand,
) -> Result<SessionCommandResult>
pub async fn run_session_command( &self, id: &str, command: SessionCommand, ) -> Result<SessionCommandResult>
Run one command on the session’s page. It waits up to 20 seconds; a
command still running then comes back Pending, to follow with
Client::get_session_command. A refused or failed one says why in
error. Sends a fresh Idempotency-Key, so a retry never runs it twice;
use Client::run_session_command_idempotent to set your own.
pub async fn run_session_command_idempotent( &self, id: &str, command: SessionCommand, idempotency_key: &str, ) -> Result<SessionCommandResult>
pub async fn get_session_command( &self, id: &str, command_id: &str, ) -> Result<SessionCommandResult>
Sourcepub async fn session_screenshot(&self, id: &str) -> Result<Vec<u8>>
pub async fn session_screenshot(&self, id: &str) -> Result<Vec<u8>>
A screenshot of the session’s page, taken now: JPEG bytes.
Sourcepub async fn list_session_events(
&self,
id: &str,
params: &ListEvents,
) -> Result<EventList>
pub async fn list_session_events( &self, id: &str, params: &ListEvents, ) -> Result<EventList>
A page of the session’s timeline, oldest first: status changes, pages and commands.
Sourcepub fn stream_session_events(
&self,
id: &str,
last_event_id: Option<&str>,
) -> EventStream
pub fn stream_session_events( &self, id: &str, last_event_id: Option<&str>, ) -> EventStream
Follow the session’s timeline live, like Client::stream_intent_events.
Sourcepub async fn create_live_link(&self, session: &str) -> Result<LiveLink>
pub async fn create_live_link(&self, session: &str) -> Result<LiveLink>
A link to the session’s live view, valid for 10 minutes. Whoever holds
url sees the browser and drives it, though never to pay or place an
order. The session must be open. Each call makes a new link.
Sourcepub async fn create_portal_session(
&self,
customer: &str,
params: CreatePortalSession,
) -> Result<PortalSession>
pub async fn create_portal_session( &self, customer: &str, params: CreatePortalSession, ) -> Result<PortalSession>
A link to a customer’s own page, shown once: send url to the
customer only. Until portal sessions are open to your key this is a
503 portal_unavailable.
Sourcepub async fn create_secret_request(
&self,
customer: &str,
params: CreateSecretRequest,
) -> Result<SecretRequestCreated>
pub async fn create_secret_request( &self, customer: &str, params: CreateSecretRequest, ) -> Result<SecretRequestCreated>
Ask a customer for their secrets on a page of their own. Send them the
url; its end is a secret_request.completed webhook.
Sourcepub async fn get_secret_request(&self, id: &str) -> Result<SecretRequest>
pub async fn get_secret_request(&self, id: &str) -> Result<SecretRequest>
Where a request for a customer’s secrets stands.
Sourcepub async fn create_secret(&self, params: CreateSecret) -> Result<Secret>
pub async fn create_secret(&self, params: CreateSecret) -> Result<Secret>
Store details a purchase may need and that you would not put in a prompt. Secrets are write-only: one comes back as its label, a mask and a few public fields, never its values. Sends a fresh Idempotency-Key.
Sourcepub async fn list_secrets(&self, params: &ListSecrets) -> Result<SecretList>
pub async fn list_secrets(&self, params: &ListSecrets) -> Result<SecretList>
A payer’s secrets in the key’s mode, without their values: your account’s, or a customer’s.
pub async fn get_secret(&self, id: &str) -> Result<Secret>
Sourcepub async fn replace_secret(
&self,
id: &str,
params: CreateSecret,
) -> Result<Secret>
pub async fn replace_secret( &self, id: &str, params: CreateSecret, ) -> Result<Secret>
Replace a secret’s whole content; its version goes up.
Sourcepub async fn delete_secret(&self, id: &str) -> Result<()>
pub async fn delete_secret(&self, id: &str) -> Result<()>
Delete a secret and its values.
Sourcepub async fn list_secret_uses(
&self,
id: &str,
page: &Page,
) -> Result<SecretUseList>
pub async fn list_secret_uses( &self, id: &str, page: &Page, ) -> Result<SecretUseList>
A secret’s history, newest first: made, replaced, filled into a shop or refused. Never a value.
Sourcepub async fn create_sign_in(&self, params: CreateSignIn) -> Result<SignIn>
pub async fn create_sign_in(&self, params: CreateSignIn) -> Result<SignIn>
A link where the payer signs in to a shop with no intent attached; the
profile keeps the login. Send them url. Its end is a
sign_in.completed or sign_in.expired webhook.
pub async fn get_sign_in(&self, id: &str) -> Result<SignIn>
Sourcepub async fn create_webhook_endpoint(
&self,
params: CreateWebhookEndpoint,
) -> Result<WebhookEndpoint>
pub async fn create_webhook_endpoint( &self, params: CreateWebhookEndpoint, ) -> Result<WebhookEndpoint>
Register a URL for your account’s events. The response alone carries
its secret: keep it.
Sourcepub async fn list_webhook_endpoints(
&self,
page: &Page,
) -> Result<WebhookEndpointList>
pub async fn list_webhook_endpoints( &self, page: &Page, ) -> Result<WebhookEndpointList>
Newest first, without their secrets.
pub async fn get_webhook_endpoint(&self, id: &str) -> Result<WebhookEndpoint>
Sourcepub async fn update_webhook_endpoint(
&self,
id: &str,
params: UpdateWebhookEndpoint,
) -> Result<WebhookEndpoint>
pub async fn update_webhook_endpoint( &self, id: &str, params: UpdateWebhookEndpoint, ) -> Result<WebhookEndpoint>
Change its URL, its event types (an empty list is every intent event) or whether it is disabled.
pub async fn delete_webhook_endpoint(&self, id: &str) -> Result<()>
Sourcepub async fn rotate_webhook_secret(&self, id: &str) -> Result<WebhookEndpoint>
pub async fn rotate_webhook_secret(&self, id: &str) -> Result<WebhookEndpoint>
Make a new secret, returned here only. The one before keeps signing for
24 hours; verify_webhook accepts a header
that carries both.
Sourcepub async fn test_webhook_endpoint(&self, id: &str) -> Result<WebhookDelivery>
pub async fn test_webhook_endpoint(&self, id: &str) -> Result<WebhookDelivery>
Send a webhook_endpoint.test event to this endpoint alone; the
delivery shows how it goes.
Sourcepub async fn list_webhook_deliveries(
&self,
id: &str,
page: &Page,
) -> Result<WebhookDeliveryList>
pub async fn list_webhook_deliveries( &self, id: &str, page: &Page, ) -> Result<WebhookDeliveryList>
What was sent to the endpoint, newest first.
Sourcepub async fn redeliver_webhook(
&self,
endpoint: &str,
delivery: &str,
) -> Result<WebhookDelivery>
pub async fn redeliver_webhook( &self, endpoint: &str, delivery: &str, ) -> Result<WebhookDelivery>
Send a delivery again, with the same event id and body.